Permalink
Show file tree
Hide file tree
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
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.
- Loading branch information
1 parent
7ffa801
commit aafb888
Showing
4 changed files
with
107 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| !include include/default_mysqld.cnf | ||
| !include ../my_1_1.cnf | ||
| !include ../my_2_1.cnf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |