MDEV-26013 distinct not work properly in some cases for spider tables
The bug is caused by the following reasons: * spider_group_by_handler::init_scan() generates a query for a data node. * The function adds DISTINCT if and only if spider_group_by_handler::query::distinct is TRUE. * spider_group_by_handler::query::distinct is set to the value of JOIN::select_distinct in JOIN::make_aggr_tables_info(). * In the test case, DISTINCT is not added because JOIN::select_distinct is FALSE at the call of JOIN::make_aggr_tables_info(). Why JOIN::select_distinct is set to FALSE? That is because the function JOIN::optimize_stage2() convert DISTINCT into GROUP BY and then optimizes away GROUP BY.
This commit is contained in:
parent
7ffa801cf2
commit
aafb888657
@ -3274,9 +3274,17 @@ bool JOIN::make_aggr_tables_info()
|
||||
|
||||
if (ht && ht->create_group_by)
|
||||
{
|
||||
/* Check if the storage engine can intercept the query */
|
||||
Query query= {&all_fields, select_distinct, tables_list, conds,
|
||||
group_list, order ? order : group_list, having};
|
||||
/*
|
||||
Check if the storage engine can intercept the query.
|
||||
|
||||
JOIN::optimize_stage2() might convert DISTINCT into GROUP BY and then
|
||||
optimize away GROUP BY (group_list). In such a case, we need to notify
|
||||
a storage engine supporting a group by handler of the existence of the
|
||||
original DISTINCT. Thus, we set select_distinct || group_optimized_away
|
||||
to Query::distinct.
|
||||
*/
|
||||
Query query= {&all_fields, select_distinct || group_optimized_away, tables_list,
|
||||
conds, group_list, order ? order : group_list, having};
|
||||
group_by_handler *gbh= ht->create_group_by(thd, &query);
|
||||
|
||||
if (gbh)
|
||||
|
42
storage/spider/mysql-test/spider/bugfix/r/mdev_26013.result
Normal file
42
storage/spider/mysql-test/spider/bugfix/r/mdev_26013.result
Normal file
@ -0,0 +1,42 @@
|
||||
for master_1
|
||||
for child2
|
||||
child2_1
|
||||
child2_2
|
||||
child2_3
|
||||
for child3
|
||||
|
||||
MDEV-26013 distinct not work properly in some cases for spider tables
|
||||
|
||||
connection child2_1;
|
||||
CREATE DATABASE auto_test_remote;
|
||||
USE auto_test_remote;
|
||||
CREATE TABLE tbl_a (
|
||||
`a`int,
|
||||
`b`int,
|
||||
PRIMARY KEY (`a`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
|
||||
insert into `tbl_a` VALUES (1,999), (2,999);
|
||||
connection master_1;
|
||||
CREATE DATABASE auto_test_remote;
|
||||
USE auto_test_remote;
|
||||
CREATE TABLE tbl_a (
|
||||
`a`int,
|
||||
`b`int,
|
||||
PRIMARY KEY (`a`)
|
||||
) ENGINE=Spider DEFAULT CHARSET=utf8 COMMENT='table "tbl_a"' PARTITION BY LIST COLUMNS(`a`) (
|
||||
PARTITION `pt1` DEFAULT COMMENT = 'srv "s_2_1"'
|
||||
);
|
||||
connection master_1;
|
||||
SELECT distinct b FROM tbl_a WHERE b=999;
|
||||
b
|
||||
999
|
||||
connection master_1;
|
||||
DROP DATABASE IF EXISTS auto_test_remote;
|
||||
connection child2_1;
|
||||
DROP DATABASE IF EXISTS auto_test_remote;
|
||||
for master_1
|
||||
for child2
|
||||
child2_1
|
||||
child2_2
|
||||
child2_3
|
||||
for child3
|
3
storage/spider/mysql-test/spider/bugfix/t/mdev_26013.cnf
Normal file
3
storage/spider/mysql-test/spider/bugfix/t/mdev_26013.cnf
Normal file
@ -0,0 +1,3 @@
|
||||
!include include/default_mysqld.cnf
|
||||
!include ../my_1_1.cnf
|
||||
!include ../my_2_1.cnf
|
51
storage/spider/mysql-test/spider/bugfix/t/mdev_26013.test
Normal file
51
storage/spider/mysql-test/spider/bugfix/t/mdev_26013.test
Normal file
@ -0,0 +1,51 @@
|
||||
--disable_warnings
|
||||
--disable_query_log
|
||||
--disable_result_log
|
||||
--source ../../t/test_init.inc
|
||||
--enable_result_log
|
||||
--enable_query_log
|
||||
--enable_warnings
|
||||
|
||||
--echo
|
||||
--echo MDEV-26013 distinct not work properly in some cases for spider tables
|
||||
--echo
|
||||
|
||||
--connection child2_1
|
||||
CREATE DATABASE auto_test_remote;
|
||||
USE auto_test_remote;
|
||||
|
||||
eval CREATE TABLE tbl_a (
|
||||
`a`int,
|
||||
`b`int,
|
||||
PRIMARY KEY (`a`)
|
||||
) $CHILD2_1_ENGINE $CHILD2_1_CHARSET;
|
||||
|
||||
insert into `tbl_a` VALUES (1,999), (2,999);
|
||||
|
||||
--connection master_1
|
||||
CREATE DATABASE auto_test_remote;
|
||||
USE auto_test_remote;
|
||||
|
||||
eval CREATE TABLE tbl_a (
|
||||
`a`int,
|
||||
`b`int,
|
||||
PRIMARY KEY (`a`)
|
||||
) $MASTER_1_ENGINE $MASTER_1_CHARSET COMMENT='table "tbl_a"' PARTITION BY LIST COLUMNS(`a`) (
|
||||
PARTITION `pt1` DEFAULT COMMENT = 'srv "s_2_1"'
|
||||
);
|
||||
|
||||
--connection master_1
|
||||
SELECT distinct b FROM tbl_a WHERE b=999;
|
||||
|
||||
--connection master_1
|
||||
DROP DATABASE IF EXISTS auto_test_remote;
|
||||
--connection child2_1
|
||||
DROP DATABASE IF EXISTS auto_test_remote;
|
||||
|
||||
--disable_warnings
|
||||
--disable_query_log
|
||||
--disable_result_log
|
||||
--source ../../t/test_deinit.inc
|
||||
--enable_result_log
|
||||
--enable_query_log
|
||||
--enable_warnings
|
Loading…
x
Reference in New Issue
Block a user