Which Takes Effect: System Variable tidb_stmt_summary_max_sql_length or Configuration Parameter stmt-summary.max-sql-length?

Note:
This topic has been translated from a Chinese forum by GPT and might contain errors.

Original topic: 系统变量tidb_stmt_summary_max_sql_lengt和配置参数stmt-summary.max-sql-length 到底谁生效

| username: Raymond

The system variable tidb_stmt_summary_max_sql_length and the configuration parameter stmt-summary.max-sql-length are both related to the length of the SQL displayed in information_schema.STATEMENTS_SUMMARY according to the official documentation. However, what is their actual function?

Official documentation for the system variable tidb_stmt_summary_max_sql_length:

Official documentation for the configuration parameter stmt-summary.max-sql-length:

First, it can be seen that the system variable tidb_stmt_summary_max_sql_length is not set based on the value of the configuration parameter stmt-summary.max-sql-length:

Experiment 1:
The value of the system variable tidb_stmt_summary_max_sql_length is 10.
The value of the configuration parameter stmt-summary.max-sql-length is 20480.


Execute the following SQL statement:

select sbtest2.k, sbtest3.k, sbtest2.id, sbtest1.k, sbtest1.id, sbtest3.id from sbtest1 join sbtest2 on sbtest1.id=sbtest2.id join sbtest3 on sbtest2.id=sbtest3.id


It is found that the output of DIGEST_TEXT and QUERY_SAMPLE_TEXT in the statement summary tables is truncated.

Experiment 2:
The value of the system variable tidb_stmt_summary_max_sql_length is 20480.
The value of the configuration parameter stmt-summary.max-sql-length is 10.


Execute the following SQL statement:

select sbtest2.k, sbtest3.k, sbtest2.id, sbtest1.k, sbtest1.id, sbtest3.id from sbtest1 join sbtest2 on sbtest1.id=sbtest2.id join sbtest3 on sbtest2.id=sbtest3.id;

It is found that the output of DIGEST_TEXT and QUERY_SAMPLE_TEXT in the statement summary tables is not truncated.

The scope of these two parameters or system variables is still a bit confusing.

Based on the above two experiments, I am not sure if the following guesses are correct:

  1. According to the official documentation, the configuration parameter stmt-summary.max-sql-length controls the maximum display length of the DIGEST_TEXT and QUERY_SAMPLE_TEXT columns in the statement summary tables. However, from Experiment 1, even if the configuration parameter stmt-summary.max-sql-length is set to 20480, it does not control the maximum display length of the DIGEST_TEXT and QUERY_SAMPLE_TEXT columns in the statement summary tables.

  2. From Experiment 2, when the configuration parameter stmt-summary.max-sql-length is lower than the system variable tidb_stmt_summary_max_sql_length, the SQL strings in the statement summary tables can display the full length (including DIGEST_TEXT and QUERY_SAMPLE_TEXT).

From these two experiments, there is a guess that the maximum display length of the DIGEST_TEXT and QUERY_SAMPLE_TEXT columns in the statement summary tables is actually controlled by the system variable tidb_stmt_summary_max_sql_length.

| username: Kongdom | Original post link

It is recommended to specify the version. In versions after v6.0.0, the configuration parameter stmt-summary.max-sql-length has been removed and is now controlled by the system variable tidb_stmt_summary_max_sql_length.

| username: Raymond | Original post link

Thank you for sharing.

| username: jansu-dev | Original post link

+1, the documentation for v4 ~ v6 needs to be updated Stmt-summary.max-sql-length is useless and ignored by TiDB · Issue #38757 · pingcap/tidb · GitHub

| username: system | Original post link

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.