From 588cac61f196f8df2235ab8a6b0ec921f96bf63c Mon Sep 17 00:00:00 2001
From: jiong-nba <2301210292@stu.pku.edu.cn>
Date: Tue, 10 Mar 2026 10:57:19 +0800
Subject: [PATCH 1/3] docs: sync session connect attrs docs with tidb#66617
---
.../information-schema-slow-query.md | 6 ++++--
.../performance-schema-session-connect-attrs.md | 12 ++++++++++++
status-variables.md | 12 ++++++++++++
system-variable-reference.md | 7 +++++++
system-variables.md | 17 +++++++++++++++++
5 files changed, 52 insertions(+), 2 deletions(-)
diff --git a/information-schema/information-schema-slow-query.md b/information-schema/information-schema-slow-query.md
index 7413fa8b46356..b19224c833ed6 100644
--- a/information-schema/information-schema-slow-query.md
+++ b/information-schema/information-schema-slow-query.md
@@ -126,9 +126,10 @@ The output is as follows:
| Plan_digest | varchar(128) | YES | | NULL | |
| Binary_plan | longtext | YES | | NULL | |
| Prev_stmt | longtext | YES | | NULL | |
+| Session_connect_attrs | json | YES | | NULL | |
| Query | longtext | YES | | NULL | |
+--------------------------------------------+-----------------+------+------+---------+-------+
-89 rows in set (0.00 sec)
+90 rows in set (0.00 sec)
```
The maximum statement length of the `Query` column is limited by the [`tidb_stmt_summary_max_sql_length`](/system-variables.md#tidb_stmt_summary_max_sql_length-new-in-v40) system variable.
@@ -246,9 +247,10 @@ The output is as follows:
| Plan_digest | varchar(128) | YES | | NULL | |
| Binary_plan | longtext | YES | | NULL | |
| Prev_stmt | longtext | YES | | NULL | |
+| Session_connect_attrs | json | YES | | NULL | |
| Query | longtext | YES | | NULL | |
+--------------------------------------------+-----------------+------+------+---------+-------+
-90 rows in set (0.00 sec)
+91 rows in set (0.00 sec)
```
When the cluster system table is queried, TiDB does not obtain data from all nodes, but pushes down the related calculation to other nodes. The execution plan is as follows:
diff --git a/performance-schema/performance-schema-session-connect-attrs.md b/performance-schema/performance-schema-session-connect-attrs.md
index fabbce7e9f110..8248a0958b5fa 100644
--- a/performance-schema/performance-schema-session-connect-attrs.md
+++ b/performance-schema/performance-schema-session-connect-attrs.md
@@ -66,3 +66,15 @@ Fields in the `SESSION_CONNECT_ATTRS` table are described as follows:
* `ATTR_NAME`: Attribute name.
* `ATTR_VALUE`: Attribute value.
* `ORDINAL_POSITION`: Ordinal position of the name/value pair.
+
+## Size limit and truncation
+
+TiDB uses the [`performance_schema_session_connect_attrs_size`](/system-variables.md#performance_schema_session_connect_attrs_size) global system variable to control the maximum total size of connection attributes per session.
+
+- Default value: `4096` bytes
+- Range: `[-1, 65536]`
+- `-1` means no configured limit, and TiDB treats it as up to `65536` bytes.
+
+When the total size exceeds this limit, TiDB truncates excess attributes and adds `_truncated` to indicate the number of truncated bytes.
+
+TiDB also enforces a hard limit of 1 MiB on connection attribute payload in handshake packets. If this hard limit is exceeded, the connection is rejected.
diff --git a/status-variables.md b/status-variables.md
index ec577d88c6173..ec07a6e52e2bf 100644
--- a/status-variables.md
+++ b/status-variables.md
@@ -31,6 +31,18 @@ Additionally, the [FLUSH STATUS](/sql-statements/sql-statement-flush-status.md)
- Type: Integer
- The compression level that is used for the MySQL Protocol.
+### Performance_schema_session_connect_attrs_longest_seen
+
+- Scope: GLOBAL
+- Type: Integer
+- The largest total size (in bytes) of session connection attributes observed by TiDB.
+
+### Performance_schema_session_connect_attrs_lost
+
+- Scope: GLOBAL
+- Type: Integer
+- The number of sessions whose connection attributes were truncated due to `performance_schema_session_connect_attrs_size`.
+
### Ssl_cipher
- Scope: SESSION | GLOBAL
diff --git a/system-variable-reference.md b/system-variable-reference.md
index ef41aa77a6c3c..3315e086b218c 100644
--- a/system-variable-reference.md
+++ b/system-variable-reference.md
@@ -600,6 +600,13 @@ Referenced in:
- [TiDB 8.5.0 Release Notes](/releases/release-8.5.0.md)
- [TiDB 7.6.0 Release Notes](/releases/release-7.6.0.md)
+### performance_schema_session_connect_attrs_size
+
+Referenced in:
+
+- [SESSION_CONNECT_ATTRS](/performance-schema/performance-schema-session-connect-attrs.md)
+- [System Variables](/system-variables.md#performance_schema_session_connect_attrs_size)
+
### plugin_dir
Referenced in:
diff --git a/system-variables.md b/system-variables.md
index 79af0db79a694..9d56d900b1394 100644
--- a/system-variables.md
+++ b/system-variables.md
@@ -789,6 +789,23 @@ mysql> SHOW GLOBAL VARIABLES LIKE 'max_prepared_stmt_count';
1 row in set (0.00 sec)
```
+### performance_schema_session_connect_attrs_size
+
+- Scope: GLOBAL
+- Persists to cluster: Yes
+- Applies to hint [SET_VAR](/optimizer-hints.md#set_varvar_namevar_value): No
+- Type: Integer
+- Default value: `4096`
+- Range: `[-1, 65536]`
+- Unit: Bytes
+- Controls the maximum total size of connection attributes for each session.
+- If the total size of connection attributes exceeds this value, TiDB truncates excess attributes and adds `_truncated` to indicate the number of truncated bytes.
+- The value `-1` means no configured limit and is treated as up to `65536` bytes in TiDB.
+
+> **Note:**
+>
+> TiDB enforces a hard limit of 1 MiB for handshake connection attributes. If this hard limit is exceeded, the connection is rejected.
+
### pd_enable_follower_handle_region New in v7.6.0
- Scope: GLOBAL
From 8f0c5181c328617cba937a4ad95293a9001f3fc4 Mon Sep 17 00:00:00 2001
From: jiong-nba <2301210292@stu.pku.edu.cn>
Date: Tue, 10 Mar 2026 17:01:04 +0800
Subject: [PATCH 2/3] docs: clarify connect attrs size impact on slow log
payload
---
information-schema/information-schema-slow-query.md | 2 ++
performance-schema/performance-schema-session-connect-attrs.md | 2 ++
system-variables.md | 2 ++
3 files changed, 6 insertions(+)
diff --git a/information-schema/information-schema-slow-query.md b/information-schema/information-schema-slow-query.md
index b19224c833ed6..82b3635fb7e56 100644
--- a/information-schema/information-schema-slow-query.md
+++ b/information-schema/information-schema-slow-query.md
@@ -134,6 +134,8 @@ The output is as follows:
The maximum statement length of the `Query` column is limited by the [`tidb_stmt_summary_max_sql_length`](/system-variables.md#tidb_stmt_summary_max_sql_length-new-in-v40) system variable.
+The `Session_connect_attrs` column stores session connection attributes in JSON format parsed from the slow log. TiDB controls the maximum payload size written to this field using [`performance_schema_session_connect_attrs_size`](/system-variables.md#performance_schema_session_connect_attrs_size).
+
## CLUSTER_SLOW_QUERY table
The `CLUSTER_SLOW_QUERY` table provides the slow query information of all nodes in the cluster, which is the parsing result of the TiDB slow log files. You can use the `CLUSTER_SLOW_QUERY` table the way you do with `SLOW_QUERY`. The table schema of the `CLUSTER_SLOW_QUERY` table differs from that of the `SLOW_QUERY` table in that an `INSTANCE` column is added to `CLUSTER_SLOW_QUERY`. The `INSTANCE` column represents the TiDB node address of the row information on the slow query.
diff --git a/performance-schema/performance-schema-session-connect-attrs.md b/performance-schema/performance-schema-session-connect-attrs.md
index 8248a0958b5fa..f4dcd14012bee 100644
--- a/performance-schema/performance-schema-session-connect-attrs.md
+++ b/performance-schema/performance-schema-session-connect-attrs.md
@@ -77,4 +77,6 @@ TiDB uses the [`performance_schema_session_connect_attrs_size`](/system-variable
When the total size exceeds this limit, TiDB truncates excess attributes and adds `_truncated` to indicate the number of truncated bytes.
+The accepted connection attributes are also written to the `Session_connect_attrs` field in the slow log and can be queried from `INFORMATION_SCHEMA.SLOW_QUERY` and `INFORMATION_SCHEMA.CLUSTER_SLOW_QUERY`. To control the payload size written to the slow log, adjust `performance_schema_session_connect_attrs_size`.
+
TiDB also enforces a hard limit of 1 MiB on connection attribute payload in handshake packets. If this hard limit is exceeded, the connection is rejected.
diff --git a/system-variables.md b/system-variables.md
index 9d56d900b1394..cef35e91b31ee 100644
--- a/system-variables.md
+++ b/system-variables.md
@@ -800,6 +800,8 @@ mysql> SHOW GLOBAL VARIABLES LIKE 'max_prepared_stmt_count';
- Unit: Bytes
- Controls the maximum total size of connection attributes for each session.
- If the total size of connection attributes exceeds this value, TiDB truncates excess attributes and adds `_truncated` to indicate the number of truncated bytes.
+- Connection attributes accepted within this limit are written to the `Session_connect_attrs` field in the slow log and can be queried from [`INFORMATION_SCHEMA.SLOW_QUERY`](/information-schema/information-schema-slow-query.md) and `INFORMATION_SCHEMA.CLUSTER_SLOW_QUERY`.
+- You can control the size of `Session_connect_attrs` recorded in the slow log by adjusting this variable.
- The value `-1` means no configured limit and is treated as up to `65536` bytes in TiDB.
> **Note:**
From e005d6338e1a1b8c38b4dcd9fc5b919299d5d2a8 Mon Sep 17 00:00:00 2001
From: jiong-nba <2301210292@stu.pku.edu.cn>
Date: Mon, 16 Mar 2026 11:07:56 +0800
Subject: [PATCH 3/3] docs: mark connect attrs size variable as new in v9.0.0
---
information-schema/information-schema-slow-query.md | 2 +-
performance-schema/performance-schema-session-connect-attrs.md | 2 +-
system-variable-reference.md | 2 +-
system-variables.md | 2 +-
4 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/information-schema/information-schema-slow-query.md b/information-schema/information-schema-slow-query.md
index 82b3635fb7e56..9b3de52791dac 100644
--- a/information-schema/information-schema-slow-query.md
+++ b/information-schema/information-schema-slow-query.md
@@ -134,7 +134,7 @@ The output is as follows:
The maximum statement length of the `Query` column is limited by the [`tidb_stmt_summary_max_sql_length`](/system-variables.md#tidb_stmt_summary_max_sql_length-new-in-v40) system variable.
-The `Session_connect_attrs` column stores session connection attributes in JSON format parsed from the slow log. TiDB controls the maximum payload size written to this field using [`performance_schema_session_connect_attrs_size`](/system-variables.md#performance_schema_session_connect_attrs_size).
+The `Session_connect_attrs` column stores session connection attributes in JSON format parsed from the slow log. TiDB controls the maximum payload size written to this field using [`performance_schema_session_connect_attrs_size`](/system-variables.md#performance_schema_session_connect_attrs_size-new-in-v900).
## CLUSTER_SLOW_QUERY table
diff --git a/performance-schema/performance-schema-session-connect-attrs.md b/performance-schema/performance-schema-session-connect-attrs.md
index f4dcd14012bee..f6ee682eb4f4e 100644
--- a/performance-schema/performance-schema-session-connect-attrs.md
+++ b/performance-schema/performance-schema-session-connect-attrs.md
@@ -69,7 +69,7 @@ Fields in the `SESSION_CONNECT_ATTRS` table are described as follows:
## Size limit and truncation
-TiDB uses the [`performance_schema_session_connect_attrs_size`](/system-variables.md#performance_schema_session_connect_attrs_size) global system variable to control the maximum total size of connection attributes per session.
+TiDB uses the [`performance_schema_session_connect_attrs_size`](/system-variables.md#performance_schema_session_connect_attrs_size-new-in-v900) global system variable to control the maximum total size of connection attributes per session.
- Default value: `4096` bytes
- Range: `[-1, 65536]`
diff --git a/system-variable-reference.md b/system-variable-reference.md
index 3315e086b218c..d5f2db378b997 100644
--- a/system-variable-reference.md
+++ b/system-variable-reference.md
@@ -605,7 +605,7 @@ Referenced in:
Referenced in:
- [SESSION_CONNECT_ATTRS](/performance-schema/performance-schema-session-connect-attrs.md)
-- [System Variables](/system-variables.md#performance_schema_session_connect_attrs_size)
+- [System Variables](/system-variables.md#performance_schema_session_connect_attrs_size-new-in-v900)
### plugin_dir
diff --git a/system-variables.md b/system-variables.md
index cef35e91b31ee..e14b0a10012ba 100644
--- a/system-variables.md
+++ b/system-variables.md
@@ -789,7 +789,7 @@ mysql> SHOW GLOBAL VARIABLES LIKE 'max_prepared_stmt_count';
1 row in set (0.00 sec)
```
-### performance_schema_session_connect_attrs_size
+### performance_schema_session_connect_attrs_size New in v9.0.0
- Scope: GLOBAL
- Persists to cluster: Yes