Skip to content

Commit

Permalink
MDEV-13354: Server crashes in find_field_in_tables upon PS with windo…
Browse files Browse the repository at this point in the history
…w function and subquery

When creating an Item_direct_view_ref we were setting the
Name_resolution_context based on TABLE_LIST::view member variable.
However, for derived tables this member is NULL. To not set a wrong
context, if TABLE_LIST::view is empty, use THD::lex instead.
  • Loading branch information
cvicentiu committed Sep 19, 2017
1 parent 454b9b1 commit a1e589b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
11 changes: 11 additions & 0 deletions mysql-test/r/win.result
Original file line number Diff line number Diff line change
Expand Up @@ -3262,3 +3262,14 @@ is_not_null_lead_order
1
0
drop table t1;
#
# MDEV-13354: Server crashes in find_field_in_tables upon PS with window function and subquery
#
CREATE TABLE t1 (i INT, a char);
INSERT INTO t1 VALUES (1, 'a'),(2, 'b');
PREPARE stmt FROM "SELECT row_number() over (partition by i order by i), i FROM (SELECT * from t1) as sq";
EXECUTE stmt;
row_number() over (partition by i order by i) i
1 1
1 2
DROP TABLE t1;
11 changes: 11 additions & 0 deletions mysql-test/t/win.test
Original file line number Diff line number Diff line change
Expand Up @@ -2025,3 +2025,14 @@ FROM t1
ORDER BY a;

drop table t1;

--echo #
--echo # MDEV-13354: Server crashes in find_field_in_tables upon PS with window function and subquery
--echo #

CREATE TABLE t1 (i INT, a char);
INSERT INTO t1 VALUES (1, 'a'),(2, 'b');
PREPARE stmt FROM "SELECT row_number() over (partition by i order by i), i FROM (SELECT * from t1) as sq";
EXECUTE stmt;

DROP TABLE t1;
5 changes: 3 additions & 2 deletions sql/table.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5766,9 +5766,10 @@ Item *create_view_field(THD *thd, TABLE_LIST *view, Item **field_ref,
{
DBUG_RETURN(field);
}
Name_resolution_context *context= view->view ? &view->view->select_lex.context :
&thd->lex->select_lex.context;
Item *item= (new (thd->mem_root)
Item_direct_view_ref(thd, &view->view->select_lex.context,
field_ref, view->alias,
Item_direct_view_ref(thd, context, field_ref, view->alias,
name, view));
/*
Force creation of nullable item for the result tmp table for outer joined
Expand Down

0 comments on commit a1e589b

Please sign in to comment.