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

Commit bef6027

Browse files
lthHerman Lee
authored andcommitted
Validate expected schema provided from client
Summary: This diff adds support to allow the client to send to the server, what it expects the schema to be. The server can then compare what the client expects with what the actual schema is on the server, and error out if needed. This currently does not support allowing type to be narrower than needed (eg. tinyint instead of bigint), as we're doing a direct type comparison. Reviewed By: mzait Differential Revision: D29944483
1 parent c24793f commit bef6027

12 files changed

Lines changed: 650 additions & 5 deletions

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2733,6 +2733,8 @@ The following options may be given as the first argument:
27332733
5.6
27342734
-u, --user=name Run mysqld daemon as user.
27352735
--validate-config Validate the server configuration specified by the user.
2736+
--validate-schema-from-attributes
2737+
Check if server schema matches client expected schema.
27362738
--validate-user-plugins
27372739
Turns on additional validation of authentication plugins
27382740
assigned to user accounts.
@@ -3594,6 +3596,7 @@ update-binlog-pos-threshold 5242880
35943596
upgrade AUTO
35953597
use-fb-json-functions
35963598
validate-config FALSE
3599+
validate-schema-from-attributes FALSE
35973600
validate-user-plugins TRUE
35983601
verbose TRUE
35993602
wait-for-hlc-sleep-scaling-factor 0.75
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
create database db1;
2+
use db1;
3+
create table abc (a varchar(25), b int);
4+
set validate_schema_from_attributes = on;
5+
select * from abc;
6+
a b
7+
select * from abc;
8+
ERROR HY000: Schema on server is different from schema expected from client: missing column for column 'c'
9+
select * from abc;
10+
a b
11+
select * from abc;
12+
ERROR HY000: Schema on server is different from schema expected from client: type too narrow for column 'a'
13+
select * from abc;
14+
ERROR HY000: Schema on server is different from schema expected from client: type mismatch for column 'a'
15+
select * from abc;
16+
ERROR HY000: Schema on server is different from schema expected from client: type mismatch for column 'a'
17+
select * from abc;
18+
ERROR HY000: Schema on server is different from schema expected from client: type mismatch for column 'a'
19+
select * from abc;
20+
ERROR HY000: Schema on server is different from schema expected from client: type mismatch for column 'a'
21+
select * from abc;
22+
ERROR HY000: Schema on server is different from schema expected from client: type mismatch for column 'a'
23+
select * from abc;
24+
ERROR HY000: Schema on server is different from schema expected from client: type mismatch for column 'a'
25+
select * from abc;
26+
ERROR HY000: Schema on server is different from schema expected from client: type mismatch for column 'a'
27+
select * from abc;
28+
ERROR HY000: Schema on server is different from schema expected from client: type mismatch for column 'a'
29+
select * from abc;
30+
ERROR HY000: Schema on server is different from schema expected from client: type mismatch for column 'a'
31+
select * from abc;
32+
ERROR HY000: Schema on server is different from schema expected from client: type mismatch for column 'a'
33+
select * from abc;
34+
ERROR HY000: Schema on server is different from schema expected from client: type mismatch for column 'a'
35+
select * from abc;
36+
ERROR HY000: Schema on server is different from schema expected from client: type mismatch for column 'a'
37+
select * from abc;
38+
ERROR HY000: Schema on server is different from schema expected from client: type mismatch for column 'a'
39+
select * from abc;
40+
ERROR HY000: Schema on server is different from schema expected from client: type mismatch for column 'a'
41+
select * from abc;
42+
a b
43+
select * from abc;
44+
ERROR HY000: Schema on server is different from schema expected from client: type mismatch for column 'a'
45+
select * from abc;
46+
ERROR HY000: Schema on server is different from schema expected from client: type mismatch for column 'a'
47+
select * from abc;
48+
ERROR HY000: Schema on server is different from schema expected from client: type mismatch for column 'a'
49+
select * from abc;
50+
ERROR HY000: Schema on server is different from schema expected from client: type mismatch for column 'a'
51+
select * from abc;
52+
ERROR HY000: Schema on server is different from schema expected from client: type mismatch for column 'a'
53+
select * from abc;
54+
ERROR HY000: Schema on server is different from schema expected from client: type mismatch for column 'a'
55+
select * from abc;
56+
ERROR HY000: Malformed query attributes '[["db1","abc",{"a":[200,25],"b":[3,0]}]]'
57+
create table abcd (a int, b int, c int, d int, e int, f int, g int, h int, i int, j int, k int, l int, m int, n int, o int, p int, q int, r int, s int, t int, u int, v int, w int, x int, y int, z int, aa int, ab int, ac int, ad int, ae int, af int, ag int);
58+
select * from abcd;
59+
a b c d e f g h i j k l m n o p q r s t u v w x y z aa ab ac ad ae af ag
60+
select * from abcd;
61+
ERROR HY000: Schema on server is different from schema expected from client: missing column for column 'ah'
62+
set validate_schema_from_attributes = off;
63+
select * from abc;
64+
a b
65+
drop database db1;
Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
#
2+
# Variable name : validate_schema_from_attributes
3+
# Scope : Global & Session
4+
#
5+
# Global - default
6+
SELECT @@global.validate_schema_from_attributes;
7+
@@global.validate_schema_from_attributes
8+
0
9+
# Session - default
10+
SELECT @@session.validate_schema_from_attributes;
11+
@@session.validate_schema_from_attributes
12+
0
13+
14+
# via performance_schema.global_variables
15+
select * from performance_schema.global_variables where variable_name like '%validate_schema_from_attributes%';
16+
VARIABLE_NAME VARIABLE_VALUE
17+
validate_schema_from_attributes OFF
18+
# via performance_schema.session_variables
19+
select * from performance_schema.session_variables where variable_name like '%validate_schema_from_attributes%';
20+
VARIABLE_NAME VARIABLE_VALUE
21+
validate_schema_from_attributes OFF
22+
SET @global_saved_tmp = @@global.validate_schema_from_attributes;
23+
24+
# Altering global variable's value
25+
SET @@global.validate_schema_from_attributes = 0;
26+
SELECT @@global.validate_schema_from_attributes;
27+
@@global.validate_schema_from_attributes
28+
0
29+
SELECT @@session.validate_schema_from_attributes;
30+
@@session.validate_schema_from_attributes
31+
0
32+
SET @@global.validate_schema_from_attributes = TrUe;
33+
SELECT @@global.validate_schema_from_attributes;
34+
@@global.validate_schema_from_attributes
35+
1
36+
SELECT @@session.validate_schema_from_attributes;
37+
@@session.validate_schema_from_attributes
38+
0
39+
SET @@global.validate_schema_from_attributes = FaLsE;
40+
SELECT @@global.validate_schema_from_attributes;
41+
@@global.validate_schema_from_attributes
42+
0
43+
SELECT @@session.validate_schema_from_attributes;
44+
@@session.validate_schema_from_attributes
45+
0
46+
47+
# Altering session variable's value
48+
SET @@session.validate_schema_from_attributes = 0;
49+
SELECT @@global.validate_schema_from_attributes;
50+
@@global.validate_schema_from_attributes
51+
0
52+
SELECT @@session.validate_schema_from_attributes;
53+
@@session.validate_schema_from_attributes
54+
0
55+
56+
SET @@session.validate_schema_from_attributes = TrUe;
57+
SELECT @@global.validate_schema_from_attributes;
58+
@@global.validate_schema_from_attributes
59+
0
60+
SELECT @@session.validate_schema_from_attributes;
61+
@@session.validate_schema_from_attributes
62+
1
63+
64+
SET @@session.validate_schema_from_attributes = FaLsE;
65+
SELECT @@global.validate_schema_from_attributes;
66+
@@global.validate_schema_from_attributes
67+
0
68+
SELECT @@session.validate_schema_from_attributes;
69+
@@session.validate_schema_from_attributes
70+
0
71+
72+
SET @@session.validate_schema_from_attributes = TrUe;
73+
SELECT @@global.validate_schema_from_attributes;
74+
@@global.validate_schema_from_attributes
75+
0
76+
SELECT @@session.validate_schema_from_attributes;
77+
@@session.validate_schema_from_attributes
78+
1
79+
80+
# Variables' values in a new session.
81+
# Global - expect 0
82+
SELECT @@global.validate_schema_from_attributes;
83+
@@global.validate_schema_from_attributes
84+
0
85+
86+
# Session - expect 0
87+
SELECT @@session.validate_schema_from_attributes;
88+
@@session.validate_schema_from_attributes
89+
0
90+
91+
# Switching to the default connection.
92+
SELECT @@global.validate_schema_from_attributes;
93+
@@global.validate_schema_from_attributes
94+
0
95+
SELECT @@session.validate_schema_from_attributes;
96+
@@session.validate_schema_from_attributes
97+
1
98+
99+
# Test if DEFAULT is working as expected.
100+
SET @@global.validate_schema_from_attributes = DEFAULT;
101+
SET @@session.validate_schema_from_attributes = DEFAULT;
102+
103+
# Global - expect 0
104+
SELECT @@global.validate_schema_from_attributes;
105+
@@global.validate_schema_from_attributes
106+
0
107+
# Session - expect 0
108+
SELECT @@session.validate_schema_from_attributes;
109+
@@session.validate_schema_from_attributes
110+
0
111+
112+
# Variables' values in a new session (con2).
113+
SELECT @@global.validate_schema_from_attributes;
114+
@@global.validate_schema_from_attributes
115+
0
116+
SELECT @@session.validate_schema_from_attributes;
117+
@@session.validate_schema_from_attributes
118+
0
119+
120+
# Altering session should not affect global.
121+
SET @@session.validate_schema_from_attributes = TRUE;
122+
SELECT @@global.validate_schema_from_attributes;
123+
@@global.validate_schema_from_attributes
124+
0
125+
SELECT @@session.validate_schema_from_attributes;
126+
@@session.validate_schema_from_attributes
127+
1
128+
129+
# Variables' values in a new session (con3).
130+
# Altering global should not affect session.
131+
SET @@global.validate_schema_from_attributes = ON;
132+
SELECT @@global.validate_schema_from_attributes;
133+
@@global.validate_schema_from_attributes
134+
1
135+
SELECT @@session.validate_schema_from_attributes;
136+
@@session.validate_schema_from_attributes
137+
0
138+
139+
# Switching to the default connection.
140+
# Restoring the original values.
141+
SET @@global.validate_schema_from_attributes = DEFAULT;
142+
SET @@session.validate_schema_from_attributes = DEFAULT;
143+
# End of tests.
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
-- source include/load_sysvars.inc
2+
3+
--echo #
4+
--echo # Variable name : validate_schema_from_attributes
5+
--echo # Scope : Global & Session
6+
--echo #
7+
8+
--echo # Global - default
9+
SELECT @@global.validate_schema_from_attributes;
10+
--echo # Session - default
11+
SELECT @@session.validate_schema_from_attributes;
12+
--echo
13+
14+
--echo # via performance_schema.global_variables
15+
--disable_warnings
16+
select * from performance_schema.global_variables where variable_name like '%validate_schema_from_attributes%';
17+
--enable_warnings
18+
19+
--echo # via performance_schema.session_variables
20+
--disable_warnings
21+
select * from performance_schema.session_variables where variable_name like '%validate_schema_from_attributes%';
22+
--enable_warnings
23+
24+
# Save the global value to be used to restore the original value.
25+
SET @global_saved_tmp = @@global.validate_schema_from_attributes;
26+
--echo
27+
28+
--echo # Altering global variable's value
29+
SET @@global.validate_schema_from_attributes = 0;
30+
SELECT @@global.validate_schema_from_attributes;
31+
SELECT @@session.validate_schema_from_attributes;
32+
33+
SET @@global.validate_schema_from_attributes = TrUe;
34+
SELECT @@global.validate_schema_from_attributes;
35+
SELECT @@session.validate_schema_from_attributes;
36+
37+
SET @@global.validate_schema_from_attributes = FaLsE;
38+
SELECT @@global.validate_schema_from_attributes;
39+
SELECT @@session.validate_schema_from_attributes;
40+
--echo
41+
42+
--echo # Altering session variable's value
43+
SET @@session.validate_schema_from_attributes = 0;
44+
SELECT @@global.validate_schema_from_attributes;
45+
SELECT @@session.validate_schema_from_attributes;
46+
--echo
47+
48+
SET @@session.validate_schema_from_attributes = TrUe;
49+
SELECT @@global.validate_schema_from_attributes;
50+
SELECT @@session.validate_schema_from_attributes;
51+
--echo
52+
53+
SET @@session.validate_schema_from_attributes = FaLsE;
54+
SELECT @@global.validate_schema_from_attributes;
55+
SELECT @@session.validate_schema_from_attributes;
56+
--echo
57+
58+
SET @@session.validate_schema_from_attributes = TrUe;
59+
SELECT @@global.validate_schema_from_attributes;
60+
SELECT @@session.validate_schema_from_attributes;
61+
--echo
62+
63+
--echo # Variables' values in a new session.
64+
connect (con1,"127.0.0.1",root,,test,$MASTER_MYPORT,);
65+
66+
--echo # Global - expect 0
67+
SELECT @@global.validate_schema_from_attributes;
68+
--echo
69+
--echo # Session - expect 0
70+
SELECT @@session.validate_schema_from_attributes;
71+
--echo
72+
73+
--echo # Switching to the default connection.
74+
connection default;
75+
76+
SELECT @@global.validate_schema_from_attributes;
77+
SELECT @@session.validate_schema_from_attributes;
78+
--echo
79+
80+
--echo # Test if DEFAULT is working as expected.
81+
SET @@global.validate_schema_from_attributes = DEFAULT;
82+
SET @@session.validate_schema_from_attributes = DEFAULT;
83+
--echo
84+
85+
--echo # Global - expect 0
86+
SELECT @@global.validate_schema_from_attributes;
87+
--echo # Session - expect 0
88+
SELECT @@session.validate_schema_from_attributes;
89+
--echo
90+
91+
--echo # Variables' values in a new session (con2).
92+
connect (con2,"127.0.0.1",root,,test,$MASTER_MYPORT,);
93+
94+
SELECT @@global.validate_schema_from_attributes;
95+
SELECT @@session.validate_schema_from_attributes;
96+
--echo
97+
98+
--echo # Altering session should not affect global.
99+
SET @@session.validate_schema_from_attributes = TRUE;
100+
SELECT @@global.validate_schema_from_attributes;
101+
SELECT @@session.validate_schema_from_attributes;
102+
--echo
103+
104+
--echo # Variables' values in a new session (con3).
105+
connect (con3,"127.0.0.1",root,,test,$MASTER_MYPORT,);
106+
107+
--echo # Altering global should not affect session.
108+
SET @@global.validate_schema_from_attributes = ON;
109+
SELECT @@global.validate_schema_from_attributes;
110+
SELECT @@session.validate_schema_from_attributes;
111+
--echo
112+
113+
--echo # Switching to the default connection.
114+
connection default;
115+
116+
--echo # Restoring the original values.
117+
SET @@global.validate_schema_from_attributes = DEFAULT;
118+
SET @@session.validate_schema_from_attributes = DEFAULT;
119+
120+
--echo # End of tests.

0 commit comments

Comments
 (0)