⚠ This page is served via a proxy. Original site: https://github.com
This service does not collect credentials or authentication data.
Skip to content

Conversation

@mariadb-RexJohnston
Copy link
Member

…UP BY use different aliases for the same column

MDEV-29300 fix causes a wrong result by incorrect removing a wrapper to
an item that needed to be wrapped for the correct result.  Direct access
to the item causes an incorrect table reference to be used during
join evaluation.  We reverting that fix.

Our original problem query is this
SELECT (SELECT 0 GROUP BY c1 HAVING (SELECT c1)) FROM t1 group by c1;

JOIN::prepare on
/* select#2 */ select 0 group by t1.t1a having (subquery#3)

fixing t1.t1a in group by clause, calls fix_outer_field()
this item is resolved in an outer select (#1) and it is a grouping select,
so we wrap it in Item_outer_ref and set this item to unfixed for later
fixing in fix_inner_refs().

JOIN::prepare continues onto the having clause and fixes (subquery#3) which
calls initiates the prepare series of calls, leading to setup_fields on the
fields in this JOIN, one of which is an outer reference t1a.
This is resolved to the item in the next most outer select in the group by
clause. This item has been wrapped with an unfixed Item_outer_ref.
It is found in resolve_ref_in_select_and_group() is it expected that
this item will have already been fixed, hence this call in

Item_field::fix_outer_field()

DBUG_ASSERT(*ref && (*ref)->fixed());

but as explained above, it isn't fixed and debug builds assert here.

Because this wrapper cannot be resolved here for reasons detailed in
fix_inner_refs, and we cannot remove this wrapper without potentially
returning an incorrect result, we have to relax this assertion.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants