Commit d4e2cc15 authored by unknown's avatar unknown

Merge sanja.is.com.ua:/home/bell/mysql/bk/mysql-4.1

into sanja.is.com.ua:/home/bell/mysql/bk/work-used_tables-4.1


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