Commit 6599cd98 authored by Kentoku SHIBA's avatar Kentoku SHIBA Committed by GitHub

MDEV-18988 Wrong result when query with group by x order by y limit n (#1286)

parent 82d06989
--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
--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 %';
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
!include include/default_mysqld.cnf
!include ../my_1_1.cnf
!include ../my_2_1.cnf
!include ../my_2_2.cnf
--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
--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
--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 %';
!include include/default_mysqld.cnf
!include my_1_1.cnf
!include my_2_1.cnf
!include my_2_2.cnf
[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
[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
[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
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
--loose-innodb --loose-skip-performance-schema
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 { };
--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
...@@ -8909,6 +8909,13 @@ bool spider_check_direct_order_limit( ...@@ -8909,6 +8909,13 @@ bool spider_check_direct_order_limit(
break; 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 #endif
} }
...@@ -8974,6 +8981,98 @@ bool spider_check_direct_order_limit( ...@@ -8974,6 +8981,98 @@ bool spider_check_direct_order_limit(
DBUG_RETURN(FALSE); 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( int spider_set_direct_limit_offset(
ha_spider *spider ha_spider *spider
) { ) {
......
/* 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 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 it under the terms of the GNU General Public License as published by
...@@ -638,6 +639,18 @@ bool spider_check_direct_order_limit( ...@@ -638,6 +639,18 @@ bool spider_check_direct_order_limit(
ha_spider *spider 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( int spider_set_direct_limit_offset(
ha_spider* spider ha_spider* spider
); );
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment