[Commits] 283cbcb9d85: MDEV-10880: Assertions `keypart_map' or `prebuilt->search_tuple->n_fields > 0' fail on DISTINCT and GROUP BY constant

Oleksandr Byelkin sanja at mariadb.com
Tue Jun 20 15:55:30 EEST 2017


revision-id: 283cbcb9d85cc35db4dd3d7d6610633c84ee465b (mariadb-10.1.24-23-g283cbcb9d85)
parent(s): 056bab0880544d91ea67d18fe8db65b4f6625482
committer: Oleksandr Byelkin
timestamp: 2017-06-20 14:55:30 +0200
message:

MDEV-10880: Assertions `keypart_map' or `prebuilt->search_tuple->n_fields > 0' fail on DISTINCT and GROUP BY constant

add_group_and_distinct_keys() should take into account JOIN::simple_group.

---
 mysql-test/r/order_by.result | 16 ++++++++++++++++
 mysql-test/t/order_by.test   | 12 ++++++++++++
 sql/sql_select.cc            |  2 +-
 3 files changed, 29 insertions(+), 1 deletion(-)

diff --git a/mysql-test/r/order_by.result b/mysql-test/r/order_by.result
index e24d9a94891..71aa32f0cee 100644
--- a/mysql-test/r/order_by.result
+++ b/mysql-test/r/order_by.result
@@ -3145,3 +3145,19 @@ id	select_type	table	type	possible_keys	key	key_len	ref	rows	Extra
 drop table t0,t1,t2,t3;
 set @@optimizer_switch=@tmp_8989;
 set optimizer_switch='orderby_uses_equalities=on';
+#
+# MDEV-10880: Assertions `keypart_map' or
+# `prebuilt->search_tuple->n_fields > 0' fail on DISTINCT and
+# GROUP BY constant
+#
+CREATE TABLE t1 (pk INT PRIMARY KEY);
+INSERT INTO t1 VALUES (1),(2),(3);
+SELECT DISTINCT pk FROM t1 GROUP BY 'foo';
+pk
+1
+SELECT DISTINCT pk FROM t1;
+pk
+1
+2
+3
+DROP TABLE t1;
diff --git a/mysql-test/t/order_by.test b/mysql-test/t/order_by.test
index 2d0c134a2d9..f61a6a8be34 100644
--- a/mysql-test/t/order_by.test
+++ b/mysql-test/t/order_by.test
@@ -2091,3 +2091,15 @@ set @@optimizer_switch=@tmp_8989;
 
 set optimizer_switch='orderby_uses_equalities=on';
 
+
+--echo #
+--echo # MDEV-10880: Assertions `keypart_map' or
+--echo # `prebuilt->search_tuple->n_fields > 0' fail on DISTINCT and
+--echo # GROUP BY constant
+--echo #
+
+CREATE TABLE t1 (pk INT PRIMARY KEY);
+INSERT INTO t1 VALUES (1),(2),(3);
+SELECT DISTINCT pk FROM t1 GROUP BY 'foo';
+SELECT DISTINCT pk FROM t1;
+DROP TABLE t1;
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 50f121ce47f..9f339146646 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -5708,7 +5708,7 @@ add_group_and_distinct_keys(JOIN *join, JOIN_TAB *join_tab)
   Item_field *cur_item;
   key_map possible_keys(0);
 
-  if (join->group_list)
+  if (join->group_list || join->simple_group)
   { /* Collect all query fields referenced in the GROUP clause. */
     for (cur_group= join->group_list; cur_group; cur_group= cur_group->next)
       (*cur_group->item)->walk(&Item::collect_item_field_processor, 0,


More information about the commits mailing list