Skip to content

Commit 9ba56c0

Browse files
committed
Add a parameter spider_strict_group_by for supporting ONLY_FULL_GROUP_BY
1 parent bbb1140 commit 9ba56c0

File tree

12 files changed

+628
-26
lines changed

12 files changed

+628
-26
lines changed

storage/spider/ha_spider.cc

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14001,6 +14001,7 @@ void ha_spider::sync_from_clone_source_base(
1400114001
dbton_hdl = dbton_handler[dbton_id];
1400214002
dbton_hdl2 = spider->dbton_handler[dbton_id];
1400314003
dbton_hdl->first_link_idx = dbton_hdl2->first_link_idx;
14004+
dbton_hdl->strict_group_by = dbton_hdl2->strict_group_by;
1400414005
}
1400514006
DBUG_VOID_RETURN;
1400614007
}
@@ -14016,6 +14017,7 @@ void ha_spider::set_first_link_idx()
1401614017
dbton_id = share->use_dbton_ids[roop_count2];
1401714018
dbton_hdl = dbton_handler[dbton_id];
1401814019
dbton_hdl->first_link_idx = -1;
14020+
dbton_hdl->strict_group_by = FALSE;
1401914021
}
1402014022
for (
1402114023
roop_count = spider_conn_link_idx_next(share->link_statuses,
@@ -14034,6 +14036,10 @@ void ha_spider::set_first_link_idx()
1403414036
{
1403514037
dbton_hdl->first_link_idx = roop_count;
1403614038
}
14039+
if (share->strict_group_bys[all_link_idx])
14040+
{
14041+
dbton_hdl->strict_group_by = TRUE;
14042+
}
1403714043
}
1403814044
#if defined(HS_HAS_SQLCOM) && defined(HAVE_HANDLERSOCKET)
1403914045
dbton_id = share->hs_dbton_ids[all_link_idx];
@@ -14044,6 +14050,10 @@ void ha_spider::set_first_link_idx()
1404414050
{
1404514051
dbton_hdl->first_link_idx = roop_count;
1404614052
}
14053+
if (share->strict_group_bys[all_link_idx])
14054+
{
14055+
dbton_hdl->strict_group_by = TRUE;
14056+
}
1404714057
}
1404814058
#endif
1404914059
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP
2+
--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP
3+
--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP
4+
--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP
5+
--let $CHILD2_2_DROP_TABLES= $CHILD2_2_DROP_TABLES_BACKUP
6+
--let $CHILD2_2_CREATE_TABLES= $CHILD2_2_CREATE_TABLES_BACKUP
7+
--let $CHILD2_2_SELECT_TABLES= $CHILD2_2_SELECT_TABLES_BACKUP
8+
--connection child2_1
9+
set global sql_mode= @old_sql_mode;
10+
--connection master_1
11+
set session spider_sync_sql_mode= @old_spider_sync_sql_mode;
12+
--disable_warnings
13+
--disable_query_log
14+
--disable_result_log
15+
--source ../t/test_deinit.inc
16+
--enable_result_log
17+
--enable_query_log
18+
--enable_warnings
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
--disable_warnings
2+
--disable_query_log
3+
--disable_result_log
4+
--source ../t/test_init.inc
5+
if (!$HAVE_PARTITION)
6+
{
7+
--source strict_group_by_deinit.inc
8+
--enable_result_log
9+
--enable_query_log
10+
--enable_warnings
11+
skip Test requires partitioning;
12+
}
13+
--enable_result_log
14+
--enable_query_log
15+
--enable_warnings
16+
--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1
17+
let $MASTER_1_COMMENT_2_1=
18+
COMMENT='table "tbl_a"'
19+
PARTITION BY KEY(pkey) (
20+
PARTITION pt1 COMMENT='srv "s_2_1"',
21+
PARTITION pt2 COMMENT='srv "s_2_2"'
22+
);
23+
--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES
24+
let $CHILD2_1_DROP_TABLES=
25+
DROP TABLE IF EXISTS tbl_a;
26+
--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES
27+
let $CHILD2_1_CREATE_TABLES=
28+
CREATE TABLE tbl_a (
29+
pkey int NOT NULL,
30+
skey int NOT NULL,
31+
PRIMARY KEY (pkey),
32+
KEY idx1 (skey)
33+
) $CHILD2_1_ENGINE $CHILD2_1_CHARSET;
34+
--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES
35+
let $CHILD2_1_SELECT_TABLES=
36+
SELECT pkey, skey FROM tbl_a ORDER BY pkey;
37+
let $CHILD2_1_SELECT_ARGUMENT1=
38+
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %';
39+
--let $CHILD2_2_DROP_TABLES_BACKUP= $CHILD2_2_DROP_TABLES
40+
let $CHILD2_2_DROP_TABLES=
41+
DROP TABLE IF EXISTS tbl_a;
42+
--let $CHILD2_2_CREATE_TABLES_BACKUP= $CHILD2_2_CREATE_TABLES
43+
let $CHILD2_2_CREATE_TABLES=
44+
CREATE TABLE tbl_a (
45+
pkey int NOT NULL,
46+
skey int NOT NULL,
47+
PRIMARY KEY (pkey),
48+
KEY idx1 (skey)
49+
) $CHILD2_2_ENGINE $CHILD2_2_CHARSET;
50+
--let $CHILD2_2_SELECT_TABLES_BACKUP= $CHILD2_2_SELECT_TABLES
51+
let $CHILD2_2_SELECT_TABLES=
52+
SELECT pkey, skey FROM tbl_a ORDER BY pkey;
53+
let $CHILD2_2_SELECT_ARGUMENT1=
54+
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %';
55+
--connection master_1
56+
set @old_spider_sync_sql_mode= @@spider_sync_sql_mode;
57+
set session spider_sync_sql_mode= FALSE;
58+
--connection child2_1
59+
set @old_sql_mode= @@sql_mode;
60+
set global sql_mode= 'ONLY_FULL_GROUP_BY';
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
for master_1
2+
for child2
3+
child2_1
4+
child2_2
5+
child2_3
6+
for child3
7+
connection master_1;
8+
set @old_spider_sync_sql_mode= @@spider_sync_sql_mode;
9+
set session spider_sync_sql_mode= FALSE;
10+
connection child2_1;
11+
set @old_sql_mode= @@sql_mode;
12+
set global sql_mode= 'ONLY_FULL_GROUP_BY';
13+
14+
this test is for MDEV-18988
15+
16+
drop and create databases
17+
connection master_1;
18+
CREATE DATABASE auto_test_local;
19+
USE auto_test_local;
20+
connection child2_1;
21+
SET @old_log_output = @@global.log_output;
22+
SET GLOBAL log_output = 'TABLE,FILE';
23+
CREATE DATABASE auto_test_remote;
24+
USE auto_test_remote;
25+
connection child2_2;
26+
SET @old_log_output = @@global.log_output;
27+
SET GLOBAL log_output = 'TABLE,FILE';
28+
CREATE DATABASE auto_test_remote2;
29+
USE auto_test_remote2;
30+
31+
create table and insert
32+
connection child2_1;
33+
CHILD2_1_CREATE_TABLES
34+
TRUNCATE TABLE mysql.general_log;
35+
connection child2_2;
36+
CHILD2_2_CREATE_TABLES
37+
TRUNCATE TABLE mysql.general_log;
38+
connection master_1;
39+
CREATE TABLE tbl_a (
40+
pkey int NOT NULL,
41+
skey int NOT NULL,
42+
PRIMARY KEY (pkey),
43+
KEY idx1 (skey)
44+
) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1
45+
INSERT INTO tbl_a (pkey,skey) VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);
46+
INSERT INTO tbl_a (pkey,skey) VALUES (10,10),(11,11),(12,12),(13,13),(14,14),(15,15),(16,16),(17,17),(18,18),(19,19);
47+
INSERT INTO tbl_a (pkey,skey) VALUES (20,5),(21,6),(22,7),(23,8),(24,9),(25,10),(26,11),(27,12),(28,13),(29,14);
48+
49+
select test 1
50+
connection child2_1;
51+
TRUNCATE TABLE mysql.general_log;
52+
connection child2_2;
53+
TRUNCATE TABLE mysql.general_log;
54+
connection master_1;
55+
FLUSH TABLES;
56+
SELECT count(pkey) cnt, skey FROM tbl_a;
57+
cnt skey
58+
30 1
59+
connection child2_1;
60+
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %';
61+
argument
62+
select count(`pkey`),min(`pkey`),min(`skey`) from `auto_test_remote`.`tbl_a`
63+
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'
64+
SELECT pkey, skey FROM tbl_a ORDER BY pkey;
65+
pkey skey
66+
1 1
67+
3 3
68+
5 5
69+
7 7
70+
9 9
71+
11 11
72+
13 13
73+
15 15
74+
17 17
75+
19 19
76+
21 6
77+
23 8
78+
25 10
79+
27 12
80+
29 14
81+
connection child2_2;
82+
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %';
83+
argument
84+
select count(`pkey`),min(`pkey`),min(`skey`) from `auto_test_remote2`.`tbl_a`
85+
SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'
86+
SELECT pkey, skey FROM tbl_a ORDER BY pkey;
87+
pkey skey
88+
0 0
89+
2 2
90+
4 4
91+
6 6
92+
8 8
93+
10 10
94+
12 12
95+
14 14
96+
16 16
97+
18 18
98+
20 5
99+
22 7
100+
24 9
101+
26 11
102+
28 13
103+
104+
deinit
105+
connection master_1;
106+
DROP DATABASE IF EXISTS auto_test_local;
107+
connection child2_1;
108+
DROP DATABASE IF EXISTS auto_test_remote;
109+
SET GLOBAL log_output = @old_log_output;
110+
connection child2_2;
111+
DROP DATABASE IF EXISTS auto_test_remote2;
112+
SET GLOBAL log_output = @old_log_output;
113+
connection child2_1;
114+
set global sql_mode= @old_sql_mode;
115+
connection master_1;
116+
set session spider_sync_sql_mode= @old_spider_sync_sql_mode;
117+
for master_1
118+
for child2
119+
child2_1
120+
child2_2
121+
child2_3
122+
for child3
123+
124+
end of test
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
!include include/default_mysqld.cnf
2+
!include ../my_1_1.cnf
3+
!include ../my_2_1.cnf
4+
!include ../my_2_2.cnf
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
--source ../include/strict_group_by_init.inc
2+
--echo
3+
--echo this test is for MDEV-18988
4+
--echo
5+
--echo drop and create databases
6+
--connection master_1
7+
--disable_warnings
8+
CREATE DATABASE auto_test_local;
9+
USE auto_test_local;
10+
11+
--connection child2_1
12+
SET @old_log_output = @@global.log_output;
13+
SET GLOBAL log_output = 'TABLE,FILE';
14+
CREATE DATABASE auto_test_remote;
15+
USE auto_test_remote;
16+
17+
--connection child2_2
18+
SET @old_log_output = @@global.log_output;
19+
SET GLOBAL log_output = 'TABLE,FILE';
20+
CREATE DATABASE auto_test_remote2;
21+
USE auto_test_remote2;
22+
--enable_warnings
23+
24+
--echo
25+
--echo create table and insert
26+
27+
--connection child2_1
28+
--disable_query_log
29+
echo CHILD2_1_CREATE_TABLES;
30+
eval $CHILD2_1_CREATE_TABLES;
31+
--enable_query_log
32+
TRUNCATE TABLE mysql.general_log;
33+
34+
--connection child2_2
35+
--disable_query_log
36+
echo CHILD2_2_CREATE_TABLES;
37+
eval $CHILD2_2_CREATE_TABLES;
38+
--enable_query_log
39+
TRUNCATE TABLE mysql.general_log;
40+
41+
--connection master_1
42+
--disable_query_log
43+
echo CREATE TABLE tbl_a (
44+
pkey int NOT NULL,
45+
skey int NOT NULL,
46+
PRIMARY KEY (pkey),
47+
KEY idx1 (skey)
48+
) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1;
49+
eval CREATE TABLE tbl_a (
50+
pkey int NOT NULL,
51+
skey int NOT NULL,
52+
PRIMARY KEY (pkey),
53+
KEY idx1 (skey)
54+
) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1;
55+
--enable_query_log
56+
INSERT INTO tbl_a (pkey,skey) VALUES (0,0),(1,1),(2,2),(3,3),(4,4),(5,5),(6,6),(7,7),(8,8),(9,9);
57+
INSERT INTO tbl_a (pkey,skey) VALUES (10,10),(11,11),(12,12),(13,13),(14,14),(15,15),(16,16),(17,17),(18,18),(19,19);
58+
INSERT INTO tbl_a (pkey,skey) VALUES (20,5),(21,6),(22,7),(23,8),(24,9),(25,10),(26,11),(27,12),(28,13),(29,14);
59+
60+
--echo
61+
--echo select test 1
62+
63+
--connection child2_1
64+
TRUNCATE TABLE mysql.general_log;
65+
66+
--connection child2_2
67+
TRUNCATE TABLE mysql.general_log;
68+
69+
--connection master_1
70+
FLUSH TABLES;
71+
SELECT count(pkey) cnt, skey FROM tbl_a;
72+
73+
--connection child2_1
74+
eval $CHILD2_1_SELECT_ARGUMENT1;
75+
eval $CHILD2_1_SELECT_TABLES;
76+
77+
--connection child2_2
78+
eval $CHILD2_2_SELECT_ARGUMENT1;
79+
eval $CHILD2_2_SELECT_TABLES;
80+
81+
--echo
82+
--echo deinit
83+
--disable_warnings
84+
--connection master_1
85+
DROP DATABASE IF EXISTS auto_test_local;
86+
87+
--connection child2_1
88+
DROP DATABASE IF EXISTS auto_test_remote;
89+
SET GLOBAL log_output = @old_log_output;
90+
91+
--connection child2_2
92+
DROP DATABASE IF EXISTS auto_test_remote2;
93+
SET GLOBAL log_output = @old_log_output;
94+
95+
--enable_warnings
96+
--source ../include/strict_group_by_deinit.inc
97+
--echo
98+
--echo end of test

