prestodb/presto · error · PrestoException

NOT_SUPPORTED

NOT_SUPPORTED

Error message

EXPLAIN ANALYZE doesn't support statement type: 

What it means

EXPLAIN ANALYZE actually executes the inner statement, so it only supports statements with a query type that is executable (queries/DML). If the inner statement is DATA_DEFINITION (CREATE/DROP/etc.) or CONTROL (SET/RESET etc.), or has no query type at all, prepareQuery throws NOT_SUPPORTED.

Source

Thrown at presto-analyzer/src/main/java/com/facebook/presto/sql/analyzer/BuiltInQueryPreparer.java:118

        }

        Optional<QualifiedObjectName> distributedProcedureName = Optional.empty();
        if (statement instanceof Call) {
            QualifiedName qualifiedName = ((Call) statement).getName();
            QualifiedObjectName qualifiedObjectName = createQualifiedObjectName(analyzerOptions.getSessionCatalogName(), analyzerOptions.getSessionSchemaName(),
                    statement, qualifiedName, (catalogName, objectName) -> objectName);
            if (procedureRegistry.isDistributedProcedure(
                    new ConnectorId(qualifiedObjectName.getCatalogName()),
                    new SchemaTableName(qualifiedObjectName.getSchemaName(), qualifiedObjectName.getObjectName()))) {
                distributedProcedureName = Optional.of(qualifiedObjectName);
            }
        }

        if (statement instanceof Explain && ((Explain) statement).isAnalyze()) {
            Statement innerStatement = ((Explain) statement).getStatement();
            Optional<QueryType> innerQueryType = StatementUtils.getQueryType(innerStatement.getClass());
            if (!innerQueryType.isPresent() || innerQueryType.get() == QueryType.DATA_DEFINITION || innerQueryType.get() == QueryType.CONTROL) {
                throw new PrestoException(NOT_SUPPORTED, "EXPLAIN ANALYZE doesn't support statement type: " + innerStatement.getClass().getSimpleName());
            }
        }
        List<Expression> parameters = ImmutableList.of();
        if (wrappedStatement instanceof Execute) {
            parameters = ((Execute) wrappedStatement).getParameters();
        }
        validateParameters(statement, parameters);
        Optional<String> formattedQuery = Optional.empty();
        if (analyzerOptions.isLogFormattedQueryEnabled()) {
            formattedQuery = Optional.of(getFormattedQuery(statement, parameters));
        }
        return new BuiltInPreparedQuery(wrappedStatement, statement, parameters, formattedQuery, prepareSql, distributedProcedureName);
    }

    private static String getFormattedQuery(Statement statement, List<Expression> parameters)
    {
        String formattedQuery = formatSql(
                statement,

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Remove EXPLAIN ANALYZE and run the DDL/control statement directly
  2. Use plain EXPLAIN (without ANALYZE) if only the plan is needed and the statement supports it
  3. Only apply EXPLAIN ANALYZE to SELECT/INSERT/UPDATE/DELETE-style statements

Example fix

// before
EXPLAIN ANALYZE CREATE TABLE t AS SELECT 1
// after
EXPLAIN CREATE TABLE t AS SELECT 1  -- or run the DDL directly
Defensive patterns

Strategy: validation

Validate before calling

Optional<QueryType> qt = StatementUtils.getQueryType(innerStatement.getClass());
if (!qt.isPresent() || qt.get() == QueryType.DATA_DEFINITION || qt.get() == QueryType.CONTROL) {
    throw new IllegalArgumentException("EXPLAIN ANALYZE not supported for " + innerStatement.getClass().getSimpleName());
}

Type guard

boolean isExplainAnalyzeSafe(Statement s) {
    Optional<QueryType> qt = StatementUtils.getQueryType(s.getClass());
    return qt.isPresent() && qt.get() != QueryType.DATA_DEFINITION && qt.get() != QueryType.CONTROL;
}

Try / catch

try {
    preparer.prepareQuery(options, sql, params, warnings);
} catch (PrestoException e) {
    if (e.getMessage().startsWith("EXPLAIN ANALYZE doesn't support statement type")) { /* strip EXPLAIN ANALYZE prefix and run plain statement */ }
    throw e;
}

Prevention

When it happens

Trigger: Running 'EXPLAIN ANALYZE <statement>' where <statement> is e.g. CREATE TABLE, DROP TABLE, SET SESSION, CALL, or any statement whose class maps to no QueryType or to DATA_DEFINITION/CONTROL.

Common situations: Users wrapping DDL or session-control statements in EXPLAIN ANALYZE expecting a plan analysis; scripted validation tools that prefix all statements with EXPLAIN ANALYZE.

Understand the failure class

Background: Presto NOT_SUPPORTED error: what "not supported" means and how to fix it — this error's family across 3 libraries.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/003b75b2f60ff6fd. Report an issue: GitHub.