Commit b78f7214 authored by unknown's avatar unknown

MDEV-5353: server crash on subselect if WHERE applied to some result field

Correct processing of view/derived with no tables added.
parent 62e95943
......@@ -465,5 +465,19 @@ t1.val=t3.val
;
ERROR 42S22: Unknown column 'v.val' in 'field list'
drop table t1, t2;
#
# MDEV-5353: server crash on subselect if WHERE applied to some
# result field
#
SELECT * FROM
( SELECT 100 a, subsel.b FROM ( SELECT 200 b ) subsel ) tmp
WHERE tmp.b;
a b
100 200
SELECT * FROM
( SELECT 100 a, subsel.b FROM ( SELECT 200 b ) subsel ) tmp
WHERE tmp.a;
a b
100 200
# End of 5.3 tests
set optimizer_switch=@save_derived_optimizer_switch;
......@@ -383,7 +383,17 @@ set
drop table t1, t2;
--echo #
--echo # MDEV-5353: server crash on subselect if WHERE applied to some
--echo # result field
--echo #
SELECT * FROM
( SELECT 100 a, subsel.b FROM ( SELECT 200 b ) subsel ) tmp
WHERE tmp.b;
SELECT * FROM
( SELECT 100 a, subsel.b FROM ( SELECT 200 b ) subsel ) tmp
WHERE tmp.a;
--echo # End of 5.3 tests
set optimizer_switch=@save_derived_optimizer_switch;
......@@ -2963,13 +2963,16 @@ class Item_direct_view_ref :public Item_direct_ref
TABLE_LIST *view;
TABLE *null_ref_table;
#define NO_NULL_TABLE (reinterpret_cast<TABLE *>(0x1))
bool check_null_ref()
{
if (null_ref_table == NULL)
{
null_ref_table= view->get_real_join_table();
if (!(null_ref_table= view->get_real_join_table()))
null_ref_table= NO_NULL_TABLE;
}
if (null_ref_table->null_row)
if (null_ref_table != NO_NULL_TABLE && null_ref_table->null_row)
{
null_value= 1;
return TRUE;
......
......@@ -4487,10 +4487,8 @@ TABLE *TABLE_LIST::get_real_join_table()
*/
for (TABLE_LIST *t= ti++; t; t= ti++)
tbl= t;
/*
It is impossible that the list is empty
so tbl can't be NULL after above loop.
*/
if (!tbl)
return NULL; // view/derived with no tables
if (!tbl->nested_join)
break;
/* go deeper if we've found nested join */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment