Skip to content

Conversation

@DaveGosselin-MariaDB
Copy link
Member

@DaveGosselin-MariaDB DaveGosselin-MariaDB commented Nov 18, 2025

Rewrite FULL OUTER JOIN queries as either LEFT, RIGHT, or INNER JOIN by checking if and how the WHERE clause rejects nulls.

For example, the following two queries are equivalent because the WHERE condition rejects nulls from the left table and allows matches in the right table (or NULL from the right table) for the remaining rows:

  SELECT * FROM t1 FULL JOIN t2 ON t1.v = t2.v WHERE t1.v IS NOT NULL;
  SELECT * FROM t1 LEFT JOIN t2 ON t1.v = t2.v;

@DaveGosselin-MariaDB DaveGosselin-MariaDB self-assigned this Nov 18, 2025
@DaveGosselin-MariaDB DaveGosselin-MariaDB force-pushed the 12.3-MDEV-37933-outer-to-left-right-or-inner branch 2 times, most recently from bf2f3ad to e3f59c1 Compare November 21, 2025 15:38
// Only the right table in a LEFT JOIN has the naming context in the grammar
left_table->on_context= nullptr;

// The grammar 'search_condition: ' rule marks this.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, an Item* object has been a FULL OUTER JOIN's ON expression and didn't have IS_COND flag?
But now it becomes a LEFT JOIN's ON expression and we're setting the flag.

A Naive question is, why don't we set IS_COND flag for FULL OUTER JOINs' ON expressions?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could do that but it would be nice if the grammar was not responsible for so much. I think it's better to keep the FULL JOIN rewrite bits all together in their respective functions. For example I would not like the grammar to call convert_right_join for RIGHT JOINs but defer that until after lexing is completed.

@DaveGosselin-MariaDB DaveGosselin-MariaDB force-pushed the 12.3-MDEV-37995-name-resolution branch from d6c2697 to c56d230 Compare November 26, 2025 16:25
Rewrite FULL OUTER JOIN queries as either LEFT, RIGHT, or INNER JOIN
by checking if and how the WHERE clause rejects nulls.

For example, the following two queries are equivalent because the
WHERE condition rejects nulls from the left table and allows matches
in the right table (or NULL from the right table) for the remaining
rows:

  SELECT * FROM t1 FULL JOIN t2 ON t1.v = t2.v WHERE t1.v IS NOT NULL;
  SELECT * FROM t1 LEFT JOIN t2 ON t1.v = t2.v;
@DaveGosselin-MariaDB DaveGosselin-MariaDB force-pushed the 12.3-MDEV-37933-outer-to-left-right-or-inner branch from e3f59c1 to b3825c2 Compare November 26, 2025 16:42
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