diff options
author | Kentoku <kentokushiba@gmail.com> | 2019-04-23 08:43:19 +0900 |
---|---|---|
committer | Kentoku <kentokushiba@gmail.com> | 2019-04-23 09:57:55 +0900 |
commit | 49a3c89e4de552192aefd0fc3e57bdbaca86eb85 (patch) | |
tree | 60dfdd32ea9e661ce66d7fcb33e4d984eed15479 | |
parent | a765b19e5ca31a3d866cdbc8bef3a6f4e5e44688 (diff) | |
download | mariadb-git-bb-10.4-MDEV-18988.tar.gz |
MDEV-18988 Wrong result when query with group by x order by y limit nbb-10.4-MDEV-18988
17 files changed, 836 insertions, 1 deletions
diff --git a/storage/spider/mysql-test/spider/bugfix/include/group_by_order_by_limit_deinit.inc b/storage/spider/mysql-test/spider/bugfix/include/group_by_order_by_limit_deinit.inc new file mode 100644 index 00000000000..9d255152dd8 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/group_by_order_by_limit_deinit.inc @@ -0,0 +1,14 @@ +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--let $CHILD2_2_DROP_TABLES= $CHILD2_2_DROP_TABLES_BACKUP +--let $CHILD2_2_CREATE_TABLES= $CHILD2_2_CREATE_TABLES_BACKUP +--let $CHILD2_2_SELECT_TABLES= $CHILD2_2_SELECT_TABLES_BACKUP +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/bugfix/include/group_by_order_by_limit_init.inc b/storage/spider/mysql-test/spider/bugfix/include/group_by_order_by_limit_init.inc new file mode 100644 index 00000000000..ac60580f463 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/include/group_by_order_by_limit_init.inc @@ -0,0 +1,54 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../t/test_init.inc +if (!$HAVE_PARTITION) +{ + --source group_by_order_by_limit_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + skip Test requires partitioning; +} +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a"' + PARTITION BY KEY(pkey) ( + PARTITION pt1 COMMENT='srv "s_2_1"', + PARTITION pt2 COMMENT='srv "s_2_2"' + ); +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE tbl_a ( + pkey int NOT NULL, + skey int NOT NULL, + PRIMARY KEY (pkey), + KEY idx1 (skey) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT pkey, skey FROM tbl_a ORDER BY pkey; +let $CHILD2_1_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; +--let $CHILD2_2_DROP_TABLES_BACKUP= $CHILD2_2_DROP_TABLES +let $CHILD2_2_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_2_CREATE_TABLES_BACKUP= $CHILD2_2_CREATE_TABLES +let $CHILD2_2_CREATE_TABLES= + CREATE TABLE tbl_a ( + pkey int NOT NULL, + skey int NOT NULL, + PRIMARY KEY (pkey), + KEY idx1 (skey) + ) $CHILD2_2_ENGINE $CHILD2_2_CHARSET; +--let $CHILD2_2_SELECT_TABLES_BACKUP= $CHILD2_2_SELECT_TABLES +let $CHILD2_2_SELECT_TABLES= + SELECT pkey, skey FROM tbl_a ORDER BY pkey; +let $CHILD2_2_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; diff --git a/storage/spider/mysql-test/spider/bugfix/r/group_by_order_by_limit.result b/storage/spider/mysql-test/spider/bugfix/r/group_by_order_by_limit.result new file mode 100644 index 00000000000..8a2bcb73537 --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/r/group_by_order_by_limit.result @@ -0,0 +1,117 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +this test is for MDEV-16520 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +connection child2_2; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection child2_2; +CHILD2_2_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +skey int NOT NULL, +PRIMARY KEY (pkey), +KEY idx1 (skey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +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); +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); +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); + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection child2_2; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT skey, count(*) cnt FROM tbl_a GROUP BY skey ORDER BY cnt DESC, skey DESC LIMIT 5; +skey cnt +14 2 +13 2 +12 2 +11 2 +10 2 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; +argument +select count(0),`skey` from `auto_test_remote`.`tbl_a` group by `skey` order by `skey` +SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %' +SELECT pkey, skey FROM tbl_a ORDER BY pkey; +pkey skey +1 1 +3 3 +5 5 +7 7 +9 9 +11 11 +13 13 +15 15 +17 17 +19 19 +21 6 +23 8 +25 10 +27 12 +29 14 +connection child2_2; +SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; +argument +select count(0),`skey` from `auto_test_remote2`.`tbl_a` group by `skey` order by `skey` +SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %' +SELECT pkey, skey FROM tbl_a ORDER BY pkey; +pkey skey +0 0 +2 2 +4 4 +6 6 +8 8 +10 10 +12 12 +14 14 +16 16 +18 18 +20 5 +22 7 +24 9 +26 11 +28 13 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection child2_2; +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/bugfix/t/group_by_order_by_limit.cnf b/storage/spider/mysql-test/spider/bugfix/t/group_by_order_by_limit.cnf new file mode 100644 index 00000000000..e0ffb99c38e --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/group_by_order_by_limit.cnf @@ -0,0 +1,4 @@ +!include include/default_mysqld.cnf +!include ../my_1_1.cnf +!include ../my_2_1.cnf +!include ../my_2_2.cnf diff --git a/storage/spider/mysql-test/spider/bugfix/t/group_by_order_by_limit.test b/storage/spider/mysql-test/spider/bugfix/t/group_by_order_by_limit.test new file mode 100644 index 00000000000..f1de6d5d25f --- /dev/null +++ b/storage/spider/mysql-test/spider/bugfix/t/group_by_order_by_limit.test @@ -0,0 +1,97 @@ +--source ../include/group_by_order_by_limit_init.inc +--echo +--echo this test is for MDEV-16520 +--echo +--echo drop and create databases +--connection master_1 +--disable_warnings +CREATE DATABASE auto_test_local; +USE auto_test_local; + +--connection child2_1 +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +--connection child2_2 +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; +--enable_warnings + +--echo +--echo create table and insert + +--connection child2_1 +--disable_query_log +echo CHILD2_1_CREATE_TABLES; +eval $CHILD2_1_CREATE_TABLES; +--enable_query_log +TRUNCATE TABLE mysql.general_log; + +--connection child2_2 +--disable_query_log +echo CHILD2_2_CREATE_TABLES; +eval $CHILD2_2_CREATE_TABLES; +--enable_query_log +TRUNCATE TABLE mysql.general_log; + +--connection master_1 +--disable_query_log +echo CREATE TABLE tbl_a ( + pkey int NOT NULL, + skey int NOT NULL, + PRIMARY KEY (pkey), + KEY idx1 (skey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE tbl_a ( + pkey int NOT NULL, + skey int NOT NULL, + PRIMARY KEY (pkey), + KEY idx1 (skey) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +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); +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); +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); + +--echo +--echo select test 1 + +--connection child2_1 +TRUNCATE TABLE mysql.general_log; + +--connection child2_2 +TRUNCATE TABLE mysql.general_log; + +--connection master_1 +SELECT skey, count(*) cnt FROM tbl_a GROUP BY skey ORDER BY cnt DESC, skey DESC LIMIT 5; + +--connection child2_1 +eval $CHILD2_1_SELECT_ARGUMENT1; +eval $CHILD2_1_SELECT_TABLES; + +--connection child2_2 +eval $CHILD2_2_SELECT_ARGUMENT1; +eval $CHILD2_2_SELECT_TABLES; + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; + +--connection child2_1 +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; + +--connection child2_2 +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; + +--enable_warnings +--source ../include/group_by_order_by_limit_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/mysql-test/spider/regression/e112122/include/group_by_order_by_limit_ok_deinit.inc b/storage/spider/mysql-test/spider/regression/e112122/include/group_by_order_by_limit_ok_deinit.inc new file mode 100644 index 00000000000..2248eef3650 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/include/group_by_order_by_limit_ok_deinit.inc @@ -0,0 +1,14 @@ +--let $MASTER_1_COMMENT_2_1= $MASTER_1_COMMENT_2_1_BACKUP +--let $CHILD2_1_DROP_TABLES= $CHILD2_1_DROP_TABLES_BACKUP +--let $CHILD2_1_CREATE_TABLES= $CHILD2_1_CREATE_TABLES_BACKUP +--let $CHILD2_1_SELECT_TABLES= $CHILD2_1_SELECT_TABLES_BACKUP +--let $CHILD2_2_DROP_TABLES= $CHILD2_2_DROP_TABLES_BACKUP +--let $CHILD2_2_CREATE_TABLES= $CHILD2_2_CREATE_TABLES_BACKUP +--let $CHILD2_2_SELECT_TABLES= $CHILD2_2_SELECT_TABLES_BACKUP +--disable_warnings +--disable_query_log +--disable_result_log +--source ../../t/test_deinit.inc +--enable_result_log +--enable_query_log +--enable_warnings diff --git a/storage/spider/mysql-test/spider/regression/e112122/include/group_by_order_by_limit_ok_init.inc b/storage/spider/mysql-test/spider/regression/e112122/include/group_by_order_by_limit_ok_init.inc new file mode 100644 index 00000000000..a6945218fab --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/include/group_by_order_by_limit_ok_init.inc @@ -0,0 +1,54 @@ +--disable_warnings +--disable_query_log +--disable_result_log +--source ../../t/test_init.inc +if (!$HAVE_PARTITION) +{ + --source group_by_order_by_limit_ok_deinit.inc + --enable_result_log + --enable_query_log + --enable_warnings + skip Test requires partitioning; +} +--enable_result_log +--enable_query_log +--enable_warnings +--let $MASTER_1_COMMENT_2_1_BACKUP= $MASTER_1_COMMENT_2_1 +let $MASTER_1_COMMENT_2_1= + COMMENT='table "tbl_a"' + PARTITION BY KEY(skey) ( + PARTITION pt1 COMMENT='srv "s_2_1"', + PARTITION pt2 COMMENT='srv "s_2_2"' + ); +--let $CHILD2_1_DROP_TABLES_BACKUP= $CHILD2_1_DROP_TABLES +let $CHILD2_1_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_1_CREATE_TABLES_BACKUP= $CHILD2_1_CREATE_TABLES +let $CHILD2_1_CREATE_TABLES= + CREATE TABLE tbl_a ( + pkey int NOT NULL, + skey int NOT NULL, + KEY idx1 (pkey), + KEY idx2 (skey) + ) $CHILD2_1_ENGINE $CHILD2_1_CHARSET; +--let $CHILD2_1_SELECT_TABLES_BACKUP= $CHILD2_1_SELECT_TABLES +let $CHILD2_1_SELECT_TABLES= + SELECT pkey, skey FROM tbl_a ORDER BY pkey; +let $CHILD2_1_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; +--let $CHILD2_2_DROP_TABLES_BACKUP= $CHILD2_2_DROP_TABLES +let $CHILD2_2_DROP_TABLES= + DROP TABLE IF EXISTS tbl_a; +--let $CHILD2_2_CREATE_TABLES_BACKUP= $CHILD2_2_CREATE_TABLES +let $CHILD2_2_CREATE_TABLES= + CREATE TABLE tbl_a ( + pkey int NOT NULL, + skey int NOT NULL, + KEY idx1 (pkey), + KEY idx2 (skey) + ) $CHILD2_2_ENGINE $CHILD2_2_CHARSET; +--let $CHILD2_2_SELECT_TABLES_BACKUP= $CHILD2_2_SELECT_TABLES +let $CHILD2_2_SELECT_TABLES= + SELECT pkey, skey FROM tbl_a ORDER BY pkey; +let $CHILD2_2_SELECT_ARGUMENT1= + SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; diff --git a/storage/spider/mysql-test/spider/regression/e112122/my.cnf b/storage/spider/mysql-test/spider/regression/e112122/my.cnf new file mode 100644 index 00000000000..6610e4cfd98 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/my.cnf @@ -0,0 +1,4 @@ +!include include/default_mysqld.cnf +!include my_1_1.cnf +!include my_2_1.cnf +!include my_2_2.cnf diff --git a/storage/spider/mysql-test/spider/regression/e112122/my_1_1.cnf b/storage/spider/mysql-test/spider/regression/e112122/my_1_1.cnf new file mode 100644 index 00000000000..5f17295d895 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/my_1_1.cnf @@ -0,0 +1,44 @@ +[mysqld.1.1] +log-bin= master-bin +loose_handlersocket_port= 20000 +loose_handlersocket_port_wr= 20001 +loose_handlersocket_threads= 2 +loose_handlersocket_threads_wr= 1 +loose_handlersocket_support_merge_table= 0 +loose_handlersocket_direct_update_mode= 2 +loose_handlersocket_unlimited_boundary= 65536 +loose_handlersocket_bulk_insert= 0 +loose_handlersocket_bulk_insert_timeout= 0 +loose_handlersocket_general_log= 1 +loose_handlersocket_timeout= 30 +loose_handlersocket_close_table_interval=2 +open_files_limit= 4096 +loose_partition= 1 + +[ENV] +USE_GEOMETRY_TEST= 1 +USE_FULLTEXT_TEST= 1 +USE_HA_TEST= 1 +USE_GENERAL_LOG= 1 +USE_REPLICATION= 1 +MASTER_1_MYPORT= @mysqld.1.1.port +MASTER_1_HSRPORT= 20000 +MASTER_1_HSWPORT= 20001 +MASTER_1_MYSOCK= @mysqld.1.1.socket +MASTER_1_ENGINE_TYPE= Spider +#MASTER_1_ENGINE_TYPE= MyISAM +MASTER_1_ENGINE= ENGINE=Spider +MASTER_1_CHARSET= DEFAULT CHARSET=utf8 +MASTER_1_ENGINE2= ENGINE=MyISAM +MASTER_1_CHARSET2= DEFAULT CHARSET=utf8 +MASTER_1_CHARSET3= DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci + +STR_SEMICOLON= ; + +#The followings are set in include/init_xxx.inc files +# MASTER_1_COMMENT_2_1 +# MASTER_1_COMMENT2_2_1 +# MASTER_1_COMMENT3_2_1 +# MASTER_1_COMMENT4_2_1 +# MASTER_1_COMMENT5_2_1 +# MASTER_1_COMMENT_P_2_1 diff --git a/storage/spider/mysql-test/spider/regression/e112122/my_2_1.cnf b/storage/spider/mysql-test/spider/regression/e112122/my_2_1.cnf new file mode 100644 index 00000000000..24161645607 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/my_2_1.cnf @@ -0,0 +1,56 @@ +[mysqld.2.1] +loose_handlersocket_port= 20002 +loose_handlersocket_port_wr= 20003 +loose_handlersocket_threads= 2 +loose_handlersocket_threads_wr= 1 +loose_handlersocket_support_merge_table= 0 +loose_handlersocket_direct_update_mode= 2 +loose_handlersocket_unlimited_boundary= 65536 +loose_handlersocket_bulk_insert= 0 +loose_handlersocket_bulk_insert_timeout= 0 +loose_handlersocket_general_log= 1 +loose_handlersocket_timeout= 30 +loose_handlersocket_close_table_interval=2 +open_files_limit= 4096 + +[ENV] +USE_CHILD_GROUP2= 1 +OUTPUT_CHILD_GROUP2= 0 +CHILD2_1_MYPORT= @mysqld.2.1.port +CHILD2_1_HSRPORT= 20002 +CHILD2_1_HSWPORT= 20003 +CHILD2_1_MYSOCK= @mysqld.2.1.socket +CHILD2_1_ENGINE_TYPE= InnoDB +CHILD2_1_ENGINE= ENGINE=InnoDB +CHILD2_1_CHARSET= DEFAULT CHARSET=utf8 +CHILD2_1_CHARSET2= DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci +CHILD2_1_FT_MYPORT= @mysqld.2.1.port +CHILD2_1_FT_MYSOCK= @mysqld.2.1.socket +CHILD2_1_FT_ENGINE_TYPE= MyISAM +CHILD2_1_FT_ENGINE= ENGINE=MyISAM +CHILD2_1_FT_CHARSET= DEFAULT CHARSET=utf8 +CHILD2_1_GM_MYPORT= @mysqld.2.1.port +CHILD2_1_GM_MYSOCK= @mysqld.2.1.socket +CHILD2_1_GM_ENGINE_TYPE= MyISAM +CHILD2_1_GM_ENGINE= ENGINE=MyISAM +CHILD2_1_GM_CHARSET= DEFAULT CHARSET=utf8 + +#The followings are set in include/init_xxx.inc files +# CHILD2_1_DROP_TABLES +# CHILD2_1_CREATE_TABLES +# CHILD2_1_SELECT_TABLES +# CHILD2_1_DROP_TABLES2 +# CHILD2_1_CREATE_TABLES2 +# CHILD2_1_SELECT_TABLES2 +# CHILD2_1_DROP_TABLES3 +# CHILD2_1_CREATE_TABLES3 +# CHILD2_1_SELECT_TABLES3 +# CHILD2_1_DROP_TABLES4 +# CHILD2_1_CREATE_TABLES4 +# CHILD2_1_SELECT_TABLES4 +# CHILD2_1_DROP_TABLES5 +# CHILD2_1_CREATE_TABLES5 +# CHILD2_1_SELECT_TABLES5 +# CHILD2_1_DROP_TABLES6 +# CHILD2_1_CREATE_TABLES6 +# CHILD2_1_SELECT_TABLES6 diff --git a/storage/spider/mysql-test/spider/regression/e112122/my_2_2.cnf b/storage/spider/mysql-test/spider/regression/e112122/my_2_2.cnf new file mode 100644 index 00000000000..2d3c2a89a7d --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/my_2_2.cnf @@ -0,0 +1,38 @@ +[mysqld.2.2] +loose_handlersocket_port= 20004 +loose_handlersocket_port_wr= 20005 +loose_handlersocket_threads= 2 +loose_handlersocket_threads_wr= 1 +loose_handlersocket_support_merge_table= 0 +loose_handlersocket_direct_update_mode= 2 +loose_handlersocket_unlimited_boundary= 65536 +loose_handlersocket_bulk_insert= 0 +loose_handlersocket_bulk_insert_timeout= 0 +loose_handlersocket_general_log= 1 +loose_handlersocket_timeout= 30 +loose_handlersocket_close_table_interval=2 +open_files_limit= 4096 + +[ENV] +CHILD2_2_MYPORT= @mysqld.2.2.port +CHILD2_2_HSRPORT= 20004 +CHILD2_2_HSWPORT= 20005 +CHILD2_2_MYSOCK= @mysqld.2.2.socket +CHILD2_2_ENGINE_TYPE= InnoDB +CHILD2_2_ENGINE= ENGINE=InnoDB +CHILD2_2_CHARSET= DEFAULT CHARSET=utf8 +CHILD2_2_FT_MYPORT= @mysqld.2.2.port +CHILD2_2_FT_MYSOCK= @mysqld.2.2.socket +CHILD2_2_FT_ENGINE_TYPE= MyISAM +CHILD2_2_FT_ENGINE= ENGINE=MyISAM +CHILD2_2_FT_CHARSET= DEFAULT CHARSET=utf8 +CHILD2_2_GM_MYPORT= @mysqld.2.2.port +CHILD2_2_GM_MYSOCK= @mysqld.2.2.socket +CHILD2_2_GM_ENGINE_TYPE= MyISAM +CHILD2_2_GM_ENGINE= ENGINE=MyISAM +CHILD2_2_GM_CHARSET= DEFAULT CHARSET=utf8 + +#The followings are set in include/init_xxx.inc files +# CHILD2_2_DROP_TABLES +# CHILD2_2_CREATE_TABLES +# CHILD2_2_SELECT_TABLES diff --git a/storage/spider/mysql-test/spider/regression/e112122/r/group_by_order_by_limit_ok.result b/storage/spider/mysql-test/spider/regression/e112122/r/group_by_order_by_limit_ok.result new file mode 100644 index 00000000000..96746e09b8d --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/r/group_by_order_by_limit_ok.result @@ -0,0 +1,117 @@ +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +this test is for MDEV-18988 + +drop and create databases +connection master_1; +CREATE DATABASE auto_test_local; +USE auto_test_local; +connection child2_1; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; +connection child2_2; +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; + +create table and insert +connection child2_1; +CHILD2_1_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection child2_2; +CHILD2_2_CREATE_TABLES +TRUNCATE TABLE mysql.general_log; +connection master_1; +CREATE TABLE tbl_a ( +pkey int NOT NULL, +skey int NOT NULL, +KEY idx1 (pkey), +KEY idx2 (skey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1 +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); +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); +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); + +select test 1 +connection child2_1; +TRUNCATE TABLE mysql.general_log; +connection child2_2; +TRUNCATE TABLE mysql.general_log; +connection master_1; +SELECT skey, count(*) cnt FROM tbl_a GROUP BY skey ORDER BY cnt DESC, skey DESC LIMIT 5; +skey cnt +14 2 +13 2 +12 2 +11 2 +10 2 +connection child2_1; +SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; +argument +select count(0),`skey` from `auto_test_remote`.`tbl_a` group by `skey` order by count(0) desc,`skey` desc limit 5 +SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %' +SELECT pkey, skey FROM tbl_a ORDER BY pkey; +pkey skey +1 1 +3 3 +5 5 +7 7 +9 9 +11 11 +13 13 +15 15 +17 17 +19 19 +20 5 +22 7 +24 9 +26 11 +28 13 +connection child2_2; +SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %'; +argument +select count(0),`skey` from `auto_test_remote2`.`tbl_a` group by `skey` order by count(0) desc,`skey` desc limit 5 +SELECT argument FROM mysql.general_log WHERE argument LIKE '%select %' +SELECT pkey, skey FROM tbl_a ORDER BY pkey; +pkey skey +0 0 +2 2 +4 4 +6 6 +8 8 +10 10 +12 12 +14 14 +16 16 +18 18 +21 6 +23 8 +25 10 +27 12 +29 14 + +deinit +connection master_1; +DROP DATABASE IF EXISTS auto_test_local; +connection child2_1; +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; +connection child2_2; +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; +for master_1 +for child2 +child2_1 +child2_2 +child2_3 +for child3 + +end of test diff --git a/storage/spider/mysql-test/spider/regression/e112122/suite.opt b/storage/spider/mysql-test/spider/regression/e112122/suite.opt new file mode 100644 index 00000000000..672a3b37d4f --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/suite.opt @@ -0,0 +1 @@ +--loose-innodb --loose-skip-performance-schema diff --git a/storage/spider/mysql-test/spider/regression/e112122/suite.pm b/storage/spider/mysql-test/spider/regression/e112122/suite.pm new file mode 100644 index 00000000000..f106147deb6 --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/suite.pm @@ -0,0 +1,12 @@ +package My::Suite::Spider; + +@ISA = qw(My::Suite); + +return "No Spider engine" unless $ENV{HA_SPIDER_SO}; +return "Not run for embedded server" if $::opt_embedded_server; +return "Test needs --big-test" unless $::opt_big_test; + +sub is_default { 1 } + +bless { }; + diff --git a/storage/spider/mysql-test/spider/regression/e112122/t/group_by_order_by_limit_ok.test b/storage/spider/mysql-test/spider/regression/e112122/t/group_by_order_by_limit_ok.test new file mode 100644 index 00000000000..2a70098ed1b --- /dev/null +++ b/storage/spider/mysql-test/spider/regression/e112122/t/group_by_order_by_limit_ok.test @@ -0,0 +1,97 @@ +--source ../include/group_by_order_by_limit_ok_init.inc +--echo +--echo this test is for MDEV-18988 +--echo +--echo drop and create databases +--connection master_1 +--disable_warnings +CREATE DATABASE auto_test_local; +USE auto_test_local; + +--connection child2_1 +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote; +USE auto_test_remote; + +--connection child2_2 +SET @old_log_output = @@global.log_output; +SET GLOBAL log_output = 'TABLE,FILE'; +CREATE DATABASE auto_test_remote2; +USE auto_test_remote2; +--enable_warnings + +--echo +--echo create table and insert + +--connection child2_1 +--disable_query_log +echo CHILD2_1_CREATE_TABLES; +eval $CHILD2_1_CREATE_TABLES; +--enable_query_log +TRUNCATE TABLE mysql.general_log; + +--connection child2_2 +--disable_query_log +echo CHILD2_2_CREATE_TABLES; +eval $CHILD2_2_CREATE_TABLES; +--enable_query_log +TRUNCATE TABLE mysql.general_log; + +--connection master_1 +--disable_query_log +echo CREATE TABLE tbl_a ( + pkey int NOT NULL, + skey int NOT NULL, + KEY idx1 (pkey), + KEY idx2 (skey) +) MASTER_1_ENGINE MASTER_1_CHARSET MASTER_1_COMMENT_2_1; +eval CREATE TABLE tbl_a ( + pkey int NOT NULL, + skey int NOT NULL, + KEY idx1 (pkey), + KEY idx2 (skey) +) $MASTER_1_ENGINE $MASTER_1_CHARSET $MASTER_1_COMMENT_2_1; +--enable_query_log +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); +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); +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); + +--echo +--echo select test 1 + +--connection child2_1 +TRUNCATE TABLE mysql.general_log; + +--connection child2_2 +TRUNCATE TABLE mysql.general_log; + +--connection master_1 +SELECT skey, count(*) cnt FROM tbl_a GROUP BY skey ORDER BY cnt DESC, skey DESC LIMIT 5; + +--connection child2_1 +eval $CHILD2_1_SELECT_ARGUMENT1; +eval $CHILD2_1_SELECT_TABLES; + +--connection child2_2 +eval $CHILD2_2_SELECT_ARGUMENT1; +eval $CHILD2_2_SELECT_TABLES; + +--echo +--echo deinit +--disable_warnings +--connection master_1 +DROP DATABASE IF EXISTS auto_test_local; + +--connection child2_1 +DROP DATABASE IF EXISTS auto_test_remote; +SET GLOBAL log_output = @old_log_output; + +--connection child2_2 +DROP DATABASE IF EXISTS auto_test_remote2; +SET GLOBAL log_output = @old_log_output; + +--enable_warnings +--source ../include/group_by_order_by_limit_ok_deinit.inc +--echo +--echo end of test diff --git a/storage/spider/spd_table.cc b/storage/spider/spd_table.cc index ed59a9be0a9..d17e76e5ec6 100644 --- a/storage/spider/spd_table.cc +++ b/storage/spider/spd_table.cc @@ -8909,6 +8909,13 @@ bool spider_check_direct_order_limit( break; } } + if (!spider_all_part_in_order((ORDER *) select_lex->group_list.first, + spider->get_table())) + { + DBUG_PRINT("info",("spider FALSE by group condition")); + first_check = FALSE; + spider->result_list.direct_distinct = FALSE; + } #endif } @@ -8974,6 +8981,98 @@ bool spider_check_direct_order_limit( DBUG_RETURN(FALSE); } +#ifdef HANDLER_HAS_DIRECT_AGGREGATE +bool spider_all_part_in_order( + ORDER *order, + TABLE *table +) { + TABLE_LIST *parent; + partition_info *part_info; + Field **part_fields; + ORDER *ptr; + Item *item; + Item_field *item_field; + DBUG_ENTER("spider_all_part_in_order"); + while (TRUE) + { + DBUG_PRINT("info", ("spider table_name = %s", table->s->db.str)); + DBUG_PRINT("info",("spider part_info=%p", table->part_info)); + if ((part_info = table->part_info)) + { + for (part_fields = part_info->full_part_field_array; + *part_fields; ++part_fields) + { + DBUG_PRINT("info", ("spider part_field = %s", + SPIDER_field_name_str(*part_fields))); + for (ptr = order; ptr; ptr = ptr->next) + { + item = *ptr->item; + if (item->type() != Item::FIELD_ITEM) + { + continue; + } + item_field = (Item_field *) item; + Field *field = item_field->field; + if (!field) + { + continue; + } + DBUG_PRINT("info", ("spider field_name = %s.%s", + field->table->s->db.str, SPIDER_field_name_str(field))); + if (*part_fields == spider_field_exchange(table->file, field)) + { + break; + } + } + if (!ptr) + { + DBUG_RETURN(FALSE); + } + } + } + if (!(parent = table->pos_in_table_list->parent_l)) + { + break; + } + table = parent->table; + } + DBUG_RETURN(TRUE); +} + +Field *spider_field_exchange( + handler *handler, + Field *field +) { + DBUG_ENTER("spider_field_exchange"); +#ifdef HA_CAN_BULK_ACCESS + if (handler->is_bulk_access_clone) + { + handler = handler->pt_clone_source_handler; + } +#endif + DBUG_PRINT("info",("spider in field=%p", field)); + DBUG_PRINT("info",("spider in field->table=%p", field->table)); +#ifdef HANDLER_HAS_TOP_TABLE_FIELDS + if (handler->set_top_table_fields) + { + DBUG_PRINT("info",("spider top_table=%p", handler->top_table)); + if (field->table != handler->top_table) + DBUG_RETURN(NULL); + if (!(field = handler->top_table_field[field->field_index])) + DBUG_RETURN(NULL); + } else { +#endif + DBUG_PRINT("info",("spider table=%p", handler->get_table())); + if (field->table != handler->get_table()) + DBUG_RETURN(NULL); +#ifdef HANDLER_HAS_TOP_TABLE_FIELDS + } +#endif + DBUG_PRINT("info",("spider out field=%p", field)); + DBUG_RETURN(field); +} +#endif + int spider_set_direct_limit_offset( ha_spider *spider ) { diff --git a/storage/spider/spd_table.h b/storage/spider/spd_table.h index 43958ca6e78..647b03953f3 100644 --- a/storage/spider/spd_table.h +++ b/storage/spider/spd_table.h @@ -1,4 +1,5 @@ -/* Copyright (C) 2008-2017 Kentoku Shiba +/* Copyright (C) 2008-2019 Kentoku Shiba + Copyright (C) 2019 MariaDB corp This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -638,6 +639,18 @@ bool spider_check_direct_order_limit( ha_spider *spider ); +#ifdef HANDLER_HAS_DIRECT_AGGREGATE +bool spider_all_part_in_order( + ORDER *order, + TABLE *table +); + +Field *spider_field_exchange( + handler *handler, + Field *field +); +#endif + int spider_set_direct_limit_offset( ha_spider* spider ); |