Skip to content

Commit a1e589b

Browse files
committed
MDEV-13354: Server crashes in find_field_in_tables upon PS with window 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.
1 parent 454b9b1 commit a1e589b

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

mysql-test/r/win.result

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3262,3 +3262,14 @@ is_not_null_lead_order
32623262
1
32633263
0
32643264
drop table t1;
3265+
#
3266+
# MDEV-13354: Server crashes in find_field_in_tables upon PS with window function and subquery
3267+
#
3268+
CREATE TABLE t1 (i INT, a char);
3269+
INSERT INTO t1 VALUES (1, 'a'),(2, 'b');
3270+
PREPARE stmt FROM "SELECT row_number() over (partition by i order by i), i FROM (SELECT * from t1) as sq";
3271+
EXECUTE stmt;
3272+
row_number() over (partition by i order by i) i
3273+
1 1
3274+
1 2
3275+
DROP TABLE t1;

mysql-test/t/win.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2025,3 +2025,14 @@ FROM t1
20252025
ORDER BY a;
20262026

20272027
drop table t1;
2028+
2029+
--echo #
2030+
--echo # MDEV-13354: Server crashes in find_field_in_tables upon PS with window function and subquery
2031+
--echo #
2032+
2033+
CREATE TABLE t1 (i INT, a char);
2034+
INSERT INTO t1 VALUES (1, 'a'),(2, 'b');
2035+
PREPARE stmt FROM "SELECT row_number() over (partition by i order by i), i FROM (SELECT * from t1) as sq";
2036+
EXECUTE stmt;
2037+
2038+
DROP TABLE t1;

sql/table.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5766,9 +5766,10 @@ Item *create_view_field(THD *thd, TABLE_LIST *view, Item **field_ref,
57665766
{
57675767
DBUG_RETURN(field);
57685768
}
5769+
Name_resolution_context *context= view->view ? &view->view->select_lex.context :
5770+
&thd->lex->select_lex.context;
57695771
Item *item= (new (thd->mem_root)
5770-
Item_direct_view_ref(thd, &view->view->select_lex.context,
5771-
field_ref, view->alias,
5772+
Item_direct_view_ref(thd, context, field_ref, view->alias,
57725773
name, view));
57735774
/*
57745775
Force creation of nullable item for the result tmp table for outer joined

0 commit comments

Comments
 (0)