mirror of
https://github.com/MariaDB/server.git
synced 2025-08-01 03:47:19 +03:00
prevent substituting Item_ref as VIEW fields in WHERE conditions (BUG#5969)
prevent filling temporary tables of views on list fields command sql/opt_range.cc: debug output fixed sql/sql_base.cc: prevent substituting Item_ref as VIEW fields in WHERE conditions sql/sql_parse.cc: prevent filling temporary tables of views on list fields command
This commit is contained in:
@ -1533,7 +1533,7 @@ int SQL_SELECT::test_quick_select(THD *thd, key_map keys_to_use,
|
|||||||
{
|
{
|
||||||
uint idx;
|
uint idx;
|
||||||
double scan_time;
|
double scan_time;
|
||||||
DBUG_ENTER("test_quick_select");
|
DBUG_ENTER("SQL_SELECT::test_quick_select");
|
||||||
//printf("\nQUERY: %s\n", thd->query);
|
//printf("\nQUERY: %s\n", thd->query);
|
||||||
DBUG_PRINT("enter",("keys_to_use: %lu prev_tables: %lu const_tables: %lu",
|
DBUG_PRINT("enter",("keys_to_use: %lu prev_tables: %lu const_tables: %lu",
|
||||||
keys_to_use.to_ulonglong(), (ulong) prev_tables,
|
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;
|
SELECT_LEX *select_lex= thd->lex->current_select;
|
||||||
Item_arena *arena= thd->current_arena;
|
Item_arena *arena= thd->current_arena;
|
||||||
Item_arena backup;
|
Item_arena backup;
|
||||||
|
bool save_wrapper= thd->lex->current_select->no_wrap_view_item;
|
||||||
DBUG_ENTER("setup_conds");
|
DBUG_ENTER("setup_conds");
|
||||||
|
|
||||||
if (select_lex->conds_processed_with_permanent_arena ||
|
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->set_query_id=1;
|
||||||
|
|
||||||
|
thd->lex->current_select->no_wrap_view_item= 1;
|
||||||
select_lex->cond_count= 0;
|
select_lex->cond_count= 0;
|
||||||
if (*conds)
|
if (*conds)
|
||||||
{
|
{
|
||||||
thd->where="where clause";
|
thd->where="where clause";
|
||||||
if (!(*conds)->fixed && (*conds)->fix_fields(thd, tables, conds) ||
|
if (!(*conds)->fixed && (*conds)->fix_fields(thd, tables, conds) ||
|
||||||
(*conds)->check_cols(1))
|
(*conds)->check_cols(1))
|
||||||
DBUG_RETURN(1);
|
goto err_no_arena;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if we are using outer joins */
|
/* 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 &&
|
if (!embedded->on_expr->fixed &&
|
||||||
embedded->on_expr->fix_fields(thd, tables, &embedded->on_expr) ||
|
embedded->on_expr->fix_fields(thd, tables, &embedded->on_expr) ||
|
||||||
embedded->on_expr->check_cols(1))
|
embedded->on_expr->check_cols(1))
|
||||||
DBUG_RETURN(1);
|
goto err_no_arena;
|
||||||
select_lex->cond_count++;
|
select_lex->cond_count++;
|
||||||
}
|
}
|
||||||
if (embedded->natural_join)
|
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();
|
Item_cond_and *cond_and=new Item_cond_and();
|
||||||
|
|
||||||
if (!cond_and) // If not out of memory
|
if (!cond_and) // If not out of memory
|
||||||
DBUG_RETURN(1);
|
goto err_no_arena;
|
||||||
cond_and->top_level_item();
|
cond_and->top_level_item();
|
||||||
|
|
||||||
if (table->field_translation)
|
if (table->field_translation)
|
||||||
@ -3123,7 +3125,7 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds)
|
|||||||
if (*conds && !(*conds)->fixed)
|
if (*conds && !(*conds)->fixed)
|
||||||
{
|
{
|
||||||
if ((*conds)->fix_fields(thd, tables, conds))
|
if ((*conds)->fix_fields(thd, tables, conds))
|
||||||
DBUG_RETURN(1);
|
goto err_no_arena;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
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 && !embedded->on_expr->fixed)
|
||||||
{
|
{
|
||||||
if (embedded->on_expr->fix_fields(thd, tables, &table->on_expr))
|
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->where= *conds;
|
||||||
select_lex->conds_processed_with_permanent_arena= 1;
|
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));
|
DBUG_RETURN(test(thd->net.report_error));
|
||||||
|
|
||||||
err:
|
err:
|
||||||
if (arena)
|
if (arena)
|
||||||
thd->restore_backup_item_arena(arena, &backup);
|
thd->restore_backup_item_arena(arena, &backup);
|
||||||
|
err_no_arena:
|
||||||
|
thd->lex->current_select->no_wrap_view_item= save_wrapper;
|
||||||
DBUG_RETURN(1);
|
DBUG_RETURN(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1573,8 +1573,6 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
|
|||||||
if (grant_option &&
|
if (grant_option &&
|
||||||
check_grant(thd, SELECT_ACL, &table_list, 2, UINT_MAX, 0))
|
check_grant(thd, SELECT_ACL, &table_list, 2, UINT_MAX, 0))
|
||||||
break;
|
break;
|
||||||
/* switch on VIEW optimisation: do not fill temporary tables */
|
|
||||||
thd->lex->sql_command= SQLCOM_SHOW_FIELDS;
|
|
||||||
/* init structures for VIEW processing */
|
/* init structures for VIEW processing */
|
||||||
table_list.select_lex= &(thd->lex->select_lex);
|
table_list.select_lex= &(thd->lex->select_lex);
|
||||||
mysql_init_query(thd, (uchar*)"", 0);
|
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,
|
select_lex.table_list.link_in_list((byte*) &table_list,
|
||||||
(byte**) &table_list.next_local);
|
(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);
|
mysqld_list_fields(thd,&table_list,fields);
|
||||||
thd->lex->unit.cleanup();
|
thd->lex->unit.cleanup();
|
||||||
thd->cleanup_after_query();
|
thd->cleanup_after_query();
|
||||||
|
Reference in New Issue
Block a user