1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-30 16:24:05 +03:00

Fix of problem with WHERE/HAVING consist of alone outer reference field by wrapping it.

sql/item.cc:
  Wrapper added.
sql/item.h:
  Wrapper added.
sql/mysql_priv.h:
  Wrap function added.
sql/sql_base.cc:
  Wrap function added.
  Fix of problem with WHERE consist of alone outer reference field by wrapping it.
sql/sql_select.cc:
  Fix of problem with HAVING consist of alone outer reference field by wrapping it.
This commit is contained in:
unknown
2011-01-24 13:31:17 +02:00
parent 2038256bed
commit 481cd2dbf1
5 changed files with 110 additions and 2 deletions

View File

@ -8120,6 +8120,29 @@ insert_fields(THD *thd, Name_resolution_context *context, const char *db_name,
}
/**
Wrap Item_ident
@param thd thread handle
@param conds pointer to the condition which should be wrapped
*/
void wrap_ident(THD *thd, Item **conds)
{
Item_direct_ref_to_ident *wrapper;
DBUG_ASSERT((*conds)->type() == Item::FIELD_ITEM || (*conds)->type() == Item::REF_ITEM);
Query_arena *arena= thd->stmt_arena, backup;
if (arena->is_conventional())
arena= 0;
else
thd->set_n_backup_active_arena(arena, &backup);
if ((wrapper= new Item_direct_ref_to_ident((Item_ident *)(*conds))))
(*conds)= (Item*) wrapper;
if (arena)
thd->restore_active_arena(arena, &backup);
}
/*
Fix all conditions and outer join expressions.
@ -8183,6 +8206,12 @@ int setup_conds(THD *thd, TABLE_LIST *tables, TABLE_LIST *leaves,
print_where(*conds,
"WHERE in setup_conds",
QT_ORDINARY););
/*
Wrap alone field in WHERE clause in case it will be outer field of subquery
which need persistent pointer on it, but conds could be changed by optimizer
*/
if ((*conds)->type() == Item::FIELD_ITEM)
wrap_ident(thd, conds);
if ((!(*conds)->fixed && (*conds)->fix_fields(thd, conds)) ||
(*conds)->check_cols(1))
goto err_no_arena;