Skip to content

Commit d2eba35

Browse files
MDEV-34716 Allow arbitrary options in CREATE SERVER
The existing syntax for CREATE SERVER CREATE [OR REPLACE] SERVER [IF NOT EXISTS] server_name FOREIGN DATA WRAPPER wrapper_name OPTIONS (option [, option] ...) option: { HOST character-literal | DATABASE character-literal | USER character-literal | PASSWORD character-literal | SOCKET character-literal | OWNER character-literal | PORT numeric-literal } With this change we have: option: { HOST character-literal | DATABASE character-literal | USER character-literal | PASSWORD character-literal | SOCKET character-literal | OWNER character-literal | PORT numeric-literal | PORT quoted-numerical-literal | identifier character-literal} We store these options as a JSON field in the mysql.servers system table. We retain the restriction that PORT needs to be a number, but also allow it to be a quoted number, so that SHOW CREATE SERVER can be used for dumping. Without an accompanied implementation of SHOW CREATE SERVER, some mysqldump tests will fail. Therefore this commit should be immediately followed by the one implementating SHOW CREATE SERVER, with testing covering both.
1 parent 2345407 commit d2eba35

21 files changed

+222
-19
lines changed

mysql-test/main/information_schema.result

+6
Original file line numberDiff line numberDiff line change
@@ -914,6 +914,7 @@ sys processlist current_statement
914914
sys processlist last_statement
915915
sys schema_auto_increment_columns column_type
916916
sys schema_table_lock_waits waiting_query
917+
mysql servers Options
917918
sys session current_statement
918919
sys session last_statement
919920
sys statement_analysis query
@@ -2437,6 +2438,7 @@ using (CONSTRAINT_CATALOG, CONSTRAINT_SCHEMA, TABLE_NAME, CONSTRAINT_NAME)
24372438
;
24382439
TABLE_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE
24392440
mysql global_priv Priv json_valid(`Priv`)
2441+
mysql servers Options json_valid(`Options`)
24402442
test t a `i` > 0
24412443
select
24422444
tc.TABLE_SCHEMA,
@@ -2449,6 +2451,7 @@ using (CONSTRAINT_CATALOG, CONSTRAINT_SCHEMA, TABLE_NAME, CONSTRAINT_NAME)
24492451
;
24502452
TABLE_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE
24512453
mysql global_priv Priv json_valid(`Priv`)
2454+
mysql servers Options json_valid(`Options`)
24522455
test t a `i` > 0
24532456
select
24542457
tc.TABLE_SCHEMA,
@@ -2460,6 +2463,7 @@ NATURAL join information_schema.CHECK_CONSTRAINTS cc
24602463
;
24612464
TABLE_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE
24622465
mysql global_priv Priv json_valid(`Priv`)
2466+
mysql servers Options json_valid(`Options`)
24632467
test t a `i` > 0
24642468
select
24652469
tc.TABLE_SCHEMA,
@@ -2471,6 +2475,7 @@ NATURAL join information_schema.TABLE_CONSTRAINTS tc
24712475
;
24722476
TABLE_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE
24732477
mysql global_priv Priv json_valid(`Priv`)
2478+
mysql servers Options json_valid(`Options`)
24742479
test t a `i` > 0
24752480
select
24762481
tc.TABLE_SCHEMA,
@@ -2485,6 +2490,7 @@ using (CONSTRAINT_CATALOG, CONSTRAINT_SCHEMA, TABLE_NAME, CONSTRAINT_NAME)
24852490
;
24862491
TABLE_SCHEMA TABLE_NAME CONSTRAINT_NAME CHECK_CLAUSE CONSTRAINT_CATALOG CONSTRAINT_SCHEMA
24872492
mysql global_priv Priv json_valid(`Priv`) def mysql
2493+
mysql servers Options json_valid(`Options`) def mysql
24882494
test t a `i` > 0 def test
24892495
drop table t;
24902496
#

mysql-test/main/servers.result

