Skip to content

Commit 1261570

Browse files
MDEV-28856 Add remaining Spider table options
MDEV-27106 added REMOTE_TABLE, REMOTE_DATABASE, REMOTE_SERVER spider table options. In this commit, we add all remaining options for table params that are not marked to be deprecated. All these options are parsed as strings from sql statements and have string values at the sql level, so that we can determine whether it is specified by checking its nullness. The string values are further parsed by Spider into their actual types in the SPIDER_SHARE, including string list, bounded nonnegative int, bounded nonnegative int list, nonnegative longlong, boolean, and key hints. Except for string lists, all other types are validated during this parsing process. Most of the options are backward compatible, i.e. they accept any values that is accepted by there corresponding param parser. The only exception is the index hint IDX which corresponds to the idxNNN param name. For example, 'idx000 "f PRIMARY", idx001 "u k1"' translates to IDX="f PRIMARY u k1". We include a test with all options specified, and tests involving spider table options of all actual types. Any table options, if present, will cause comments to be ignored with a warning. The warning can be disabled by setting a new spider global/session system variable spider_suppress_comment_ignored_warning to 1. Another global/session variable introduced is spider_ignore_comments, which if set to 1, will cause COMMENT and CONNECTION strings to be ignored unconditionally, whether or not table options are specified.
1 parent c507678 commit 1261570

File tree

13 files changed

+1691
-483
lines changed

13 files changed

+1691
-483
lines changed

sql/sql_yacc.yy

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize);
13331333
ident
13341334
label_ident
13351335
sp_decl_ident
1336+
ident_options
13361337
ident_or_empty
13371338
ident_table_alias
13381339
ident_sysvar_name
@@ -1363,6 +1364,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, size_t *yystacksize);
13631364
keyword_cast_type
13641365
keyword_ident
13651366
keyword_label
1367+
keyword_options
13661368
keyword_set_special_case
13671369
keyword_set_usual_case
13681370
keyword_sp_block_section
@@ -5646,32 +5648,49 @@ create_table_option:
56465648
;
56475649

56485650
engine_defined_option:
5649-
IDENT_sys equal TEXT_STRING_sys
5651+
ident_options equal TEXT_STRING_sys
56505652
{
56515653
if (unlikely($3.length > ENGINE_OPTION_MAX_LENGTH))
56525654
my_yyabort_error((ER_VALUE_TOO_LONG, MYF(0), $1.str));
56535655
$$= new (thd->mem_root) engine_option_value($1, $3, true);
56545656
MYSQL_YYABORT_UNLESS($$);
56555657
}
5656-
| IDENT_sys equal ident
5658+
| ident_options equal ident
56575659
{
56585660
if (unlikely($3.length > ENGINE_OPTION_MAX_LENGTH))
56595661
my_yyabort_error((ER_VALUE_TOO_LONG, MYF(0), $1.str));
56605662
$$= new (thd->mem_root) engine_option_value($1, $3, false);
56615663
MYSQL_YYABORT_UNLESS($$);
56625664
}
5663-
| IDENT_sys equal real_ulonglong_num
5665+
| ident_options equal real_ulonglong_num
56645666
{
56655667
$$= new (thd->mem_root) engine_option_value($1, $3, thd->mem_root);
56665668
MYSQL_YYABORT_UNLESS($$);
56675669
}
5668-
| IDENT_sys equal DEFAULT
5670+
| ident_options equal DEFAULT
56695671
{
56705672
$$= new (thd->mem_root) engine_option_value($1);
56715673
MYSQL_YYABORT_UNLESS($$);
56725674
}
56735675
;
56745676

5677+
ident_options:
5678+
IDENT_sys
5679+
| keyword_options
5680+
{
5681+
if (unlikely($$.copy_keyword(thd, &$1)))
5682+
MYSQL_YYABORT;
5683+
}
5684+
;
5685+
5686+
/*
5687+
These keywords are fine for option names.
5688+
*/
5689+
keyword_options:
5690+
READ_ONLY_SYM
5691+
| WRAPPER_SYM
5692+
;
5693+
56755694
opt_versioning_option:
56765695
/* empty */
56775696
| versioning_option

