Skip to content
This repository was archived by the owner on Mar 1, 2026. It is now read-only.

Commit e53d362

Browse files
inikepHerman Lee
authored andcommitted
Return the list of read and write tables in the query response attributes
Summary: Return the list of read and write tables in the query response attributes Reviewed By: satya-valluri, george-reynya Differential Revision: D30528514 ------------------------------------------------------------------------------- Prevent copying of strings Summary: Do not copy but rather move the lists and string when returning write and query tables in response attrs. Reviewed By: hermanlee Differential Revision: D35380554
1 parent c59b059 commit e53d362

12 files changed

Lines changed: 767 additions & 24 deletions

‎mysql-test/r/mysqld--help-notwin.result‎

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -467,8 +467,8 @@ The following options may be given as the first argument:
467467
If set, prevents super from writing to a read_only
468468
instance when sql_log_bin is also enabled
469469
--enable-user-tables-engine-check
470-
Enable checking storage engine compatibilty of user table
471-
creation DDL.
470+
Enable checking storage engine compatibility of user
471+
table creation DDL.
472472
--end-markers-in-json
473473
In JSON output ("EXPLAIN FORMAT=JSON" and optimizer
474474
trace), if variable is set to 1, repeats the structure's
@@ -1690,6 +1690,13 @@ The following options may be given as the first argument:
16901690
pair - 'hlc_ts' is the key and the value is the
16911691
stringified HLC timestamp. Note that HLC should be
16921692
enabled by setting enable_binlog_hlc
1693+
--response-attrs-contain-read-tables-bytes[=#]
1694+
Specifies the size of the tables information (specified
1695+
in bytes) that can be included in the query response
1696+
attributes. The tables are sent as a key-value pair -
1697+
'read_tables' is the key and the value is a list of table
1698+
names separated by commas. The default value is 0 which
1699+
disables this feature
16931700
--response-attrs-contain-server-cpu
16941701
If this is enabled, then the server CPU time of the query
16951702
is sent back to clients as part of OK packet in session
@@ -1706,6 +1713,13 @@ The following options may be given as the first argument:
17061713
second value of the pair is the message text and these
17071714
are separated by a comma. The default value is 0 which
17081715
disables this feature
1716+
--response-attrs-contain-write-tables-bytes[=#]
1717+
Specifies the size of the tables information (specified
1718+
in bytes) that can be included in the query response
1719+
attributes. The tables are sent as a key-value pair -
1720+
'write_tables' is the key and the value is a list of
1721+
table names separated by commas. The default value is 0
1722+
which disables this feature
17091723
--rocksdb[=name] Enable or disable ROCKSDB plugin. Possible values are ON,
17101724
OFF, FORCE (don't start if the plugin fails to load).
17111725
--rocksdb-access-hint-on-compaction-start=#
@@ -3287,8 +3301,10 @@ require-secure-transport FALSE
32873301
reset-period-status-vars FALSE
32883302
reset-seconds-behind-master TRUE
32893303
response-attrs-contain-hlc FALSE
3304+
response-attrs-contain-read-tables-bytes 0
32903305
response-attrs-contain-server-cpu FALSE
32913306
response-attrs-contain-warnings-bytes 0
3307+
response-attrs-contain-write-tables-bytes 0
32923308
rocksdb ON
32933309
rocksdb-access-hint-on-compaction-start 1
32943310
rocksdb-active-compaction-stats ON
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
2+
# Test read_tables and write_tables query response attributes
3+
4+
use test;
5+
create table tab1 (c1 int PRIMARY KEY, c2 int unsigned);
6+
create table tab2 (c1 int PRIMARY KEY, c2 int unsigned);
7+
create table tab3 (c1 int PRIMARY KEY, c2 int unsigned);
8+
create view view1 as select tab1.c1, tab2.c2 from tab1, tab2;
9+
create view view2 as select * from tab1 union select * from tab2;
10+
# Test 1: session level variables are default, i.e. 0
11+
Expected read=<empty>, write=<empty>
12+
set @@session.response_attrs_contain_read_tables_bytes = default;
13+
set @@session.response_attrs_contain_write_tables_bytes = default;
14+
select * from tab1;
15+
c1 c2
16+
[^] Read tables in query response attributes:
17+
# set session level variables to 1KB
18+
set @@session.response_attrs_contain_read_tables_bytes = 1024;
19+
set @@session.response_attrs_contain_write_tables_bytes = 1024;
20+
# Test 2: read from a join
21+
Expected read=tab1,tab2, write=<empty>
22+
select * from tab1, tab2;
23+
c1 c2 c1 c2
24+
[^] Read tables in query response attributes: tab1,tab2
25+
# Test 3: no tables in the query
26+
Expected read=<empty>, write=<empty>
27+
select 'no tables in this query' alias;
28+
alias
29+
no tables in this query
30+
[^] Read tables in query response attributes:
31+
# Test 4: read from a join view
32+
Expected read=tab1,tab2, write=<empty>
33+
select * from view1;
34+
c1 c2
35+
[^] Read tables in query response attributes: tab1,tab2
36+
# Test 5: read from a union view
37+
Expected read=tab1,tab2, write=<empty>
38+
select * from view2;
39+
c1 c2
40+
[^] Read tables in query response attributes: tab1,tab2
41+
# Test 6: insert-select with the same table
42+
Expected read=tab1, write=tab1
43+
insert into tab1 select * from tab1;
44+
[^] Read tables in query response attributes: tab1
45+
[^] Write tables in query response attributes: tab1
46+
# Test 7: insert-select with different tables
47+
Expected read=tab1, write=tab2
48+
insert into tab2 select * from tab1;
49+
[^] Read tables in query response attributes: tab1
50+
[^] Write tables in query response attributes: tab2
51+
# Test 8: replace-select with different tables
52+
Expected read=tab1, write=tab2
53+
replace into tab2 select * from tab1;
54+
[^] Read tables in query response attributes: tab1
55+
[^] Write tables in query response attributes: tab2
56+
# Test 9: insert-values
57+
Expected read=<empty>, write=tab1
58+
insert into tab1 values(1, 1);
59+
[^] Read tables in query response attributes:
60+
[^] Write tables in query response attributes: tab1
61+
# Test 10: replace-values
62+
Expected read=<empty>, write=tab1
63+
replace into tab1 values(1, 1);
64+
[^] Read tables in query response attributes:
65+
[^] Write tables in query response attributes: tab1
66+
# Test 11: single table delete
67+
Expected write=tab1
68+
DELETE FROM tab1
69+
WHERE
70+
tab1.c1 > 1;
71+
[^] Read tables in query response attributes:
72+
[^] Write tables in query response attributes: tab1
73+
# Test 12: single table delete with sub-query
74+
Expected read=tab3, write=tab2
75+
DELETE FROM tab1
76+
WHERE
77+
tab1.c1 in (select c1 from tab3);
78+
[^] Read tables in query response attributes: tab3
79+
[^] Write tables in query response attributes: tab1
80+
# Test 13: multi-table delete
81+
Expected read=<empty>, write=tab1,tab2
82+
DELETE tab1,tab2 FROM tab1
83+
INNER JOIN
84+
tab2 ON tab2.c2 = tab1.c2
85+
WHERE
86+
tab1.c1 > 1;
87+
[^] Read tables in query response attributes:
88+
[^] Write tables in query response attributes: tab1,tab2
89+
# Test 14: multi-table delete with sub-query
90+
Expected read=tab3, write=tab1,tab2
91+
DELETE tab1,tab2 FROM tab1
92+
INNER JOIN
93+
tab2 ON tab2.c2 = tab1.c2
94+
WHERE
95+
tab1.c1 in (select c1 from tab3);
96+
[^] Read tables in query response attributes: tab3
97+
[^] Write tables in query response attributes: tab1,tab2
98+
# Test 15: single table update
99+
Expected read=<empty>, write=tab1
100+
UPDATE tab1
101+
SET tab1.c1=1
102+
WHERE tab1.c1>2;
103+
[^] Read tables in query response attributes:
104+
[^] Write tables in query response attributes: tab1
105+
# Test 16: single table update with sub-query
106+
Expected read=tab3, write=tab1
107+
UPDATE tab1
108+
SET tab1.c1=1
109+
WHERE tab1.c1 in (select c1 from tab3);
110+
[^] Read tables in query response attributes: tab3
111+
[^] Write tables in query response attributes: tab1
112+
# Test 17: multi-table update
113+
Expected read=<empty>, write=tab1,tab2
114+
UPDATE tab1, tab2
115+
SET tab1.c1=1, tab2.c1=2
116+
WHERE tab1.c1>2 AND tab2.c1 > 1;
117+
[^] Read tables in query response attributes:
118+
[^] Write tables in query response attributes: tab1,tab2
119+
# Test 18: multi-table update with sub-query
120+
Expected read=tab3, write=tab1,tab2
121+
UPDATE tab1, tab2
122+
SET tab1.c1=1, tab2.c1=2
123+
WHERE tab1.c1>2 AND tab2.c1 in (select c1 from tab3);
124+
[^] Read tables in query response attributes: tab3
125+
[^] Write tables in query response attributes: tab1,tab2
126+
# Test 19: LOAD into table
127+
Expected read=<empty> write=tab1
128+
[^] Read tables in query response attributes:
129+
[^] Write tables in query response attributes: tab1
130+
# Test 20: multi-query
131+
Expected read=tab2 write=<empty>
132+
Shows the tables from the last query
133+
(the session tracker is reset between queries)
134+
select * from tab1;
135+
select * from tab2;
136+
|||
137+
c1 c2
138+
1 1
139+
c1 c2
140+
[^] Read tables in query response attributes: tab2
141+
# Test 21: SELECT with duplicate table names
142+
Expected read=tab1,tab2,tab3 write=<empty>
143+
show unique table names
144+
select * from tab1 t11, tab2 t21, tab1 t12, tab2 t22, tab3, tab2 t23;
145+
c1 c2 c1 c2 c1 c2 c1 c2 c1 c2 c1 c2
146+
[^] Read tables in query response attributes: tab1,tab2,tab3
147+
# Test 22: SELECT with a very long table
148+
Expected read=tab1,... write=<empty>
149+
the long table name is ommited
150+
create table averyveryveryveryveryveryverylongtablename
151+
(c1 int PRIMARY KEY, c2 int unsigned);
152+
set @@session.response_attrs_contain_read_tables_bytes = 20;
153+
select * from tab1, averyveryveryveryveryveryverylongtablename;
154+
c1 c2 c1 c2
155+
[^] Read tables in query response attributes: tab1,...
156+
[^] Write tables in query response attributes:
157+
set @@session.response_attrs_contain_read_tables_bytes = default;
158+
use test;
159+
drop table tab1;
160+
drop table tab2;
161+
drop table tab3;
162+
drop table averyveryveryveryveryveryverylongtablename;
163+
drop view view1;
164+
drop view view2;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Default value of response_attrs_contain_read_tables_bytes
2+
SELECT @@global.response_attrs_contain_read_tables_bytes;
3+
@@global.response_attrs_contain_read_tables_bytes
4+
0
5+
response_attrs_contain_read_tables_bytes is set to 1 KB
6+
set @@global.response_attrs_contain_read_tables_bytes = 1024;
7+
SELECT @@global.response_attrs_contain_read_tables_bytes;
8+
@@global.response_attrs_contain_read_tables_bytes
9+
1024
10+
response_attrs_contain_read_tables_bytes is set to 1 MB
11+
set @@global.response_attrs_contain_read_tables_bytes = 1048576;
12+
SELECT @@global.response_attrs_contain_read_tables_bytes;
13+
@@global.response_attrs_contain_read_tables_bytes
14+
1048576
15+
setting read_control to a negative number throws warning
16+
set @@global.response_attrs_contain_read_tables_bytes = -10000;
17+
Warnings:
18+
Warning 1292 Truncated incorrect response_attrs_contain_read_tables_bytes value: '-10000'
19+
SELECT @@global.response_attrs_contain_read_tables_bytes;
20+
@@global.response_attrs_contain_read_tables_bytes
21+
0
22+
setting read_control to a random string gives error
23+
set @@global.response_attrs_contain_read_tables_bytes = 'XYZ';
24+
ERROR 42000: Incorrect argument type to variable 'response_attrs_contain_read_tables_bytes'
25+
SELECT @@global.response_attrs_contain_read_tables_bytes;
26+
@@global.response_attrs_contain_read_tables_bytes
27+
0
28+
restore the default value
29+
SET @@global.response_attrs_contain_read_tables_bytes = 0;
30+
SELECT @@global.response_attrs_contain_read_tables_bytes;
31+
@@global.response_attrs_contain_read_tables_bytes
32+
0
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Default value of response_attrs_contain_write_tables_bytes
2+
SELECT @@global.response_attrs_contain_write_tables_bytes;
3+
@@global.response_attrs_contain_write_tables_bytes
4+
0
5+
response_attrs_contain_write_tables_bytes is set to 1 KB
6+
set @@global.response_attrs_contain_write_tables_bytes = 1024;
7+
SELECT @@global.response_attrs_contain_write_tables_bytes;
8+
@@global.response_attrs_contain_write_tables_bytes
9+
1024
10+
response_attrs_contain_write_tables_bytes is set to 1 MB
11+
set @@global.response_attrs_contain_write_tables_bytes = 1048576;
12+
SELECT @@global.response_attrs_contain_write_tables_bytes;
13+
@@global.response_attrs_contain_write_tables_bytes
14+
1048576
15+
setting write_control to a negative number throws warning
16+
set @@global.response_attrs_contain_write_tables_bytes = -10000;
17+
Warnings:
18+
Warning 1292 Truncated incorrect response_attrs_contain_write_tables_bytes value: '-10000'
19+
SELECT @@global.response_attrs_contain_write_tables_bytes;
20+
@@global.response_attrs_contain_write_tables_bytes
21+
0
22+
setting write_control to a random string gives error
23+
set @@global.response_attrs_contain_write_tables_bytes = 'XYZ';
24+
ERROR 42000: Incorrect argument type to variable 'response_attrs_contain_write_tables_bytes'
25+
SELECT @@global.response_attrs_contain_write_tables_bytes;
26+
@@global.response_attrs_contain_write_tables_bytes
27+
0
28+
restore the default value
29+
SET @@global.response_attrs_contain_write_tables_bytes = 0;
30+
SELECT @@global.response_attrs_contain_write_tables_bytes;
31+
@@global.response_attrs_contain_write_tables_bytes
32+
0
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
-- source include/load_sysvars.inc
2+
3+
####################################################
4+
# Variable: response_attrs_contain_read_tables_bytes
5+
####################################################
6+
7+
####
8+
# Verify the default value
9+
####
10+
--echo Default value of response_attrs_contain_read_tables_bytes
11+
SELECT @@global.response_attrs_contain_read_tables_bytes;
12+
13+
####
14+
## Verify that the variable is dynamic
15+
####
16+
--echo response_attrs_contain_read_tables_bytes is set to 1 KB
17+
set @@global.response_attrs_contain_read_tables_bytes = 1024;
18+
SELECT @@global.response_attrs_contain_read_tables_bytes;
19+
20+
--echo response_attrs_contain_read_tables_bytes is set to 1 MB
21+
set @@global.response_attrs_contain_read_tables_bytes = 1048576;
22+
SELECT @@global.response_attrs_contain_read_tables_bytes;
23+
24+
-- echo setting read_control to a negative number throws warning
25+
set @@global.response_attrs_contain_read_tables_bytes = -10000;
26+
SELECT @@global.response_attrs_contain_read_tables_bytes;
27+
28+
-- echo setting read_control to a random string gives error
29+
--error ER_WRONG_TYPE_FOR_VAR
30+
set @@global.response_attrs_contain_read_tables_bytes = 'XYZ';
31+
SELECT @@global.response_attrs_contain_read_tables_bytes;
32+
33+
####
34+
## Restore the default value
35+
####
36+
-- echo restore the default value
37+
SET @@global.response_attrs_contain_read_tables_bytes = 0;
38+
SELECT @@global.response_attrs_contain_read_tables_bytes;
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
-- source include/load_sysvars.inc
2+
3+
####################################################
4+
# Variable: response_attrs_contain_write_tables_bytes
5+
####################################################
6+
7+
####
8+
# Verify the default value
9+
####
10+
--echo Default value of response_attrs_contain_write_tables_bytes
11+
SELECT @@global.response_attrs_contain_write_tables_bytes;
12+
13+
####
14+
## Verify that the variable is dynamic
15+
####
16+
--echo response_attrs_contain_write_tables_bytes is set to 1 KB
17+
set @@global.response_attrs_contain_write_tables_bytes = 1024;
18+
SELECT @@global.response_attrs_contain_write_tables_bytes;
19+
20+
--echo response_attrs_contain_write_tables_bytes is set to 1 MB
21+
set @@global.response_attrs_contain_write_tables_bytes = 1048576;
22+
SELECT @@global.response_attrs_contain_write_tables_bytes;
23+
24+
-- echo setting write_control to a negative number throws warning
25+
set @@global.response_attrs_contain_write_tables_bytes = -10000;
26+
SELECT @@global.response_attrs_contain_write_tables_bytes;
27+
28+
-- echo setting write_control to a random string gives error
29+
--error ER_WRONG_TYPE_FOR_VAR
30+
set @@global.response_attrs_contain_write_tables_bytes = 'XYZ';
31+
SELECT @@global.response_attrs_contain_write_tables_bytes;
32+
33+
####
34+
## Restore the default value
35+
####
36+
-- echo restore the default value
37+
SET @@global.response_attrs_contain_write_tables_bytes = 0;
38+
SELECT @@global.response_attrs_contain_write_tables_bytes;

0 commit comments

Comments
 (0)