+8-8
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,25 @@ set sql_mode="";
44
#
55
CREATE SERVER s1 FOREIGN DATA WRAPPER mysql OPTIONS(HOST 'localhost');
66
SELECT * FROM mysql.servers;
7-
Server_name Host Db Username Password Port Socket Wrapper Owner
8-
s1 localhost 3306 mysql
7+
Server_name Host Db Username Password Port Socket Wrapper Owner Options
8+
s1 localhost 3306 mysql {"HOST": "localhost"}
99
DROP SERVER s1;
1010
CREATE SERVER s1 FOREIGN DATA WRAPPER foo OPTIONS(USER 'bar');
1111
SELECT * FROM mysql.servers;
12-
Server_name Host Db Username Password Port Socket Wrapper Owner
13-
s1 bar 0 foo
12+
Server_name Host Db Username Password Port Socket Wrapper Owner Options
13+
s1 bar 0 foo {"USER": "bar"}
1414
DROP SERVER s1;
1515
CREATE SERVER s1 FOREIGN DATA WRAPPER mysql OPTIONS(USER 'bar');
1616
ERROR HY000: Can't create federated table. Foreign data src error: either HOST or SOCKET must be set
1717
CREATE SERVER s1 FOREIGN DATA WRAPPER mysql OPTIONS(HOST 'bar');
1818
SELECT * FROM mysql.servers;
19-
Server_name Host Db Username Password Port Socket Wrapper Owner
20-
s1 bar 3306 mysql
19+
Server_name Host Db Username Password Port Socket Wrapper Owner Options
20+
s1 bar 3306 mysql {"HOST": "bar"}
2121
DROP SERVER s1;
2222
CREATE SERVER s1 FOREIGN DATA WRAPPER mysql OPTIONS(SOCKET 'bar');
2323
SELECT * FROM mysql.servers;
24-
Server_name Host Db Username Password Port Socket Wrapper Owner
25-
s1 3306 bar mysql
24+
Server_name Host Db Username Password Port Socket Wrapper Owner Options
25+
s1 3306 bar mysql {"SOCKET": "bar"}
2626
DROP SERVER s1;
2727
CREATE SERVER s1 FOREIGN DATA WRAPPER mysql OPTIONS(SOCKET '/tmp/1234567890_1234567890_1234567890_1234567890_1234567890_1234567890.sock');
2828
SELECT Socket FROM mysql.servers where Server_name = 's1';

mysql-test/main/system_mysql_db.result

+1
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ servers CREATE TABLE `servers` (
133133
`Socket` char(108) NOT NULL DEFAULT '',
134134
`Wrapper` char(64) NOT NULL DEFAULT '',
135135
`Owner` varchar(512) NOT NULL DEFAULT '',
136+
`Options` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL DEFAULT '{}' CHECK (json_valid(`Options`)),
136137
PRIMARY KEY (`Server_name`)
137138
) ENGINE=Aria DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci PAGE_CHECKSUM=1 TRANSACTIONAL=1 COMMENT='MySQL Foreign Servers table'
138139
show create table proc;

mysql-test/main/system_mysql_db_fix40123.result

+1
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ servers CREATE TABLE `servers` (
171171
`Socket` char(108) NOT NULL DEFAULT '',
172172
`Wrapper` char(64) NOT NULL DEFAULT '',
173173
`Owner` varchar(512) NOT NULL DEFAULT '',
174+
`Options` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL DEFAULT '{}' CHECK (json_valid(`Options`)),
174175
PRIMARY KEY (`Server_name`)
175176
) ENGINE=Aria DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci PAGE_CHECKSUM=1 TRANSACTIONAL=1 COMMENT='MySQL Foreign Servers table'
176177
show create table proc;

mysql-test/main/system_mysql_db_fix50030.result

+1
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ servers CREATE TABLE `servers` (
175175
`Socket` char(108) NOT NULL DEFAULT '',
176176
`Wrapper` char(64) NOT NULL DEFAULT '',
177177
`Owner` varchar(512) NOT NULL DEFAULT '',
178+
`Options` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL DEFAULT '{}' CHECK (json_valid(`Options`)),
178179
PRIMARY KEY (`Server_name`)
179180
) ENGINE=Aria DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci PAGE_CHECKSUM=1 TRANSACTIONAL=1 COMMENT='MySQL Foreign Servers table'
180181
show create table proc;

mysql-test/main/system_mysql_db_fix50117.result

+1
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ servers CREATE TABLE `servers` (
155155
`Socket` char(108) NOT NULL DEFAULT '',
156156
`Wrapper` char(64) NOT NULL DEFAULT '',
157157
`Owner` varchar(512) NOT NULL DEFAULT '',
158+
`Options` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL DEFAULT '{}' CHECK (json_valid(`Options`)),
158159
PRIMARY KEY (`Server_name`)
159160
) ENGINE=Aria DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci PAGE_CHECKSUM=1 TRANSACTIONAL=1 COMMENT='MySQL Foreign Servers table'
160161
show create table proc;

mysql-test/main/system_mysql_db_fix50568.result

