Skip to main content
This topic introduces the SQL Digest feature of the database. This feature is supported from v3.3.6 onwards.

Overview

SQL Digest is a fingerprint generated by historical SQL statements with parameters removed. It helps cluster SQL statements with the same structure but different parameters. Common use cases of SQL Digest include:
  • Finding other SQL statements with the same structure but different parameters in query history
  • Tracking execution frequency, cumulative time, and other statistics of SQL with the same structure
  • Identifying the most time-consuming SQL patterns in the system
In the database, SQL Digests are mainly recorded through audit logs fe.audit.log. For example, execute the following two SQL statements:
Two same Digest will be generated in fe.audit.log:

Usage

Prerequisites

To enable this feature, you must set the FE configuration item enable_sql_digest to true. Execute the following statement to enable it dynamically:
To enable it permanently, you must add enable_sql_digest = true to the FE configuration file fe.conf and restart FE. After enabling this feature, you can install the AuditLoader plugin to perform statistical analysis on SQL statements.

Find similar SQL

Track daily execution count and time of similar SQL

Calculate average execution time of similar SQL

Aggregate similar SQL to analyze the most time-consuming pattern

Parameter normalization rules

  • Constant values in SQL will be normalized. For example, similar SQL statements with WHERE a = 1 and WHERE a = 2 will have the same Digest.
  • IN predicates will be normalized. For example, similar SQL statements with IN (1,2,3) and IN (1,2) will have the same Digest.
  • LIMIT N clauses will be normalized. For example, similar SQL statements with LIMIT 10 and LIMIT 30 will have the same Digest.