Commit 7acbea3f authored by unknown's avatar unknown
Browse files

fix for bug #13545: Server crash caused by select query.


sql/sql_base.cc:
  fix for bug #13545: Server crash caused by select query.
  - compare table qualifier only with tables which are not nested joins.
  - perform recursion accordingly.
  - DBUG_ASSERT(table_list->table); added before the find_field_in_table() call.
parent 35598ff5
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -1375,3 +1375,31 @@ groupid price
6	9900
DROP VIEW v1,v2;
DROP TABLE t1,t2,t3,t4;
CREATE TABLE t1(a int);
CREATE TABLE t2(b int);
CREATE TABLE t3(c int, d int);
CREATE TABLE t4(d int);
CREATE TABLE t5(e int, f int);
CREATE TABLE t6(f int);
CREATE VIEW v1 AS 
SELECT e FROM t5 JOIN t6 ON t5.e=t6.f;
CREATE VIEW v2 AS 
SELECT e FROM t5 NATURAL JOIN t6;
SELECT t1.a FROM t1 JOIN t2 ON a=b JOIN t3 ON a=c JOIN t4 USING(d);
a
SELECT t1.x FROM t1 JOIN t2 ON a=b JOIN t3 ON a=c JOIN t4 USING(d);
ERROR 42S22: Unknown column 't1.x' in 'field list'
SELECT t1.a FROM t1 JOIN t2 ON a=b JOIN t3 ON a=c NATURAL JOIN t4;
a
SELECT t1.x FROM t1 JOIN t2 ON a=b JOIN t3 ON a=c NATURAL JOIN t4;
ERROR 42S22: Unknown column 't1.x' in 'field list'
SELECT v1.e FROM v1 JOIN t2 ON e=b JOIN t3 ON e=c JOIN t4 USING(d);
e
SELECT v1.x FROM v1 JOIN t2 ON e=b JOIN t3 ON e=c JOIN t4 USING(d);
ERROR 42S22: Unknown column 'v1.x' in 'field list'
SELECT v2.e FROM v2 JOIN t2 ON e=b JOIN t3 ON e=c JOIN t4 USING(d);
e
SELECT v2.x FROM v2 JOIN t2 ON e=b JOIN t3 ON e=c JOIN t4 USING(d);
ERROR 42S22: Unknown column 'v2.x' in 'field list'
DROP VIEW v1, v2;
DROP TABLE t1, t2, t3, t4, t5, t6;
+31 −0
Original line number Diff line number Diff line
@@ -801,3 +801,34 @@ SELECT * FROM

DROP VIEW v1,v2;
DROP TABLE t1,t2,t3,t4;

#
# Bug #13545: problem with NATURAL/USING joins.
#

CREATE TABLE t1(a int);
CREATE TABLE t2(b int);
CREATE TABLE t3(c int, d int);
CREATE TABLE t4(d int);
CREATE TABLE t5(e int, f int);
CREATE TABLE t6(f int);
CREATE VIEW v1 AS 
  SELECT e FROM t5 JOIN t6 ON t5.e=t6.f;
CREATE VIEW v2 AS 
  SELECT e FROM t5 NATURAL JOIN t6;

SELECT t1.a FROM t1 JOIN t2 ON a=b JOIN t3 ON a=c JOIN t4 USING(d);
--error 1054
SELECT t1.x FROM t1 JOIN t2 ON a=b JOIN t3 ON a=c JOIN t4 USING(d);
SELECT t1.a FROM t1 JOIN t2 ON a=b JOIN t3 ON a=c NATURAL JOIN t4;
--error 1054
SELECT t1.x FROM t1 JOIN t2 ON a=b JOIN t3 ON a=c NATURAL JOIN t4;
SELECT v1.e FROM v1 JOIN t2 ON e=b JOIN t3 ON e=c JOIN t4 USING(d);
--error 1054
SELECT v1.x FROM v1 JOIN t2 ON e=b JOIN t3 ON e=c JOIN t4 USING(d);
SELECT v2.e FROM v2 JOIN t2 ON e=b JOIN t3 ON e=c JOIN t4 USING(d);
--error 1054
SELECT v2.x FROM v2 JOIN t2 ON e=b JOIN t3 ON e=c JOIN t4 USING(d);

DROP VIEW v1, v2;
DROP TABLE t1, t2, t3, t4, t5, t6;
+6 −9
Original line number Diff line number Diff line
@@ -2988,7 +2988,7 @@ find_field_in_table_ref(THD *thd, TABLE_LIST *table_list,
    are the same as the table reference we are going to search for the field.

    We exclude from the test below NATURAL/USING joins and any nested join
    that is an operand of NATURAL/USING join, because each column in such
    because each column in such
    joins may potentially originate from a different table. However, base
    tables and views that are under some NATURAL/USING join are searched
    as usual base tables/views.
@@ -3001,8 +3001,8 @@ find_field_in_table_ref(THD *thd, TABLE_LIST *table_list,
    TODO: Ensure that table_name, db_name and tables->db always points to
          something !
  */
  if (/* Exclude natural joins and nested joins underlying natural joins. */
      (!(table_list->nested_join && table_list->join_columns) ||
  if (/* Exclude nested joins. */
      (!table_list->nested_join ||
       /* Include merge views and information schema tables. */
       table_list->field_translation) &&
      /*
@@ -3025,13 +3025,10 @@ find_field_in_table_ref(THD *thd, TABLE_LIST *table_list,
                                 register_tree_change)))
      *actual_table= table_list;
  }
  else if (!(table_list->nested_join && table_list->join_columns))
  else if (!table_list->nested_join)
  {
    /*
      'table_list' is a stored table. It is so because the only type of nested
      join passed to this procedure is a NATURAL/USING join or an operand of a
      NATURAL/USING join.
    */
    /* 'table_list' is a stored table. */
    DBUG_ASSERT(table_list->table);
    if ((fld= find_field_in_table(thd, table_list->table, name, length,
                                  check_grants_table, allow_rowid,
                                  cached_field_index_ptr)))