storage/spider/spd_db_include.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,8 @@ typedef st_spider_result SPIDER_RESULT;
218218
#define SPIDER_SQL_CONNECTION_LEN (sizeof(SPIDER_SQL_CONNECTION_STR) - 1)
219219
#define SPIDER_SQL_LCL_NAME_QUOTE_STR "`"
220220
#define SPIDER_SQL_LCL_NAME_QUOTE_LEN (sizeof(SPIDER_SQL_LCL_NAME_QUOTE_STR) - 1)
221+
#define SPIDER_SQL_MIN_STR "min"
222+
#define SPIDER_SQL_MIN_LEN (sizeof(SPIDER_SQL_MIN_STR) - 1)
221223

222224
#define SPIDER_SQL_LOP_CHK_PRM_PRF_STR "spider_lc_"
223225
#define SPIDER_SQL_LOP_CHK_PRM_PRF_LEN (sizeof(SPIDER_SQL_LOP_CHK_PRM_PRF_STR) - 1)
@@ -1352,6 +1354,7 @@ class spider_db_handler
13521354
#ifdef SPIDER_HAS_GROUP_BY_HANDLER
13531355
SPIDER_LINK_IDX_CHAIN *link_idx_chain;
13541356
#endif
1357+
bool strict_group_by;
13551358
spider_db_handler(ha_spider *spider, spider_db_share *db_share) :
13561359
dbton_id(db_share->dbton_id), spider(spider), db_share(db_share),
13571360
first_link_idx(-1) {}

0 commit comments

Comments
 (0)