storage/spider/mysql-test/spider/bugfix/r/mdev_31524.result

Lines changed: 0 additions & 50 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#
2+
# MDEV-32486 Assertion `!trx->alloc_line_no[id] || trx->alloc_line_no[id] == line_no' failed in spider_alloc_mem_calc
3+
#
4+
for master_1
5+
for child2
6+
for child3
7+
CREATE TABLE t (c INT) ENGINE=Spider REMOTE_PORT="1";
8+
DROP TABLE t;
9+
CREATE TABLE t (c INT) ENGINE=Spider COMMENT="WRAPPER 'mysql', SERVER 's',MONITORING_KIND '1'";
10+
ERROR HY000: The foreign server name you are trying to reference does not exist. Data source error: s
11+
CREATE TABLE t (c INT) ENGINE=Spider COMMENT="WRAPPER 'mysql',SRV 's',MONITORING_KIND '2'";
12+
ERROR HY000: The foreign server name you are trying to reference does not exist. Data source error: s
13+
CREATE TABLE t (c INT) ENGINE=Spider REMOTE_PORT="1";
14+
drop table t;
15+
for master_1
16+
for child2
17+
for child3
18+
#
19+
# end of test mdev_32486
20+
#
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
2+
Testing spider sysvar and table params / options, including default values and overriding mechanisms
3+
4+
for master_1
5+
for child2
6+
for child3
7+
SET @old_spider_read_only_mode = @@session.spider_read_only_mode;
8+
CREATE SERVER srv FOREIGN DATA WRAPPER MYSQL OPTIONS (SOCKET "$MASTER_1_MYSOCK", DATABASE 'test',user 'root');
9+
# Cases where table params/options are not set
10+
set session spider_read_only_mode = default;
11+
create table t2 (c int);
12+
create table t1 (c int) ENGINE=Spider COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"';
13+
/* 1 */ insert into t1 values (42);
14+
drop table t1, t2;
15+
set session spider_read_only_mode = 1;
16+
create table t2 (c int);
17+
create table t1 (c int) ENGINE=Spider COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"';
18+
/* 2 */ insert into t1 values (42);
19+
ERROR HY000: Table 'test.t1' is read only
20+
drop table t1, t2;
21+
set session spider_read_only_mode = -1;
22+
Warnings:
23+
Warning 138 The option value -1 (fallback to default) is deprecated and will be removed in a future release
24+
create table t2 (c int);
25+
create table t1 (c int) ENGINE=Spider COMMENT='WRAPPER "mysql", srv "srv",TABLE "t2"';
26+
/* 3 */ insert into t1 values (42);
27+
drop table t1, t2;
28+
# Cases where table params are set
29+
SET session spider_read_only_mode = default;
30+
create table t2 (c int);
31+
create table t1 (c int) ENGINE=Spider COMMENT='read_only_mode "1", WRAPPER "mysql", srv "srv",TABLE "t2"';
32+
/* 4 */ insert into t1 values (42);
33+
ERROR HY000: Table 'test.t1' is read only
34+
drop table t1, t2;
35+
set session spider_read_only_mode = 1;
36+
create table t2 (c int);
37+
create table t1 (c int) ENGINE=Spider COMMENT='read_only_mode "0", WRAPPER "mysql", srv "srv",TABLE "t2"';
38+
/* 5 */ insert into t1 values (42);
39+
drop table t1, t2;
40+
SET session spider_read_only_mode = -1;
41+
Warnings:
42+
Warning 138 The option value -1 (fallback to default) is deprecated and will be removed in a future release
43+
create table t2 (c int);
44+
create table t1 (c int) ENGINE=Spider COMMENT='read_only_mode "1", WRAPPER "mysql", srv "",TABLE "t2"';
45+
/* 6 */ insert into t1 values (42);
46+
ERROR HY000: Table 'test.t1' is read only
47+
drop table t1, t2;
48+
# Cases where table options are set
49+
SET session spider_read_only_mode = default;
50+
create table t2 (c int);
51+
create table t1 (c int) ENGINE=Spider REMOTE_SERVER=srv REMOTE_TABLE=t2 READ_ONLY=1 WRAPPER=mysql;
52+
/* 7 */ insert into t1 values (42);
53+
ERROR HY000: Table 'test.t1' is read only
54+
drop table t1, t2;
55+
set session spider_read_only_mode = 1;
56+
create table t2 (c int);
57+
create table t1 (c int) ENGINE=Spider READ_ONLY=0 REMOTE_SERVER=srv REMOTE_TABLE=t2 WRAPPER=mysql;
58+
/* 8 */ insert into t1 values (42);
59+
drop table t1, t2;
60+
SET session spider_read_only_mode = -1;
61+
Warnings:
62+
Warning 138 The option value -1 (fallback to default) is deprecated and will be removed in a future release
63+
create table t2 (c int);
64+
create table t1 (c int) ENGINE=Spider READ_ONLY=1 REMOTE_SERVER=srv REMOTE_TABLE=t2 WRAPPER=mysql;
65+
/* 9 */ insert into t1 values (42);
66+
ERROR HY000: Table 'test.t1' is read only
67+
drop table t1, t2;
68+
SET session spider_read_only_mode = 0;
69+
create table t2 (c int);
70+
create table t1 (c int) ENGINE=Spider READ_ONLY=default REMOTE_SERVER=srv REMOTE_TABLE=t2 WRAPPER=mysql;
71+
/* 10 */ insert into t1 values (42);
72+
drop table t1, t2;
73+
SET session spider_read_only_mode = 1;
74+
create table t2 (c int);
75+
create table t1 (c int) ENGINE=Spider READ_ONLY=default REMOTE_SERVER=srv REMOTE_TABLE=t2 WRAPPER=mysql;
76+
/* 11 */ insert into t1 values (42);
77+
ERROR HY000: Table 'test.t1' is read only
78+
drop table t1, t2;
79+
SET session spider_read_only_mode = -1;
80+
Warnings:
81+
Warning 138 The option value -1 (fallback to default) is deprecated and will be removed in a future release
82+
create table t2 (c int);
83+
create table t1 (c int) ENGINE=Spider READ_ONLY=default REMOTE_SERVER=srv REMOTE_TABLE=t2 WRAPPER=mysql;
84+
/* 12 */ insert into t1 values (42);
85+
drop table t1, t2;
86+
drop server srv;
87+
SET session spider_read_only_mode = @old_spider_read_only_mode;
88+
for master_1
89+
for child2
90+
for child3
91+
#
92+
# End of test sysvar_params
93+
#

