Skip to content

Commit 729b27d

Browse files
MDEV-29300 Assertion `*ref && (*ref)->fixed()' failed in Item_field::fix_outer_field on SELECT
This issue arises when we have an outer reference resolved in another outer reference where that outer reference is resolved in a outer select that is a grouping select. Under these circumstances, the intermediate item is wrapped in an Item_outer_ref and fixing is deferred later until fix_inner_refs. As this item wrapper isn't fixed we fail this assertion. The fix here is to resolve the item at the lowest level to the item inside the wrapper, which is fixed. This item can then get it's own wrapper pointing to the ultimate resolution of this item. Approved by Sanja Byelkin (sanja@mariadb.com) 2025-06-13
1 parent 7ba32f3 commit 729b27d

File tree

3 files changed

+19
-0
lines changed

3 files changed

+19
-0
lines changed

mysql-test/main/subselect4.result

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3366,3 +3366,11 @@ Variable_name Value
33663366
Handler_read_rnd_next 0
33673367
drop table t1,t2,t3;
33683368
# End of 10.4 tests
3369+
#
3370+
# MDEV-29300 Assertion `*ref && (*ref)->fixed()' failed in Item_field::fix_outer_field on SELECT
3371+
#
3372+
CREATE TABLE t(c INT);
3373+
SELECT (SELECT 0 GROUP BY c HAVING (SELECT c)) FROM t GROUP BY c;
3374+
(SELECT 0 GROUP BY c HAVING (SELECT c))
3375+
DROP TABLE t;
3376+
# End of 10.11 tests

mysql-test/main/subselect4.test

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2687,3 +2687,12 @@ drop table t1,t2,t3;
26872687

26882688
--echo # End of 10.4 tests
26892689

2690+
--echo #
2691+
--echo # MDEV-29300 Assertion `*ref && (*ref)->fixed()' failed in Item_field::fix_outer_field on SELECT
2692+
--echo #
2693+
2694+
CREATE TABLE t(c INT);
2695+
SELECT (SELECT 0 GROUP BY c HAVING (SELECT c)) FROM t GROUP BY c;
2696+
DROP TABLE t;
2697+
2698+
--echo # End of 10.11 tests

sql/item.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5792,6 +5792,8 @@ resolve_ref_in_select_and_group(THD *thd, Item_ident *ref, SELECT_LEX *select)
57925792
DBUG_ASSERT((*select_ref)->fixed());
57935793
return &select->ref_pointer_array[counter];
57945794
}
5795+
if (group_by_ref && (*group_by_ref)->type() == Item::REF_ITEM)
5796+
return ((Item_ref*)(*group_by_ref))->ref;
57955797
if (group_by_ref)
57965798
return group_by_ref;
57975799
DBUG_ASSERT(FALSE);

0 commit comments

Comments
 (0)