Commit 41ddca4d authored by bell@sanja.is.com.ua's avatar bell@sanja.is.com.ua

prevent substituting Item_ref as VIEW fields in WHERE conditions (BUG#5969)

prevent filling temporary tables of views on list fields command
parent 183036ea
......@@ -1533,7 +1533,7 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use,
{
uint idx;
double scan_time;
DBUG_ENTER("test_quick_select");
DBUG_ENTER("SQL_SELECT::test_quick_select");
//printf("\nQUERY: %s\n", thd->query);
DBUG_PRINT("enter",("keys_to_use: %lu prev_tables: %lu const_tables: %lu",
keys_to_use.to_ulonglong(), (ulong) prev_tables,
......
......@@ -2973,6 +2973,7 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds)
SELECT_LEX *select_lex= thd->lex->current_select;
Item_arena *arena= thd->current_arena;
Item_arena backup;
bool save_wrapper= thd->lex->current_select->no_wrap_view_item;
DBUG_ENTER("setup_conds");
if (select_lex->conds_processed_with_permanent_arena ||
......@@ -2981,13 +2982,14 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds)
thd->set_query_id=1;
thd->lex->current_select->no_wrap_view_item= 1;
select_lex->cond_count= 0;
if (*conds)
{
thd->where="where clause";
if (!(*conds)->fixed && (*conds)->fix_fields(thd, tables, conds) ||
(*conds)->check_cols(1))
DBUG_RETURN(1);
goto err_no_arena;
}
/* Check if we are using outer joins */
......@@ -3005,7 +3007,7 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds)
if (!embedded->on_expr->fixed &&
embedded->on_expr->fix_fields(thd, tables, &embedded->on_expr) ||
embedded->on_expr->check_cols(1))
DBUG_RETURN(1);
goto err_no_arena;
select_lex->cond_count++;
}
if (embedded->natural_join)
......@@ -3059,7 +3061,7 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds)
Item_cond_and *cond_and=new Item_cond_and();
if (!cond_and) // If not out of memory
DBUG_RETURN(1);
goto err_no_arena;
cond_and->top_level_item();
if (table->field_translation)
......@@ -3123,7 +3125,7 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds)
if (*conds && !(*conds)->fixed)
{
if ((*conds)->fix_fields(thd, tables, conds))
DBUG_RETURN(1);
goto err_no_arena;
}
}
else
......@@ -3135,7 +3137,7 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds)
if (embedded->on_expr && !embedded->on_expr->fixed)
{
if (embedded->on_expr->fix_fields(thd, tables, &table->on_expr))
DBUG_RETURN(1);
goto err_no_arena;
}
}
}
......@@ -3157,11 +3159,14 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds)
select_lex->where= *conds;
select_lex->conds_processed_with_permanent_arena= 1;
}
thd->lex->current_select->no_wrap_view_item= save_wrapper;
DBUG_RETURN(test(thd->net.report_error));
err:
if (arena)
thd->restore_backup_item_arena(arena, &backup);
err_no_arena:
thd->lex->current_select->no_wrap_view_item= save_wrapper;
DBUG_RETURN(1);
}
......
......@@ -1573,8 +1573,6 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
if (grant_option &&
check_grant(thd, SELECT_ACL, &table_list, 2, UINT_MAX, 0))
break;
/* switch on VIEW optimisation: do not fill temporary tables */
thd->lex->sql_command= SQLCOM_SHOW_FIELDS;
/* init structures for VIEW processing */
table_list.select_lex= &(thd->lex->select_lex);
mysql_init_query(thd, (uchar*)"", 0);
......@@ -1582,6 +1580,8 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
select_lex.table_list.link_in_list((byte*) &table_list,
(byte**) &table_list.next_local);
/* switch on VIEW optimisation: do not fill temporary tables */
thd->lex->sql_command= SQLCOM_SHOW_FIELDS;
mysqld_list_fields(thd,&table_list,fields);
thd->lex->unit.cleanup();
thd->cleanup_after_query();
......
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