diff options
Diffstat (limited to 'sql')
-rw-r--r-- | sql/item_create.cc | 10 | ||||
-rw-r--r-- | sql/item_func.cc | 4 | ||||
-rw-r--r-- | sql/item_subselect.cc | 35 | ||||
-rw-r--r-- | sql/item_subselect.h | 12 | ||||
-rw-r--r-- | sql/mysql_priv.h | 5 | ||||
-rw-r--r-- | sql/sql_lex.cc | 9 | ||||
-rw-r--r-- | sql/sql_lex.h | 15 | ||||
-rw-r--r-- | sql/sql_select.cc | 6 | ||||
-rw-r--r-- | sql/sql_union.cc | 4 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 22 |
10 files changed, 62 insertions, 60 deletions
diff --git a/sql/item_create.cc b/sql/item_create.cc index 0195f0c24bc..c46696dfabf 100644 --- a/sql/item_create.cc +++ b/sql/item_create.cc @@ -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); } diff --git a/sql/item_func.cc b/sql/item_func.cc index 43cc67b554e..02a85eea193 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -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; } diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 9fd6dab83f6..a60a35aac6b 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -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; } diff --git a/sql/item_subselect.h b/sql/item_subselect.h index 712b3de42ad..3637e025d3c 100644 --- a/sql/item_subselect.h +++ b/sql/item_subselect.h @@ -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); diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 71ad5ce67c2..53896a4a182 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -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 diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index a55b801a0fc..f9fb2a5529f 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -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; diff --git a/sql/sql_lex.h b/sql/sql_lex.h index be931c56247..118283f141e 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -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; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 9d19ab1e470..745f19d0bcf 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -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); diff --git a/sql/sql_union.cc b/sql/sql_union.cc index 93541d66d65..5292299f928 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -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()) { diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index bb37c58004f..c6e4fe811e4 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -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); } ; |