Skip to content

Commit 31e0ad6

Browse files
author
Tor Didriksen
committed
Bug #22200984 ASSERTION IN FILESORT::MAKE_SORTORDER()
Problem: make_sortorder() asserts in debug mode: we are not supposed to be sorting on outer references. If we switch off only_full_group_by then this schenario may happen. Solution: Relax the debug assert.
1 parent 2e11fe0 commit 31e0ad6

File tree

3 files changed

+40
-6
lines changed

3 files changed

+40
-6
lines changed

mysql-test/r/filesort_debug.result

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,3 +114,17 @@ FROM g
114114
GROUP BY b, a);
115115
1
116116
DROP TABLE t, g;
117+
#
118+
# Bug #22200984 ASSERTION IN FILESORT::MAKE_SORTORDER()
119+
#
120+
SET sql_mode="";
121+
Warnings:
122+
Warning 3090 Changing sql mode 'NO_AUTO_CREATE_USER' is deprecated. It will be removed in a future release.
123+
CREATE TABLE t1(a_t1 INT, c INT, d INT) ENGINE=INNODB;
124+
CREATE TABLE t2(a_t2 INT NOT NULL, UNIQUE KEY (a_t2)) ENGINE=INNODB;
125+
INSERT INTO t1 VALUES();
126+
SELECT (SELECT 1 FROM t2 GROUP BY d, a_t2 HAVING c) FROM t1 GROUP BY (1=2);
127+
(SELECT 1 FROM t2 GROUP BY d, a_t2 HAVING c)
128+
NULL
129+
DROP TABLE t1, t2;
130+
SET sql_mode=default;

mysql-test/t/filesort_debug.test

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,3 +190,18 @@ HAVING (SELECT a
190190
GROUP BY b, a);
191191

192192
DROP TABLE t, g;
193+
194+
--echo #
195+
--echo # Bug #22200984 ASSERTION IN FILESORT::MAKE_SORTORDER()
196+
--echo #
197+
198+
# group by d below is incompatible with sql_mode=only_full_group_by
199+
SET sql_mode="";
200+
201+
CREATE TABLE t1(a_t1 INT, c INT, d INT) ENGINE=INNODB;
202+
CREATE TABLE t2(a_t2 INT NOT NULL, UNIQUE KEY (a_t2)) ENGINE=INNODB;
203+
INSERT INTO t1 VALUES();
204+
SELECT (SELECT 1 FROM t2 GROUP BY d, a_t2 HAVING c) FROM t1 GROUP BY (1=2);
205+
DROP TABLE t1, t2;
206+
207+
SET sql_mode=default;

sql/filesort.cc

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -622,12 +622,17 @@ uint Filesort::make_sortorder()
622622
pos->field= 0; pos->item= 0;
623623
if (real_item->type() == Item::FIELD_ITEM)
624624
{
625-
// Could be a field, or Item_direct_view_ref/Item_ref wrapping a field
626-
DBUG_ASSERT(item->type() == Item::FIELD_ITEM ||
627-
(item->type() == Item::REF_ITEM &&
628-
(down_cast<Item_ref*>(item)->ref_type() == Item_ref::VIEW_REF
629-
|| down_cast<Item_ref*>(item)->ref_type() == Item_ref::REF)
630-
));
625+
/*
626+
Could be a field, or Item_direct_view_ref/Item_ref wrapping a field
627+
If it is an Item_outer_ref, only_full_group_by has been switched off.
628+
*/
629+
DBUG_ASSERT
630+
(item->type() == Item::FIELD_ITEM ||
631+
(item->type() == Item::REF_ITEM &&
632+
(down_cast<Item_ref*>(item)->ref_type() == Item_ref::VIEW_REF
633+
|| down_cast<Item_ref*>(item)->ref_type() == Item_ref::OUTER_REF
634+
|| down_cast<Item_ref*>(item)->ref_type() == Item_ref::REF)
635+
));
631636
pos->field= down_cast<Item_field*>(real_item)->field;
632637
}
633638
else if (real_item->type() == Item::SUM_FUNC_ITEM &&

0 commit comments

Comments
 (0)