+1
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ servers CREATE TABLE `servers` (
176176
`Socket` char(108) NOT NULL DEFAULT '',
177177
`Wrapper` char(64) NOT NULL DEFAULT '',
178178
`Owner` varchar(512) NOT NULL DEFAULT '',
179+
`Options` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL DEFAULT '{}' CHECK (json_valid(`Options`)),
179180
PRIMARY KEY (`Server_name`)
180181
) ENGINE=Aria DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci PAGE_CHECKSUM=1 TRANSACTIONAL=1 COMMENT='MySQL Foreign Servers table'
181182
show create table proc;

mysql-test/suite/federated/federated_server.result

+4-4
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@ PORT SLAVE_PORT,
6161
SOCKET '',
6262
OWNER 'root');
6363
select * from mysql.servers order by db;
64-
Server_name Host Db Username Password Port Socket Wrapper Owner
65-
server_one 127.0.0.1 first_db root SLAVE_PORT mysql root
66-
server_two 127.0.0.1 second_db root SLAVE_PORT mysql root
64+
Server_name Host Db Username Password Port Socket Wrapper Owner Options
65+
server_one 127.0.0.1 first_db root SLAVE_PORT mysql root {"HOST": "127.0.0.1", "DATABASE": "first_db", "USER": "root", "PASSWORD": "", "PORT": "SLAVE_PORT", "SOCKET": "", "OWNER": "root"}
66+
server_two 127.0.0.1 second_db root SLAVE_PORT mysql root {"HOST": "127.0.0.1", "DATABASE": "second_db", "USER": "root", "PASSWORD": "", "PORT": "SLAVE_PORT", "SOCKET": "", "OWNER": "root"}
6767
DROP TABLE IF EXISTS federated.old;
6868
Warnings:
6969
Note 1051 Unknown table 'federated.old'
@@ -161,7 +161,7 @@ drop table federated.t1;
161161
drop server 'server_one';
162162
drop server 'server_two';
163163
select * from mysql.servers order by db;
164-
Server_name Host Db Username Password Port Socket Wrapper Owner
164+
Server_name Host Db Username Password Port Socket Wrapper Owner Options
165165
connection slave;
166166
drop table first_db.t1;
167167
drop table second_db.t1;

mysql-test/suite/funcs_1/r/is_check_constraints.result

+3
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ SELECT * FROM information_schema.check_constraints;
139139
CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME LEVEL CHECK_CLAUSE
140140
def db t1 CONSTRAINT_1 Table `b` > 0
141141
def mysql global_priv Priv Column json_valid(`Priv`)
142+
def mysql servers Options Column json_valid(`Options`)
142143
CONNECT con1,localhost, foo,, db;
143144
SELECT a FROM t1;
144145
a
@@ -172,6 +173,7 @@ t CREATE TABLE `t` (
172173
) ENGINE=MyISAM DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_uca1400_ai_ci
173174
select * from information_schema.table_constraints where CONSTRAINT_TYPE='CHECK';
174175
CONSTRAINT_CATALOG CONSTRAINT_SCHEMA CONSTRAINT_NAME TABLE_SCHEMA TABLE_NAME CONSTRAINT_TYPE
176+
def mysql Options mysql servers CHECK
175177
def mysql Priv mysql global_priv CHECK
176178
def test CONSTRAINT_1 test t CHECK
177179
def test t1 test t CHECK
@@ -181,6 +183,7 @@ def test tc_1 test t CHECK
181183
select * from information_schema.check_constraints;
182184
CONSTRAINT_CATALOG CONSTRAINT_SCHEMA TABLE_NAME CONSTRAINT_NAME LEVEL CHECK_CLAUSE
183185
def mysql global_priv Priv Column json_valid(`Priv`)
186+
def mysql servers Options Column json_valid(`Options`)
184187
def test t CONSTRAINT_1 Table `t0` > 0
185188
def test t t1 Column `t1` < 0
186189
def test t t2 Column `t2` < -1

mysql-test/suite/funcs_1/r/is_columns_mysql.result