storage/spider/mysql-test/spider/bugfix/t/mdev_31524.test

Lines changed: 0 additions & 73 deletions
This file was deleted.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
--echo #
2+
--echo # MDEV-32486 Assertion `!trx->alloc_line_no[id] || trx->alloc_line_no[id] == line_no' failed in spider_alloc_mem_calc
3+
--echo #
4+
--disable_query_log
5+
--disable_result_log
6+
--source ../../t/test_init.inc
7+
--enable_result_log
8+
--enable_query_log
9+
CREATE TABLE t (c INT) ENGINE=Spider REMOTE_PORT="1";
10+
DROP TABLE t;
11+
--error ER_FOREIGN_SERVER_DOESNT_EXIST
12+
CREATE TABLE t (c INT) ENGINE=Spider COMMENT="WRAPPER 'mysql', SERVER 's',MONITORING_KIND '1'";
13+
14+
--error ER_FOREIGN_SERVER_DOESNT_EXIST
15+
CREATE TABLE t (c INT) ENGINE=Spider COMMENT="WRAPPER 'mysql',SRV 's',MONITORING_KIND '2'";
16+
CREATE TABLE t (c INT) ENGINE=Spider REMOTE_PORT="1";
17+
drop table t;
18+
19+
--disable_query_log
20+
--disable_result_log
21+
--source ../../t/test_deinit.inc
22+
--enable_result_log
23+
--enable_query_log
24+
--echo #
25+
--echo # end of test mdev_32486
26+
--echo #

0 commit comments

Comments
 (0)