Skip to content
Permalink
Browse files
MDEV-16549 Server crashes in Item_field::fix_fields on query with vie…
…w and subquery, Assertion `context' failed, Assertion `field' failed

Add one-table-resolve context for items created with an aim of switching
to temporary table because then it can be cloned in push-down-condition.
  • Loading branch information
sanja-byelkin committed Oct 24, 2022
1 parent 28d6f6a commit e00ea30
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 2 deletions.
@@ -1313,3 +1313,19 @@ a a
4 4
6 6
drop table t1,t2,t3;
#
# MDEV-16549: Server crashes in Item_field::fix_fields on query with
# view and subquery, Assertion `context' failed, Assertion `field' failed
#
CREATE TABLE t1 (a DECIMAL, b INT);
INSERT INTO t1 VALUES (1,1),(2,2);
CREATE VIEW v1 AS SELECT * FROM ( SELECT * FROM t1 WHERE a <> RAND() ) sq;
SELECT * FROM v1 WHERE b > 0;
a b
1 1
2 2
DROP VIEW v1;
DROP TABLE t1;
#
# End of 10.3 tests
#
@@ -1120,3 +1120,23 @@ analyze select * from t1 , ( (select t2.a from t2 order by c) union all (select
select * from t1 , ( (select t2.a from t2 order by c) union all (select t2.a from t2 order by c) except(select t3.a from t3 order by b))q where t1.a=q.a;

drop table t1,t2,t3;


--echo #
--echo # MDEV-16549: Server crashes in Item_field::fix_fields on query with
--echo # view and subquery, Assertion `context' failed, Assertion `field' failed
--echo #

CREATE TABLE t1 (a DECIMAL, b INT);
INSERT INTO t1 VALUES (1,1),(2,2); # optional
CREATE VIEW v1 AS SELECT * FROM ( SELECT * FROM t1 WHERE a <> RAND() ) sq;

SELECT * FROM v1 WHERE b > 0;

# Cleanup
DROP VIEW v1;
DROP TABLE t1;

--echo #
--echo # End of 10.3 tests
--echo #
@@ -10753,6 +10753,20 @@ void view_error_processor(THD *thd, void *data)
((TABLE_LIST *)data)->hide_view_error(thd);
}

/**
Name resolution context with resolution in only one table
*/

Name_resolution_context::Name_resolution_context(TABLE_LIST *table):
outer_context(0), table_list(0), select_lex(0),
error_processor_data(0),
security_ctx(0)
{
resolve_in_select_list= FALSE;
error_processor= &dummy_error_processor;
// resolve only in this table
first_name_resolution_table= last_name_resolution_table= table;
}

st_select_lex *Item_ident::get_depended_from() const
{
@@ -237,6 +237,8 @@ struct Name_resolution_context: Sql_alloc
security_ctx(0)
{}

Name_resolution_context(TABLE_LIST *table);

void init()
{
resolve_in_select_list= FALSE;
@@ -8826,7 +8826,8 @@ bool TABLE_LIST::change_refs_to_fields()

Item **materialized_items=
(Item **)thd->calloc(sizeof(void *) * table->s->fields);
if (!materialized_items)
Name_resolution_context *ctx= new Name_resolution_context(this);
if (!materialized_items || !ctx)
return TRUE;

while ((ref= (Item_direct_ref*)li++))
@@ -8842,7 +8843,8 @@ bool TABLE_LIST::change_refs_to_fields()
DBUG_ASSERT(!field_it.end_of_fields());
if (!materialized_items[idx])
{
materialized_items[idx]= new (thd->mem_root) Item_field(thd, table->field[idx]);
materialized_items[idx]=
new (thd->mem_root) Item_field(thd, ctx, table->field[idx]);
if (!materialized_items[idx])
return TRUE;
}

0 comments on commit e00ea30

Please sign in to comment.