Skip to content

Conversation

@DaveGosselin-MariaDB
Copy link
Member

Allow FULL OUTER JOIN queries to proceed through name resolution.

Permits limited EXPLAIN EXTENDED support so tests can prove that the JOIN_TYPE_* table markings are reflected when the query is echoed back by the server. This happens in at least two places: via a Warning message during EXPLAIN EXTENDED and during VIEW .frm file creation.

While the query plan output is mostly meaningless at this point, this limited EXPLAIN support improves the SELECT_LEX print function for the new JOIN types.

PS protocol is disabled in the tests for FULL JOIN at this point and will be fixed as FULL JOIN development continues.

@spetrunia
Copy link
Member

It's interesting that NATURAL JOIN was supported before without JOIN_TYPE_NATURAL . Is it really necessary to add it now?

@spetrunia
Copy link
Member

spetrunia commented Nov 25, 2025

So I'm playing with these queries:

Q1: fails

MariaDB [test]> select * from t1 cross join t2 full outer join t3 on t1.a=t3.a;
ERROR 1054 (42S22): Unknown column 't1.a' in 'ON'

Q2: fails

MariaDB [test]> select * from t1 cross join (t2 full outer join t3 on t1.a=t3.a);
ERROR 1054 (42S22): Unknown column 't1.a' in 'ON'

Q3: Accepted

MariaDB [test]> select * from (t1 cross join t2) full outer join t3 on t1.a=t3.a;
ERROR 1235 (42000): This version of MariaDB doesn't yet support 'full join'

It looks like Q1 is parsed in the same way as Q2.
and Chatgpt tells me that "Outer/inner joins bind tighter than CROSS JOIN (comma)".
EDIT: and now it said that this statement was wrong.

Okay, but running the same queries in PostgreSQL: https://dbfiddle.uk/woT65Sxc
and SQL Server: https://dbfiddle.uk/lWj3fZxJ, I get this result in both:

Q1: accepted
Q2: fails 
Q3: accepted

Any idea?

@DaveGosselin-MariaDB
Copy link
Member Author

It's interesting that NATURAL JOIN was supported before without JOIN_TYPE_NATURAL . Is it really necessary to add it now?

Yes, it's needed for correct SELECT_LEX prints:

    /*
      NATURAL JOINs don't expose explicit join columns, so don't
      print them as they're considered invalid syntax (this is
      important for VIEWs as when VIEWs are loaded, their SQL
      syntax is parsed again and must be valid).
    */
    if (curr->on_expr && !(curr->outer_join & JOIN_TYPE_NATURAL))

@DaveGosselin-MariaDB
Copy link
Member Author

DaveGosselin-MariaDB commented Nov 26, 2025

So I'm playing with these queries:

Q1: fails

MariaDB [test]> select * from t1 cross join t2 full outer join t3 on t1.a=t3.a;
ERROR 1054 (42S22): Unknown column 't1.a' in 'ON'

Q2: fails

MariaDB [test]> select * from t1 cross join (t2 full outer join t3 on t1.a=t3.a);
ERROR 1054 (42S22): Unknown column 't1.a' in 'ON'

Q3: Accepted

MariaDB [test]> select * from (t1 cross join t2) full outer join t3 on t1.a=t3.a;
ERROR 1235 (42000): This version of MariaDB doesn't yet support 'full join'

It looks like Q1 is parsed in the same way as Q2. and Chatgpt tells me that "Outer/inner joins bind tighter than CROSS JOIN (comma)". EDIT: and now it said that this statement was wrong.

Okay, but running the same queries in PostgreSQL: https://dbfiddle.uk/woT65Sxc and SQL Server: https://dbfiddle.uk/lWj3fZxJ, I get this result in both:

Q1: accepted
Q2: fails 
Q3: accepted

Any idea?

Yes, we need to attach the on_context in the grammar to both the left and right tables, not just the left table, when parsing a FULL JOIN.

diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy
index 17120e3ab76..24fd9b5510e 100644
--- a/sql/sql_yacc.yy
+++ b/sql/sql_yacc.yy
@@ -12389,6 +12389,7 @@ join_table:
           {
             add_join_on(thd, $5, $8);
             $1->on_context= Lex->pop_context();
+            $5->on_context= $1->on_context;
             Select->parsing_place= NO_MATTER;
             $$= $1;
             Lex->has_full_outer_join= true;

Now the queries accept/reject as expected:

MariaDB [test]> select * from t1 cross join t2 full outer join t3 on t1.a=t3.a;
ERROR 1235 (42000): This version of MariaDB doesn't yet support 'full join'
MariaDB [test]> select * from t1 cross join (t2 full outer join t3 on t1.a=t3.a);
ERROR 1054 (42S22): Unknown column 't1.a' in 'ON'
MariaDB [test]>  select * from (t1 cross join t2) full outer join t3 on t1.a=t3.a;
ERROR 1235 (42000): This version of MariaDB doesn't yet support 'full join'

(Later, during simplify_joins, the context will be removed if a rewrite can be done.)

Allow FULL OUTER JOIN queries to proceed through name resolution.

Permits limited EXPLAIN EXTENDED support so tests can prove that the
JOIN_TYPE_* table markings are reflected when the query is echoed back by the
server.  This happens in at least two places:  via a Warning message during
EXPLAIN EXTENDED and during VIEW .frm file creation.

While the query plan output is mostly meaningless at this point, this
limited EXPLAIN support improves the SELECT_LEX print function for the new
JOIN types.
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