mirror of
https://github.com/MariaDB/server.git
synced 2025-01-29 10:14:19 +01:00
fixed using 'uncachable' tag and RAND_TABLE_BIT setting
sql/item_create.cc: specify cause of uncachability sql/item_func.cc: specify cause of uncachability sql/item_subselect.cc: fixed setting RAND_TABLE_BIT specify cause of uncachability sql/item_subselect.h: used one field for all uncachability causes sql/mysql_priv.h: causes of uncachability sql/sql_lex.cc: specify cause of uncachability sql/sql_lex.h: used one field for all uncachability causes sql/sql_select.cc: used one field for all uncachability causes sql/sql_union.cc: used one field for all uncachability causes sql/sql_yacc.yy: specify cause of uncachability
This commit is contained in:
parent
8fed6653de
commit
79533975b1
10 changed files with 62 additions and 60 deletions
|
@ -159,7 +159,7 @@ Item *create_func_from_days(Item* a)
|
|||
|
||||
Item *create_func_get_lock(Item* a, Item *b)
|
||||
{
|
||||
current_thd->lex.uncacheable();
|
||||
current_thd->lex.uncacheable(UNCACHEABLE_UNCACHEABLE);
|
||||
return new Item_func_get_lock(a, b);
|
||||
}
|
||||
|
||||
|
@ -324,7 +324,7 @@ Item *create_func_radians(Item *a)
|
|||
|
||||
Item *create_func_release_lock(Item* a)
|
||||
{
|
||||
current_thd->lex.uncacheable();
|
||||
current_thd->lex.uncacheable(UNCACHEABLE_UNCACHEABLE);
|
||||
return new Item_func_release_lock(a);
|
||||
}
|
||||
|
||||
|
@ -445,7 +445,7 @@ Item *create_func_year(Item* a)
|
|||
|
||||
Item *create_load_file(Item* a)
|
||||
{
|
||||
current_thd->lex.uncacheable();
|
||||
current_thd->lex.uncacheable(UNCACHEABLE_UNCACHEABLE);
|
||||
return new Item_load_file(a);
|
||||
}
|
||||
|
||||
|
@ -472,13 +472,13 @@ Item *create_func_cast(Item *a, Cast_target cast_type, int len,
|
|||
|
||||
Item *create_func_is_free_lock(Item* a)
|
||||
{
|
||||
current_thd->lex.uncacheable();
|
||||
current_thd->lex.uncacheable(UNCACHEABLE_UNCACHEABLE);
|
||||
return new Item_func_is_free_lock(a);
|
||||
}
|
||||
|
||||
Item *create_func_is_used_lock(Item* a)
|
||||
{
|
||||
current_thd->lex.uncacheable();
|
||||
current_thd->lex.uncacheable(UNCACHEABLE_UNCACHEABLE);
|
||||
return new Item_func_is_used_lock(a);
|
||||
}
|
||||
|
||||
|
|
|
@ -2947,7 +2947,7 @@ Item *get_system_var(THD *thd, enum_var_type var_type, LEX_STRING name,
|
|||
}
|
||||
if (!(item=var->item(thd, var_type, component_name)))
|
||||
return 0; // Impossible
|
||||
thd->lex.uncacheable();
|
||||
thd->lex.uncacheable(UNCACHEABLE_UNCACHEABLE);
|
||||
buff[0]='@';
|
||||
buff[1]='@';
|
||||
pos=buff+2;
|
||||
|
@ -2987,7 +2987,7 @@ Item *get_system_var(THD *thd, enum_var_type var_type, const char *var_name,
|
|||
DBUG_ASSERT(var != 0);
|
||||
if (!(item=var->item(thd, var_type, &null_lex_string)))
|
||||
return 0; // Impossible
|
||||
thd->lex.uncacheable();
|
||||
thd->lex.uncacheable(UNCACHEABLE_UNCACHEABLE);
|
||||
item->set_name(item_name, 0, system_charset_info); // Will use original name
|
||||
return item;
|
||||
}
|
||||
|
|
|
@ -111,10 +111,12 @@ bool Item_subselect::fix_fields(THD *thd_param, TABLE_LIST *tables, Item **ref)
|
|||
}
|
||||
fix_length_and_dec();
|
||||
}
|
||||
if (engine->uncacheable())
|
||||
uint8 uncacheable= engine->uncacheable();
|
||||
if (uncacheable)
|
||||
{
|
||||
const_item_cache= 0;
|
||||
used_tables_cache|= RAND_TABLE_BIT;
|
||||
if (uncacheable & UNCACHEABLE_RAND)
|
||||
used_tables_cache|= RAND_TABLE_BIT;
|
||||
}
|
||||
fixed= 1;
|
||||
thd->where= save_where;
|
||||
|
@ -155,7 +157,7 @@ void Item_subselect::fix_length_and_dec()
|
|||
|
||||
table_map Item_subselect::used_tables() const
|
||||
{
|
||||
return (table_map) (engine->dependent() ? used_tables_cache : 0L);
|
||||
return (table_map) (engine->uncacheable() ? used_tables_cache : 0L);
|
||||
}
|
||||
|
||||
|
||||
|
@ -558,7 +560,7 @@ Item_in_subselect::single_value_transformer(JOIN *join,
|
|||
}
|
||||
|
||||
if ((abort_on_null || (upper_not && upper_not->top_level())) &&
|
||||
!select_lex->master_unit()->dependent && !func->eqne_op())
|
||||
!select_lex->master_unit()->uncacheable && !func->eqne_op())
|
||||
{
|
||||
if (substitution)
|
||||
{
|
||||
|
@ -644,10 +646,10 @@ Item_in_subselect::single_value_transformer(JOIN *join,
|
|||
(char *)"<no matter>",
|
||||
(char *)in_left_expr_name);
|
||||
|
||||
unit->dependent= unit->uncacheable= 1;
|
||||
unit->uncacheable|= UNCACHEABLE_DEPENDENT;
|
||||
}
|
||||
|
||||
select_lex->dependent= select_lex->uncacheable= 1;
|
||||
select_lex->uncacheable|= UNCACHEABLE_DEPENDENT;
|
||||
Item *item;
|
||||
|
||||
item= (Item*) select_lex->item_list.head();
|
||||
|
@ -768,12 +770,12 @@ Item_in_subselect::row_value_transformer(JOIN *join)
|
|||
DBUG_RETURN(RES_ERROR);
|
||||
}
|
||||
thd->lex.current_select= current;
|
||||
unit->dependent= unit->uncacheable= 1;
|
||||
unit->uncacheable|= UNCACHEABLE_DEPENDENT;
|
||||
}
|
||||
|
||||
uint n= left_expr->cols();
|
||||
|
||||
select_lex->dependent= select_lex->uncacheable= 1;
|
||||
select_lex->uncacheable|= UNCACHEABLE_DEPENDENT;
|
||||
select_lex->setup_ref_array(thd,
|
||||
select_lex->order_list.elements +
|
||||
select_lex->group_list.elements);
|
||||
|
@ -1047,7 +1049,7 @@ int subselect_single_select_engine::exec()
|
|||
DBUG_RETURN(1);
|
||||
}
|
||||
}
|
||||
if ((select_lex->dependent || select_lex->uncacheable) && executed)
|
||||
if (select_lex->uncacheable && executed)
|
||||
{
|
||||
if (join->reinit())
|
||||
{
|
||||
|
@ -1199,24 +1201,13 @@ uint subselect_union_engine::cols()
|
|||
}
|
||||
|
||||
|
||||
bool subselect_single_select_engine::dependent()
|
||||
{
|
||||
return select_lex->dependent;
|
||||
}
|
||||
|
||||
bool subselect_union_engine::dependent()
|
||||
{
|
||||
return unit->dependent;
|
||||
}
|
||||
|
||||
|
||||
bool subselect_single_select_engine::uncacheable()
|
||||
uint8 subselect_single_select_engine::uncacheable()
|
||||
{
|
||||
return select_lex->uncacheable;
|
||||
}
|
||||
|
||||
|
||||
bool subselect_union_engine::uncacheable()
|
||||
uint8 subselect_union_engine::uncacheable()
|
||||
{
|
||||
return unit->uncacheable;
|
||||
}
|
||||
|
|
|
@ -269,8 +269,7 @@ public:
|
|||
virtual void fix_length_and_dec(Item_cache** row)= 0;
|
||||
virtual int exec()= 0;
|
||||
virtual uint cols()= 0; /* return number of columnss in select */
|
||||
virtual bool dependent()= 0; /* depended from outer select */
|
||||
virtual bool uncacheable()= 0; /* query is uncacheable */
|
||||
virtual uint8 uncacheable()= 0; /* query is uncacheable */
|
||||
enum Item_result type() { return res_type; }
|
||||
virtual void exclude()= 0;
|
||||
bool may_be_null() { return maybe_null; };
|
||||
|
@ -295,8 +294,7 @@ public:
|
|||
void fix_length_and_dec(Item_cache** row);
|
||||
int exec();
|
||||
uint cols();
|
||||
bool dependent();
|
||||
bool uncacheable();
|
||||
uint8 uncacheable();
|
||||
void exclude();
|
||||
table_map upper_select_const_tables();
|
||||
void print (String *str);
|
||||
|
@ -314,8 +312,7 @@ public:
|
|||
void fix_length_and_dec(Item_cache** row);
|
||||
int exec();
|
||||
uint cols();
|
||||
bool dependent();
|
||||
bool uncacheable();
|
||||
uint8 uncacheable();
|
||||
void exclude();
|
||||
table_map upper_select_const_tables();
|
||||
void print (String *str);
|
||||
|
@ -342,8 +339,7 @@ public:
|
|||
void fix_length_and_dec(Item_cache** row);
|
||||
int exec();
|
||||
uint cols() { return 1; }
|
||||
bool dependent() { return 1; }
|
||||
bool uncacheable() { return 1; }
|
||||
uint8 uncacheable() { return UNCACHEABLE_DEPENDENT; }
|
||||
void exclude();
|
||||
table_map upper_select_const_tables() { return 0; }
|
||||
void print (String *str);
|
||||
|
|
|
@ -248,6 +248,11 @@ extern CHARSET_INFO *national_charset_info, *table_alias_charset;
|
|||
|
||||
#define MY_CHARSET_BIN_MB_MAXLEN 1
|
||||
|
||||
// uncachable cause
|
||||
#define UNCACHEABLE_DEPENDENT 1
|
||||
#define UNCACHEABLE_RAND 2
|
||||
#define UNCACHEABLE_UNCACHEABLE 4
|
||||
|
||||
#ifdef EXTRA_DEBUG
|
||||
/*
|
||||
Sync points allow us to force the server to reach a certain line of code
|
||||
|
|
|
@ -965,7 +965,8 @@ void st_select_lex_node::init_query()
|
|||
{
|
||||
options= 0;
|
||||
linkage= UNSPECIFIED_TYPE;
|
||||
no_error= no_table_names_allowed= uncacheable= dependent= 0;
|
||||
no_error= no_table_names_allowed= 0;
|
||||
uncacheable= 0;
|
||||
}
|
||||
|
||||
void st_select_lex_node::init_select()
|
||||
|
@ -1215,12 +1216,12 @@ void st_select_lex::mark_as_dependent(SELECT_LEX *last)
|
|||
for (SELECT_LEX *s= this;
|
||||
s && s != last;
|
||||
s= s->outer_select())
|
||||
if ( !s->dependent )
|
||||
if (!(s->uncacheable & UNCACHEABLE_DEPENDENT))
|
||||
{
|
||||
// Select is dependent of outer select
|
||||
s->dependent= s->uncacheable= 1;
|
||||
s->uncacheable|= UNCACHEABLE_DEPENDENT;
|
||||
SELECT_LEX_UNIT *munit= s->master_unit();
|
||||
munit->dependent= munit->uncacheable= 1;
|
||||
munit->uncacheable|= UNCACHEABLE_DEPENDENT;
|
||||
//Tables will be reopened many times
|
||||
for (TABLE_LIST *tbl= s->get_table_list();
|
||||
tbl;
|
||||
|
|
|
@ -84,6 +84,7 @@ enum enum_sql_command {
|
|||
#define DESCRIBE_NORMAL 1
|
||||
#define DESCRIBE_EXTENDED 2
|
||||
|
||||
|
||||
typedef List<Item> List_item;
|
||||
|
||||
typedef struct st_lex_master_info
|
||||
|
@ -226,9 +227,14 @@ public:
|
|||
};
|
||||
|
||||
ulong options;
|
||||
/*
|
||||
result of this query can't be cached, bit field, can be :
|
||||
UNCACHEABLE_DEPENDENT
|
||||
UNCACHEABLE_RAND
|
||||
UNCACHEABLE_UNCACHEABLE
|
||||
*/
|
||||
uint8 uncacheable;
|
||||
enum sub_select_type linkage;
|
||||
bool dependent; /* dependent from outer select subselect */
|
||||
bool uncacheable; /* result of this query can't be cached */
|
||||
bool no_table_names_allowed; /* used for global order by */
|
||||
bool no_error; /* suppress error message (convert it to warnings) */
|
||||
|
||||
|
@ -565,7 +571,7 @@ typedef struct st_lex
|
|||
bool derived_tables;
|
||||
bool safe_to_cache_query;
|
||||
st_lex() {}
|
||||
inline void uncacheable()
|
||||
inline void uncacheable(uint8 cause)
|
||||
{
|
||||
safe_to_cache_query= 0;
|
||||
|
||||
|
@ -580,7 +586,8 @@ typedef struct st_lex
|
|||
un != &unit;
|
||||
sl= sl->outer_select(), un= sl->master_unit())
|
||||
{
|
||||
sl->uncacheable = un->uncacheable= 1;
|
||||
sl->uncacheable|= cause;
|
||||
un->uncacheable|= cause;
|
||||
}
|
||||
}
|
||||
} LEX;
|
||||
|
|
|
@ -9041,10 +9041,12 @@ int mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit, select_result *result)
|
|||
((sl == first)?
|
||||
((sl->linkage == DERIVED_TABLE_TYPE) ?
|
||||
"DERIVED":
|
||||
((sl->dependent)?"DEPENDENT SUBQUERY":
|
||||
((sl->uncacheable & UNCACHEABLE_DEPENDENT)?
|
||||
"DEPENDENT SUBQUERY":
|
||||
(sl->uncacheable?"UNCACHEABLE SUBQUERY":
|
||||
"SUBQUERY"))):
|
||||
((sl->dependent)?"DEPENDENT UNION":
|
||||
((sl->uncacheable & UNCACHEABLE_DEPENDENT)?
|
||||
"DEPENDENT UNION":
|
||||
sl->uncacheable?"UNCACHEABLE UNION":
|
||||
"UNION"))),
|
||||
result);
|
||||
|
|
|
@ -249,11 +249,11 @@ int st_select_lex_unit::exec()
|
|||
ulonglong add_rows=0;
|
||||
DBUG_ENTER("st_select_lex_unit::exec");
|
||||
|
||||
if (executed && !(dependent || uncacheable))
|
||||
if (executed && !uncacheable)
|
||||
DBUG_RETURN(0);
|
||||
executed= 1;
|
||||
|
||||
if ((dependent || uncacheable) || !item || !item->assigned())
|
||||
if (uncacheable || !item || !item->assigned())
|
||||
{
|
||||
if (optimized && item && item->assigned())
|
||||
{
|
||||
|
|
|
@ -2197,7 +2197,7 @@ select_option:
|
|||
YYABORT;
|
||||
Select->options|= OPTION_FOUND_ROWS;
|
||||
}
|
||||
| SQL_NO_CACHE_SYM { Lex->uncacheable(); }
|
||||
| SQL_NO_CACHE_SYM { Lex->safe_to_cache_query=0; }
|
||||
| SQL_CACHE_SYM
|
||||
{
|
||||
Lex->select_lex.options|= OPTION_TO_QUERY_CACHE;
|
||||
|
@ -2466,12 +2466,12 @@ simple_expr:
|
|||
| '@' ident_or_text SET_VAR expr
|
||||
{
|
||||
$$= new Item_func_set_user_var($2,$4);
|
||||
Lex->uncacheable();
|
||||
Lex->uncacheable(UNCACHEABLE_RAND);
|
||||
}
|
||||
| '@' ident_or_text
|
||||
{
|
||||
$$= new Item_func_get_user_var($2);
|
||||
Lex->uncacheable();
|
||||
Lex->uncacheable(UNCACHEABLE_RAND);
|
||||
}
|
||||
| '@' '@' opt_var_ident_type ident_or_text opt_component
|
||||
{
|
||||
|
@ -2587,7 +2587,7 @@ simple_expr:
|
|||
| ENCRYPT '(' expr ')'
|
||||
{
|
||||
$$= new Item_func_encrypt($3);
|
||||
Lex->uncacheable();
|
||||
Lex->uncacheable(UNCACHEABLE_RAND);
|
||||
}
|
||||
| ENCRYPT '(' expr ',' expr ')' { $$= new Item_func_encrypt($3,$5); }
|
||||
| DECODE_SYM '(' expr ',' TEXT_STRING_literal ')'
|
||||
|
@ -2755,9 +2755,9 @@ simple_expr:
|
|||
| POSITION_SYM '(' no_in_expr IN_SYM expr ')'
|
||||
{ $$ = new Item_func_locate($5,$3); }
|
||||
| RAND '(' expr ')'
|
||||
{ $$= new Item_func_rand($3); Lex->uncacheable();}
|
||||
{ $$= new Item_func_rand($3); Lex->uncacheable(UNCACHEABLE_RAND);}
|
||||
| RAND '(' ')'
|
||||
{ $$= new Item_func_rand(); Lex->uncacheable();}
|
||||
{ $$= new Item_func_rand(); Lex->uncacheable(UNCACHEABLE_RAND);}
|
||||
| REPLACE '(' expr ',' expr ',' expr ')'
|
||||
{ $$= new Item_func_replace($3,$5,$7); }
|
||||
| RIGHT '(' expr ',' expr ')'
|
||||
|
@ -2884,7 +2884,7 @@ simple_expr:
|
|||
| BENCHMARK_SYM '(' ULONG_NUM ',' expr ')'
|
||||
{
|
||||
$$=new Item_func_benchmark($3,$5);
|
||||
Lex->uncacheable();
|
||||
Lex->uncacheable(UNCACHEABLE_UNCACHEABLE);
|
||||
}
|
||||
| EXTRACT_SYM '(' interval FROM expr ')'
|
||||
{ $$=new Item_extract( $3, $5); };
|
||||
|
@ -3464,7 +3464,7 @@ procedure_clause:
|
|||
lex->proc_list.next= (byte**) &lex->proc_list.first;
|
||||
if (add_proc_to_list(lex->thd, new Item_field(NULL,NULL,$2.str)))
|
||||
YYABORT;
|
||||
Lex->uncacheable();
|
||||
Lex->uncacheable(UNCACHEABLE_UNCACHEABLE);
|
||||
}
|
||||
'(' procedure_list ')';
|
||||
|
||||
|
@ -3518,7 +3518,7 @@ into:
|
|||
LEX *lex=Lex;
|
||||
if (!lex->describe)
|
||||
{
|
||||
lex->uncacheable();
|
||||
lex->uncacheable(UNCACHEABLE_UNCACHEABLE);
|
||||
if (!(lex->exchange= new sql_exchange($3.str,0)))
|
||||
YYABORT;
|
||||
if (!(lex->result= new select_export(lex->exchange)))
|
||||
|
@ -3531,7 +3531,7 @@ into:
|
|||
LEX *lex=Lex;
|
||||
if (!lex->describe)
|
||||
{
|
||||
lex->uncacheable();
|
||||
lex->uncacheable(UNCACHEABLE_UNCACHEABLE);
|
||||
if (!(lex->exchange= new sql_exchange($3.str,1)))
|
||||
YYABORT;
|
||||
if (!(lex->result= new select_dump(lex->exchange)))
|
||||
|
@ -3540,7 +3540,7 @@ into:
|
|||
}
|
||||
| INTO select_var_list_init
|
||||
{
|
||||
Lex->uncacheable();
|
||||
Lex->uncacheable(UNCACHEABLE_UNCACHEABLE);
|
||||
}
|
||||
;
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue