Commit ae2192ed authored by pem@mysql.com's avatar pem@mysql.com

Moved safe_to_cache_query from thd to lex.

This is required for prepared statements and stored procedures.
parent b201dfec
......@@ -557,3 +557,8 @@ vio/test-ssl
vio/test-sslclient
vio/test-sslserver
vio/viotest-ssl
bkpull.log
bkpull.log.2
bkpull.log.3
build.log
sql/safe_to_cache_query.txt
......@@ -76,7 +76,7 @@ Item *create_func_ceiling(Item* a)
Item *create_func_connection_id(void)
{
THD *thd=current_thd;
thd->safe_to_cache_query=0;
thd->lex.safe_to_cache_query=0;
return new Item_int("CONNECTION_ID()",(longlong) thd->thread_id,10);
}
......@@ -149,7 +149,7 @@ Item *create_func_floor(Item* a)
Item *create_func_found_rows(void)
{
THD *thd=current_thd;
thd->safe_to_cache_query=0;
thd->lex.safe_to_cache_query=0;
return new Item_int("FOUND_ROWS()",(longlong) thd->found_rows(),21);
}
......@@ -160,7 +160,7 @@ Item *create_func_from_days(Item* a)
Item *create_func_get_lock(Item* a, Item *b)
{
current_thd->safe_to_cache_query=0;
current_thd->lex.safe_to_cache_query=0;
return new Item_func_get_lock(a, b);
}
......@@ -308,7 +308,7 @@ Item *create_func_radians(Item *a)
Item *create_func_release_lock(Item* a)
{
current_thd->safe_to_cache_query=0;
current_thd->lex.safe_to_cache_query=0;
return new Item_func_release_lock(a);
}
......@@ -416,13 +416,13 @@ Item *create_func_year(Item* a)
Item *create_load_file(Item* a)
{
current_thd->safe_to_cache_query=0;
current_thd->lex.safe_to_cache_query=0;
return new Item_load_file(a);
}
Item *create_wait_for_master_pos(Item* a, Item* b)
{
current_thd->safe_to_cache_query=0;
current_thd->lex.safe_to_cache_query=0;
return new Item_master_pos_wait(a, b);
}
......@@ -443,7 +443,7 @@ Item *create_func_cast(Item *a, Item_cast cast_type)
Item *create_func_is_free_lock(Item* a)
{
current_thd->safe_to_cache_query=0;
current_thd->lex.safe_to_cache_query=0;
return new Item_func_is_free_lock(a);
}
......
......@@ -2470,7 +2470,7 @@ Item *get_system_var(enum_var_type var_type, LEX_STRING name)
}
if (!(item=var->item(thd, var_type)))
return 0; // Impossible
thd->safe_to_cache_query=0;
thd->lex.safe_to_cache_query=0;
buff[0]='@';
buff[1]='@';
pos=buff+2;
......@@ -2496,7 +2496,7 @@ Item *get_system_var(enum_var_type var_type, const char *var_name, uint length,
DBUG_ASSERT(var != 0);
if (!(item=var->item(thd, var_type)))
return 0; // Impossible
thd->safe_to_cache_query=0;
thd->lex.safe_to_cache_query=0;
item->set_name(item_name); // Will use original name
return item;
}
......
......@@ -289,7 +289,7 @@ TODO list:
if (thd->temp_tables || global_merge_table_count)
- Another option would be to set thd->safe_to_cache_query to 0
- Another option would be to set thd->lex.safe_to_cache_query to 0
in 'get_lock_data' if any of the tables was a tmp table or a
MRG_ISAM table.
(This could be done with almost no speed penalty)
......@@ -900,7 +900,7 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length)
/* Check that we haven't forgot to reset the query cache variables */
DBUG_ASSERT(thd->net.query_cache_query == 0);
if (!thd->safe_to_cache_query)
if (!thd->lex.safe_to_cache_query)
{
DBUG_PRINT("qcache", ("SELECT is non-cacheable"));
goto err;
......@@ -994,7 +994,7 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length)
table_list.db, table_list.alias));
refused++; // This is actually a hit
STRUCT_UNLOCK(&structure_guard_mutex);
thd->safe_to_cache_query=0; // Don't try to cache this
thd->lex.safe_to_cache_query=0; // Don't try to cache this
BLOCK_UNLOCK_RD(query_block);
DBUG_RETURN(-1); // Privilege error
}
......@@ -1003,7 +1003,7 @@ Query_cache::send_result_to_client(THD *thd, char *sql, uint query_length)
DBUG_PRINT("qcache", ("Need to check column privileges for %s.%s",
table_list.db, table_list.alias));
BLOCK_UNLOCK_RD(query_block);
thd->safe_to_cache_query=0; // Don't try to cache this
thd->lex.safe_to_cache_query=0; // Don't try to cache this
goto err_unlock; // Parse query
}
}
......@@ -2457,7 +2457,7 @@ TABLE_COUNTER_TYPE Query_cache::is_cacheable(THD *thd, uint32 query_len,
(thd->variables.query_cache_type == 1 ||
(thd->variables.query_cache_type == 2 && (lex->select_lex.options &
OPTION_TO_QUERY_CACHE))) &&
thd->safe_to_cache_query)
lex->safe_to_cache_query)
{
my_bool has_transactions = 0;
DBUG_PRINT("qcache", ("options %lx %lx, type %u",
......
......@@ -87,7 +87,7 @@ THD::THD():user_time(0), fatal_error(0),
host=user=priv_user=db=query=ip=0;
host_or_ip="unknown ip";
locked=killed=count_cuted_fields=some_tables_deleted=no_errors=password=
query_start_used=safe_to_cache_query=prepare_command=0;
query_start_used=prepare_command=0;
db_length=query_length=col_access=0;
query_error=0;
next_insert_id=last_insert_id=0;
......
......@@ -507,7 +507,6 @@ class THD :public ilink {
bool query_start_used,last_insert_id_used,insert_id_used,rand_used;
bool system_thread,in_lock_tables,global_read_lock;
bool query_error, bootstrap, cleanup_done;
bool safe_to_cache_query;
bool volatile killed;
bool prepare_command;
Item_param *params; // Pointer to array of params
......
......@@ -154,6 +154,7 @@ LEX *lex_start(THD *thd, uchar *buf,uint length)
lex->ignore_space=test(thd->sql_mode & MODE_IGNORE_SPACE);
lex->slave_thd_opt=0;
lex->sql_command=SQLCOM_END;
lex->safe_to_cache_query= 1;
bzero(&lex->mi,sizeof(lex->mi));
return lex;
}
......@@ -182,7 +183,7 @@ static int find_keyword(LEX *lex, uint len, bool function)
udf_func *udf;
if (function && using_udf_functions && (udf=find_udf((char*) tok, len)))
{
lex->thd->safe_to_cache_query=0;
lex->safe_to_cache_query=0;
lex->yylval->udf=udf;
switch (udf->returns) {
case STRING_RESULT:
......
......@@ -440,6 +440,7 @@ typedef struct st_lex
bool drop_primary, drop_if_exists, drop_temporary, local_file;
bool in_comment, ignore_space, verbose, simple_alter;
bool derived_tables, describe, olap;
bool safe_to_cache_query;
uint slave_thd_opt;
CHARSET_INFO *charset;
char *help_arg;
......
......@@ -2875,7 +2875,6 @@ mysql_init_query(THD *thd)
thd->last_insert_id_used= thd->query_start_used= thd->insert_id_used=0;
thd->sent_row_count= thd->examined_row_count= 0;
thd->fatal_error= thd->rand_used= 0;
thd->safe_to_cache_query= 1;
thd->possible_loops= 0;
DBUG_VOID_RETURN;
}
......
......@@ -606,9 +606,9 @@ static bool parse_prepare_query(PREP_STMT *stmt,
mysql_log.write(thd,COM_PREPARE,"%s",packet);
mysql_init_query(thd);
thd->prepare_command=true;
thd->safe_to_cache_query= 0;
LEX *lex=lex_start(thd, (uchar*) packet, length);
lex->safe_to_cache_query= 0;
if (!yyparse() && !thd->fatal_error)
error= send_prepare_results(stmt);
lex_end(lex);
......
......@@ -1676,7 +1676,7 @@ select_option:
YYABORT;
Select->options|= OPTION_FOUND_ROWS;
}
| SQL_NO_CACHE_SYM { current_thd->safe_to_cache_query=0; }
| SQL_NO_CACHE_SYM { Lex->safe_to_cache_query=0; }
| SQL_CACHE_SYM { Select->options|= OPTION_TO_QUERY_CACHE; }
| ALL {}
;
......@@ -1689,7 +1689,7 @@ select_lock_type:
if (check_simple_select())
YYABORT;
lex->lock_option= TL_WRITE;
lex->thd->safe_to_cache_query=0;
lex->safe_to_cache_query=0;
}
| LOCK_SYM IN_SYM SHARE_SYM MODE_SYM
{
......@@ -1697,7 +1697,7 @@ select_lock_type:
if (check_simple_select())
YYABORT;
lex->lock_option= TL_READ_WITH_SHARED_LOCKS;
lex->thd->safe_to_cache_query=0;
lex->safe_to_cache_query=0;
}
;
......@@ -1885,12 +1885,12 @@ simple_expr:
| '@' ident_or_text SET_VAR expr
{
$$= new Item_func_set_user_var($2,$4);
current_thd->safe_to_cache_query=0;
Lex->safe_to_cache_query=0;
}
| '@' ident_or_text
{
$$= new Item_func_get_user_var($2);
current_thd->safe_to_cache_query=0;
Lex->safe_to_cache_query=0;
}
| '@' '@' opt_var_ident_type ident_or_text
{
......@@ -1944,13 +1944,13 @@ simple_expr:
| CONCAT_WS '(' expr ',' expr_list ')'
{ $$= new Item_func_concat_ws($3, *$5); }
| CURDATE optional_braces
{ $$= new Item_func_curdate(); current_thd->safe_to_cache_query=0; }
{ $$= new Item_func_curdate(); Lex->safe_to_cache_query=0; }
| CURTIME optional_braces
{ $$= new Item_func_curtime(); current_thd->safe_to_cache_query=0; }
{ $$= new Item_func_curtime(); Lex->safe_to_cache_query=0; }
| CURTIME '(' expr ')'
{
$$= new Item_func_curtime($3);
current_thd->safe_to_cache_query=0;
Lex->safe_to_cache_query=0;
}
| DATE_ADD_INTERVAL '(' expr ',' INTERVAL_SYM expr interval ')'
{ $$= new Item_date_add_interval($3,$6,$7,0); }
......@@ -1959,7 +1959,7 @@ simple_expr:
| DATABASE '(' ')'
{
$$= new Item_func_database();
current_thd->safe_to_cache_query=0;
Lex->safe_to_cache_query=0;
}
| ELT_FUNC '(' expr ',' expr_list ')'
{ $$= new Item_func_elt($3, *$5); }
......@@ -1968,7 +1968,7 @@ simple_expr:
| ENCRYPT '(' expr ')'
{
$$= new Item_func_encrypt($3);
current_thd->safe_to_cache_query=0;
Lex->safe_to_cache_query=0;
}
| ENCRYPT '(' expr ',' expr ')' { $$= new Item_func_encrypt($3,$5); }
| DECODE_SYM '(' expr ',' TEXT_STRING ')'
......@@ -2028,7 +2028,7 @@ simple_expr:
| LAST_INSERT_ID '(' expr ')'
{
$$= new Item_func_set_last_insert_id($3);
current_thd->safe_to_cache_query=0;
Lex->safe_to_cache_query=0;
}
| LEFT '(' expr ',' expr ')'
{ $$= new Item_func_left($3,$5); }
......@@ -2083,9 +2083,9 @@ simple_expr:
{ $$= new Item_func_spatial_collection(* $3,
Geometry::wkbMultiPolygon, Geometry::wkbPolygon ); }
| NOW_SYM optional_braces
{ $$= new Item_func_now(); current_thd->safe_to_cache_query=0;}
{ $$= new Item_func_now(); Lex->safe_to_cache_query=0;}
| NOW_SYM '(' expr ')'
{ $$= new Item_func_now($3); current_thd->safe_to_cache_query=0;}
{ $$= new Item_func_now($3); Lex->safe_to_cache_query=0;}
| PASSWORD '(' expr ')'
{
$$= new Item_func_password($3);
......@@ -2104,9 +2104,9 @@ simple_expr:
| POSITION_SYM '(' no_in_expr IN_SYM expr ')'
{ $$ = new Item_func_locate($5,$3); }
| RAND '(' expr ')'
{ $$= new Item_func_rand($3); current_thd->safe_to_cache_query=0;}
{ $$= new Item_func_rand($3); Lex->safe_to_cache_query=0;}
| RAND '(' ')'
{ $$= new Item_func_rand(); current_thd->safe_to_cache_query=0;}
{ $$= new Item_func_rand(); Lex->safe_to_cache_query=0;}
| REPLACE '(' expr ',' expr ',' expr ')'
{ $$= new Item_func_replace($3,$5,$7); }
| RIGHT '(' expr ',' expr ')'
......@@ -2189,12 +2189,12 @@ simple_expr:
| UNIX_TIMESTAMP '(' ')'
{
$$= new Item_func_unix_timestamp();
current_thd->safe_to_cache_query=0;
Lex->safe_to_cache_query=0;
}
| UNIX_TIMESTAMP '(' expr ')'
{ $$= new Item_func_unix_timestamp($3); }
| USER '(' ')'
{ $$= new Item_func_user(); current_thd->safe_to_cache_query=0; }
{ $$= new Item_func_user(); Lex->safe_to_cache_query=0; }
| WEEK_SYM '(' expr ')'
{ $$= new Item_func_week($3,new Item_int((char*) "0",0,1)); }
| WEEK_SYM '(' expr ',' expr ')'
......@@ -2208,7 +2208,7 @@ simple_expr:
| BENCHMARK_SYM '(' ULONG_NUM ',' expr ')'
{
$$=new Item_func_benchmark($3,$5);
current_thd->safe_to_cache_query=0;
Lex->safe_to_cache_query=0;
}
| EXTRACT_SYM '(' interval FROM expr ')'
{ $$=new Item_extract( $3, $5); };
......@@ -2667,7 +2667,7 @@ procedure_clause:
lex->proc_list.next= (byte**) &lex->proc_list.first;
if (add_proc_to_list(new Item_field(NULL,NULL,$2.str)))
YYABORT;
current_thd->safe_to_cache_query=0;
Lex->safe_to_cache_query=0;
}
'(' procedure_list ')';
......@@ -2739,7 +2739,7 @@ opt_into:
}
| INTO select_var_list_init
{
current_thd->safe_to_cache_query=0;
Lex->safe_to_cache_query=0;
}
;
......
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