We we not generating digest for `DDL` like `CREATE...
# questions-and-troubleshooting
y
We we not generating digest for
DDL
like
CREATE TABLE AS SELECT
? https://github.com/StarRocks/starrocks/blob/main/fe/fe-core/src/main/java/com/starrocks/qe/ConnectProcessor.java#L351
Copy code
// Build Digest and queryFeMemory for SELECT/INSERT/UPDATE/DELETE
        if (ctx.getState().isQuery() || parsedStmt instanceof DmlStmt) {
            String digest = digestFromLeader;
            if (digest == null && (Config.enable_sql_digest || ctx.getSessionVariable().isEnableSQLDigest())) {
                digest = computeStatementDigest(parsedStmt);
            }
            if (digest != null) {
                ctx.getAuditEventBuilder().setDigest(digest);
            }
            long threadAllocatedMemory =
                    getThreadAllocatedBytes(Thread.currentThread().getId()) - ctx.getCurrentThreadAllocatedMemory();
            ctx.getAuditEventBuilder().setQueryFeMemory(threadAllocatedMemory);
        }
@Rocky @Michael Taranov @Rotem Adhoh cc
r
Based on the code snippet and StarRocks' current implementation (as of v3.3.6 and later), SQL digests are indeed only generated for Query statements (like
SELECT
) and DML statements (like
INSERT
,
UPDATE
,
DELETE
). Why
CREATE TABLE AS SELECT
(CTAS) is not included:
In the StarRocks FE codebase,
CreateTableAsSelectStmt
is categorized as a DDL (Data Definition Language) statement rather than a
DmlStmt
. The logic in
ConnectProcessor.java
specifically filters for: 1. `ctx.getState().isQuery()`: Typically true for
SELECT
and certain
SHOW
statements. 2. `parsedStmt instanceof DmlStmt`: Covers
INSERT
,
UPDATE
, and
DELETE
. Since CTAS is technically a "Create Table" operation that happens to contain a "Select" query, it is treated as a DDL schema change. Most DDLs (
ALTER
,
DROP
,
CREATE
) are excluded from digest generation because: * Frequency: DDLs are generally low-frequency operations compared to queries and DML. * Purpose: The SQL Digest feature was primarily designed to identify patterns in high-concurrency workloads to analyze query performance and resource consumption. Impact on CTAS Even though the "Select" portion of a CTAS can be resource-intensive and follow a repeated pattern (common in ETL jobs), the outer statement remains a DDL. Consequently: * CTAS operations will appear in the audit log, but the
digest
field will be empty. * You cannot cluster CTAS operations by their query structure using the
digest
column in the
starrocks_audit_tbl__
. Recommendation If you need to track the performance patterns of heavy CTAS operations via digests, this would currently require an enhancement to the FE logic to include
CreateTableAsSelectStmt
(or DDLs in general) in the digest computation block. For now, if you are performing heavy ETL, you might consider using
INSERT INTO ... SELECT
into an existing table if possible, as
INSERT
statements will generate a digest. References: * SQL Digest Documentation * Audit Log Field Reference Referencesadministration/sql_digest.mdadministration/management/FE_configuration.mdfaq/operation_maintenance_faq.mdadministration/management/logs.mdadministration/management/audit_loader.mdintegrations/smt/starrocks_sqlalchemy.md