+2
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ def mysql roles_mapping Role 3 '' NO char 128 384 NULL NULL NULL utf8mb3 utf8mb3
160160
def mysql roles_mapping User 2 '' NO char 128 384 NULL NULL NULL utf8mb3 utf8mb3_bin char(128) PRI select,insert,update,references NEVER NULL NO NO
161161
def mysql servers Db 3 '' NO char 64 192 NULL NULL NULL utf8mb3 utf8mb3_general_ci char(64) select,insert,update,references NEVER NULL NO NO
162162
def mysql servers Host 2 '' NO varchar 2048 6144 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(2048) select,insert,update,references NEVER NULL NO NO
163+
def mysql servers Options 10 '{}' NO longtext 4294967295 4294967295 NULL NULL NULL utf8mb4 utf8mb4_bin longtext select,insert,update,references NEVER NULL NO NO
163164
def mysql servers Owner 9 '' NO varchar 512 1536 NULL NULL NULL utf8mb3 utf8mb3_general_ci varchar(512) select,insert,update,references NEVER NULL NO NO
164165
def mysql servers Password 5 '' NO char 64 192 NULL NULL NULL utf8mb3 utf8mb3_general_ci char(64) select,insert,update,references NEVER NULL NO NO
165166
def mysql servers Port 6 0 NO int NULL NULL 10 0 NULL NULL NULL int(4) select,insert,update,references NEVER NULL NO NO
@@ -495,6 +496,7 @@ NULL mysql servers Port int NULL NULL NULL NULL int(4)
495496
3.0000 mysql servers Socket char 108 324 utf8mb3 utf8mb3_general_ci char(108)
496497
3.0000 mysql servers Wrapper char 64 192 utf8mb3 utf8mb3_general_ci char(64)
497498
3.0000 mysql servers Owner varchar 512 1536 utf8mb3 utf8mb3_general_ci varchar(512)
499+
1.0000 mysql servers Options longtext 4294967295 4294967295 utf8mb4 utf8mb4_bin longtext
498500
NULL mysql slow_log start_time timestamp NULL NULL NULL NULL timestamp(6)
499501
1.0000 mysql slow_log user_host mediumtext 16777215 16777215 utf8mb3 utf8mb3_general_ci mediumtext
500502
NULL mysql slow_log query_time time NULL NULL NULL NULL time(6)

mysql-test/suite/funcs_1/r/is_table_constraints.result

+1
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ def mysql PRIMARY mysql proc
8181
def mysql PRIMARY mysql procs_priv
8282
def mysql PRIMARY mysql proxies_priv
8383
def mysql Host mysql roles_mapping
84+
def mysql Options mysql servers
8485
def mysql PRIMARY mysql servers
8586
def mysql PRIMARY mysql tables_priv
8687
def mysql PRIMARY mysql table_stats

mysql-test/suite/funcs_1/r/is_table_constraints_mysql.result

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def mysql PRIMARY mysql proc PRIMARY KEY
3030
def mysql PRIMARY mysql procs_priv PRIMARY KEY
3131
def mysql PRIMARY mysql proxies_priv PRIMARY KEY
3232
def mysql Host mysql roles_mapping UNIQUE
33+
def mysql Options mysql servers CHECK
3334
def mysql PRIMARY mysql servers PRIMARY KEY
3435
def mysql PRIMARY mysql tables_priv PRIMARY KEY
3536
def mysql PRIMARY mysql table_stats PRIMARY KEY

mysql-test/suite/funcs_1/r/is_tables_mysql.result

+1-1
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ TABLE_SCHEMA mysql
515515
TABLE_NAME servers
516516
TABLE_TYPE BASE TABLE
517517
ENGINE MYISAM_OR_MARIA
518-
VERSION 10
518+
VERSION 11
519519
ROW_FORMAT DYNAMIC_OR_PAGE
520520
TABLE_ROWS #TBLR#
521521
AVG_ROW_LENGTH #ARL#

mysql-test/suite/galera/r/galera_server.result

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ OPTIONS (HOST 'foo');
88
connection node_2;
99
# On node_2
1010
SELECT * FROM mysql.servers;
11-
Server_name Host Db Username Password Port Socket Wrapper Owner
12-
s1 foo 3306 mysql
11+
Server_name Host Db Username Password Port Socket Wrapper Owner Options
12+
s1 foo 3306 mysql {"HOST": "foo"}
1313
ALTER SERVER s1
1414
OPTIONS (HOST 'bar');
1515
connection node_1;
1616
# On node_1
1717
SELECT * FROM mysql.servers;
18-
Server_name Host Db Username Password Port Socket Wrapper Owner
19-
s1 bar 3306 mysql
18+
Server_name Host Db Username Password Port Socket Wrapper Owner Options
19+
s1 bar 3306 mysql {"HOST": "bar"}
2020
DROP SERVER s1;
2121
connection node_2;
2222
# On node_2

scripts/mariadb_system_tables.sql

+1-1
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ CREATE TABLE IF NOT EXISTS func ( name char(64) binary DEFAULT '' NOT NULL, ret
109109
CREATE TABLE IF NOT EXISTS plugin ( name varchar(64) DEFAULT '' NOT NULL, dl varchar(128) DEFAULT '' NOT NULL, PRIMARY KEY (name) ) engine=Aria transactional=1 CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci comment='MySQL plugins';
110110

111111

112-
CREATE TABLE IF NOT EXISTS servers ( Server_name char(64) NOT NULL DEFAULT '', Host varchar(2048) NOT NULL DEFAULT '', Db char(64) NOT NULL DEFAULT '', Username char(128) NOT NULL DEFAULT '', Password char(64) NOT NULL DEFAULT '', Port INT(4) NOT NULL DEFAULT '0', Socket char(108) NOT NULL DEFAULT '', Wrapper char(64) NOT NULL DEFAULT '', Owner varchar(512) NOT NULL DEFAULT '', PRIMARY KEY (Server_name)) engine=Aria transactional=1 CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci comment='MySQL Foreign Servers table';
112+
CREATE TABLE IF NOT EXISTS servers ( Server_name char(64) NOT NULL DEFAULT '', Host varchar(2048) NOT NULL DEFAULT '', Db char(64) NOT NULL DEFAULT '', Username char(128) NOT NULL DEFAULT '', Password char(64) NOT NULL DEFAULT '', Port INT(4) NOT NULL DEFAULT '0', Socket char(108) NOT NULL DEFAULT '', Wrapper char(64) NOT NULL DEFAULT '', Owner varchar(512) NOT NULL DEFAULT '', PRIMARY KEY (Server_name), Options JSON NOT NULL DEFAULT '{}' CHECK(JSON_VALID(Options))) engine=Aria transactional=1 CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci comment='MySQL Foreign Servers table';
113113

114114

115115
CREATE TABLE IF NOT EXISTS tables_priv ( Host char(255) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, User char(128) binary DEFAULT '' NOT NULL, Table_name char(64) binary DEFAULT '' NOT NULL, Grantor varchar(384) DEFAULT '' NOT NULL, Timestamp timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, Table_priv set('Select','Insert','Update','Delete','Create','Drop','Grant','References','Index','Alter','Create View','Show view','Trigger','Delete versioning rows') COLLATE utf8mb3_general_ci DEFAULT '' NOT NULL, Column_priv set('Select','Insert','Update','References') COLLATE utf8mb3_general_ci DEFAULT '' NOT NULL, PRIMARY KEY (Host,Db,User,Table_name), KEY Grantor (Grantor) ) engine=Aria transactional=1 CHARACTER SET utf8mb3 COLLATE utf8mb3_bin comment='Table privileges';

scripts/mariadb_system_tables_fix.sql

+7
Original file line numberDiff line numberDiff line change
@@ -901,3 +901,10 @@ ALTER TABLE servers
901901
# MDEV-34716 Fix mysql.servers socket max length too short
902902
ALTER TABLE servers
903903
MODIFY Socket char(108) NOT NULL DEFAULT '';
904+
905+
# MDEV-34716 Allow arbitrary options in CREATE SERVER
906+
ALTER TABLE servers
907+
ADD Options JSON NOT NULL DEFAULT '{}' CHECK(JSON_VALID(Options));
908+
# Ensure the collation is utf8mb4_bin (default for JSON)
909+
ALTER TABLE servers
910+
MODIFY Options JSON NOT NULL DEFAULT '{}' CHECK(JSON_VALID(Options));

sql/create_options.h

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626

2727
enum { ENGINE_OPTION_MAX_LENGTH=32767 };
2828

29+
/*
30+
Key-value list. Used for engine-defined options in CREATE TABLE
31+
and OPTIONS in CREATE SERVER.
32+
*/
2933
class engine_option_value: public Sql_alloc
3034
{
3135
public:

sql/sql_lex.h

+2
Original file line numberDiff line numberDiff line change
@@ -317,11 +317,13 @@ typedef struct st_lex_server_options
317317
{
318318
long port;
319319
LEX_CSTRING server_name, host, db, username, password, scheme, socket, owner;
320+
engine_option_value *option_list;
320321
void reset(LEX_CSTRING name)
321322
{
322323
server_name= name;
323324
host= db= username= password= scheme= socket= owner= null_clex_str;
324325
port= -1;
326+
option_list= NULL;
325327
}
326328
} LEX_SERVER_OPTIONS;
327329

0 commit comments

Comments
 (0)