Commit e294751c authored by bell@sanja.is.com.ua's avatar bell@sanja.is.com.ua

fixed bug in determinating uncacheable queries

new fatal_error interface to assign is_fatal_error and ne.report_error
commant about Item_row
parent 2f04313d
......@@ -988,3 +988,12 @@ t1 CREATE TABLE `t1` (
`a` bigint(17) NOT NULL default '0'
) TYPE=MyISAM CHARSET=latin1
drop table t1;
create table t1 (a int);
insert into t1 values (1), (2), (3);
explain select a,(select (select rand() from t1 limit 1) from t1 limit 1)
from t1;
id select_type table type possible_keys key key_len ref rows Extra
1 PRIMARY t1 ALL NULL NULL NULL NULL 3
2 UNCACHEABLE SUBSELECT t1 ALL NULL NULL NULL NULL 3
3 UNCACHEABLE SUBSELECT t1 ALL NULL NULL NULL NULL 3
drop table t1;
......@@ -575,3 +575,9 @@ drop table t1;
CREATE TABLE t1 SELECT (SELECT 1 as a UNION SELECT 1+1 limit 1,1) as a;
SHOW CREATE TABLE t1;
drop table t1;
create table t1 (a int);
insert into t1 values (1), (2), (3);
explain select a,(select (select rand() from t1 limit 1) from t1 limit 1)
from t1;
drop table t1;
......@@ -544,7 +544,7 @@ bool Item_asterisk_remover::fix_fields(THD *thd,
tb->used_fields= tb->fields;
}
else
thd->fatal_error= 1; // can't create Item => out of memory
thd->fatal_error(); // can't create Item => out of memory
}
else
my_error(ER_CARDINALITY_COL, MYF(0), 1);
......@@ -560,7 +560,7 @@ bool Item_asterisk_remover::fix_fields(THD *thd,
else
res= item->fix_fields(thd, list, &item);
else
thd->fatal_error= 1; // no item given => out of memory
thd->fatal_error(); // no item given => out of memory
DBUG_RETURN(res);
}
......
......@@ -2010,7 +2010,7 @@ void Item_func_set_user_var::update_hash(void *ptr, uint length,
return;
err:
current_thd->fatal_error=1; // Probably end of memory
current_thd->fatal_error(); // Probably end of memory
null_value=1;
return;
}
......@@ -2038,7 +2038,7 @@ Item_func_set_user_var::update()
DBUG_ASSERT(0);
break;
}
return current_thd->fatal_error;
return current_thd->is_fatal_error;
}
......
......@@ -16,6 +16,15 @@
#include "mysql_priv.h"
/*
Row items used for comparing rows and IN operations on rows:
(a, b, c) > (10, 10, 30)
(a, b, c) = (select c, d, e, from t1 where x=12)
(a, b, c) IN ((1,2,2), (3,4,5), (6,7,8)
(a, b, c) IN (select c, d, e, from t1)
*/
Item_row::Item_row(List<Item> &arg):
Item(), used_tables_cache(0), array_holder(1), const_item_cache(1)
{
......
......@@ -642,11 +642,8 @@ subselect_single_select_engine::subselect_single_select_engine(THD *thd,
select_lex->options&= ~OPTION_FOUND_ROWS;
join= new JOIN(thd, select_lex->item_list, select_lex->options, result);
if (!join || !result)
{
//out of memory
thd->fatal_error= 1;
my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0));
}
thd->fatal_error();
unit->item= item;
this->select_lex= select_lex;
}
......@@ -659,11 +656,8 @@ subselect_union_engine::subselect_union_engine(THD *thd,
{
unit= u;
if (!result)
{
//out of memory
thd->fatal_error= 1;
my_message(ER_OUT_OF_RESOURCES, ER(ER_OUT_OF_RESOURCES), MYF(0));
}
thd->fatal_error();
unit->item= item;
}
......@@ -805,7 +799,7 @@ int subselect_single_select_engine::exec()
join->thd->lex.current_select= save_select;
executed= 1;
join->thd->where= save_where;
DBUG_RETURN(join->error||thd->fatal_error);
DBUG_RETURN(join->error||thd->is_fatal_error);
}
join->thd->where= save_where;
DBUG_RETURN(0);
......
......@@ -953,7 +953,7 @@ int Query_log_event::exec_event(struct st_relay_log_info* rli)
thd->variables.convert_set = 0;
close_thread_tables(thd);
if (thd->query_error || thd->fatal_error)
if (thd->query_error || thd->is_fatal_error)
{
slave_print_error(rli,actual_error, "error '%s' on query '%s'",
actual_error ? thd->net.last_error :
......@@ -1624,7 +1624,7 @@ int Load_log_event::exec_event(NET* net, struct st_relay_log_info* rli,
}
free_root(&thd->mem_root,0);
if (thd->fatal_error)
if (thd->is_fatal_error)
{
sql_print_error("Slave: Fatal error running LOAD DATA INFILE ");
return 1;
......
......@@ -2527,7 +2527,7 @@ static int bootstrap(FILE *file)
DBUG_PRINT("quit",("One thread died (count=%u)",thread_count));
}
(void) pthread_mutex_unlock(&LOCK_thread_count);
error= thd->fatal_error;
error= thd->is_fatal_error;
net_end(&thd->net);
thd->cleanup();
delete thd;
......
......@@ -107,7 +107,7 @@ void send_error(THD *thd, uint sql_errno, const char *err)
}
VOID(net_write_command(net,(uchar) 255, "", 0, (char*) err,length));
#endif /* EMBEDDED_LIBRARY*/
thd->fatal_error=0; // Error message is given
thd->is_fatal_error=0; // Error message is given
thd->net.report_error= 0;
DBUG_VOID_RETURN;
}
......@@ -217,7 +217,7 @@ net_printf(THD *thd, uint errcode, ...)
This may also happen when we get an error from a slave thread
*/
fprintf(stderr,"ERROR: %d %s\n",errcode,text_pos);
thd->fatal_error=1;
thd->fatal_error();
}
DBUG_VOID_RETURN;
}
......@@ -232,7 +232,7 @@ net_printf(THD *thd, uint errcode, ...)
net->last_errno= errcode;
strmake(net->last_error, text_pos, length);
#endif
thd->fatal_error=0; // Error message is given
thd->is_fatal_error=0; // Error message is given
DBUG_VOID_RETURN;
}
......
......@@ -1962,7 +1962,7 @@ int setup_fields(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables,
item->split_sum_func(ref_pointer_array, *sum_func_list);
thd->used_tables|=item->used_tables();
}
DBUG_RETURN(test(thd->fatal_error || thd->net.report_error));
DBUG_RETURN(test(thd->net.report_error));
}
/*
......@@ -2182,7 +2182,7 @@ int setup_conds(THD *thd,TABLE_LIST *tables,COND **conds)
table->on_expr=and_conds(table->on_expr,cond_and);
}
}
DBUG_RETURN(test(thd->fatal_error || thd->net.report_error));
DBUG_RETURN(test(thd->net.report_error));
}
......
......@@ -77,7 +77,7 @@ extern "C" void free_user_var(user_var_entry *entry)
** Thread specific functions
****************************************************************************/
THD::THD():user_time(0), fatal_error(0),
THD::THD():user_time(0), is_fatal_error(0),
last_insert_id_used(0),
insert_id_used(0), rand_used(0), in_lock_tables(0),
global_read_lock(0), bootstrap(0)
......
......@@ -530,7 +530,7 @@ class THD :public ilink {
uint8 query_cache_type; // type of query cache processing
bool slave_thread;
bool set_query_id,locked,count_cuted_fields,some_tables_deleted;
bool no_errors, allow_sum_func, password, fatal_error;
bool no_errors, allow_sum_func, password, is_fatal_error;
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;
......@@ -660,6 +660,11 @@ class THD :public ilink {
#else
void clear_error();
#endif
inline void fatal_error()
{
is_fatal_error= 1;
net.report_error= 1;
}
};
/*
......
......@@ -301,7 +301,7 @@ multi_delete::initialize_tables(JOIN *join)
MEM_STRIP_BUF_SIZE);
}
init_ftfuncs(thd, thd->lex.current_select->select_lex(), 1);
DBUG_RETURN(thd->fatal_error != 0);
DBUG_RETURN(thd->is_fatal_error != 0);
}
......
......@@ -151,7 +151,7 @@ int mysql_insert(THD *thd,TABLE_LIST *table_list,
DBUG_RETURN(-1);
}
}
if ((table= delayed_get_table(thd,table_list)) && !thd->fatal_error)
if ((table= delayed_get_table(thd,table_list)) && !thd->is_fatal_error)
if (table_list->next && table)
res= open_and_lock_tables(thd, table_list->next);
else
......@@ -685,7 +685,7 @@ static TABLE *delayed_get_table(THD *thd,TABLE_LIST *table_list)
{
if (!(tmp=new delayed_insert()))
{
thd->fatal_error=1;
thd->fatal_error();
my_error(ER_OUTOFMEMORY,MYF(0),sizeof(delayed_insert));
pthread_mutex_unlock(&LOCK_delayed_create);
DBUG_RETURN(0);
......@@ -697,7 +697,7 @@ static TABLE *delayed_get_table(THD *thd,TABLE_LIST *table_list)
!(tmp->thd.query=my_strdup(table_list->real_name,MYF(MY_WME))))
{
delete tmp;
thd->fatal_error=1;
thd->fatal_error();
my_error(ER_OUT_OF_RESOURCES,MYF(0));
pthread_mutex_unlock(&LOCK_delayed_create);
DBUG_RETURN(0);
......@@ -716,7 +716,7 @@ static TABLE *delayed_get_table(THD *thd,TABLE_LIST *table_list)
pthread_mutex_unlock(&tmp->mutex);
tmp->unlock();
delete tmp;
thd->fatal_error=1;
thd->fatal_error();
pthread_mutex_unlock(&LOCK_delayed_create);
net_printf(thd,ER_CANT_CREATE_THREAD,error);
DBUG_RETURN(0);
......@@ -732,10 +732,10 @@ static TABLE *delayed_get_table(THD *thd,TABLE_LIST *table_list)
thd->proc_info="got old table";
if (tmp->thd.killed)
{
if (tmp->thd.fatal_error)
if (tmp->thd.is_fatal_error)
{
/* Copy error message and abort */
thd->fatal_error=1;
thd->fatal_error();
strmov(thd->net.last_error,tmp->thd.net.last_error);
thd->net.last_errno=tmp->thd.net.last_errno;
}
......@@ -759,8 +759,8 @@ static TABLE *delayed_get_table(THD *thd,TABLE_LIST *table_list)
tmp->unlock();
if (table)
thd->di=tmp;
else if (tmp->thd.fatal_error)
thd->fatal_error=1;
else if (tmp->thd.is_fatal_error)
thd->fatal_error();
DBUG_RETURN((table_list->table=table));
}
......@@ -988,7 +988,7 @@ extern "C" pthread_handler_decl(handle_delayed_insert,arg)
DBUG_ENTER("handle_delayed_insert");
if (init_thr_lock() || thd->store_globals())
{
thd->fatal_error=1;
thd->fatal_error();
strmov(thd->net.last_error,ER(thd->net.last_errno=ER_OUT_OF_RESOURCES));
goto end;
}
......@@ -1002,12 +1002,12 @@ extern "C" pthread_handler_decl(handle_delayed_insert,arg)
if (!(di->table=open_ltable(thd,&di->table_list,TL_WRITE_DELAYED)))
{
thd->fatal_error=1; // Abort waiting inserts
thd->fatal_error(); // Abort waiting inserts
goto end;
}
if (di->table->file->has_transactions())
{
thd->fatal_error=1;
thd->fatal_error();
my_error(ER_ILLEGAL_HA, MYF(0), di->table_list.real_name);
goto end;
}
......
......@@ -480,8 +480,18 @@ typedef struct st_lex
inline void uncacheable()
{
safe_to_cache_query= 0;
current_select->uncacheable =
current_select->master_unit()->uncacheable= 1;
/*
There are no sense to mark select_lex and union fields of LEX,
but we should merk all subselects as uncacheable from current till
most upper
*/
for (SELECT_LEX_NODE *sl= current_select;
sl != &select_lex;
sl= sl->outer_select())
{
sl->uncacheable = sl->master_unit()->uncacheable= 1;
}
}
} LEX;
......
......@@ -839,7 +839,7 @@ extern "C" pthread_handler_decl(handle_bootstrap,arg)
if (my_thread_init() || thd->store_globals())
{
close_connection(&thd->net,ER_OUT_OF_RESOURCES);
thd->fatal_error=1;
thd->fatal_error();
goto end;
}
DBUG_ENTER("handle_bootstrap");
......@@ -886,7 +886,7 @@ extern "C" pthread_handler_decl(handle_bootstrap,arg)
}
mysql_parse(thd,thd->query,length);
close_thread_tables(thd); // Free tables
if (thd->fatal_error)
if (thd->is_fatal_error)
break;
free_root(&thd->mem_root,MYF(MY_KEEP_PREALLOC));
free_root(&thd->transaction.mem_root,MYF(MY_KEEP_PREALLOC));
......@@ -1206,7 +1206,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
DBUG_PRINT("query",("%-.4096s",thd->query));
mysql_parse(thd,thd->query, thd->query_length);
while (!thd->fatal_error && thd->lex.found_colon)
while (!thd->is_fatal_error && thd->lex.found_colon)
{
char *packet= thd->lex.found_colon;
/*
......@@ -1442,7 +1442,7 @@ bool dispatch_command(enum enum_server_command command, THD *thd,
close_thread_tables(thd); /* Free tables */
}
if (thd->fatal_error)
if (thd->is_fatal_error)
send_error(thd,0); // End of memory ?
time_t start_of_query=thd->start_time;
......@@ -2375,8 +2375,8 @@ mysql_execute_command(THD *thd)
}
}
fix_tables_pointers(lex->all_selects_list);
if (!thd->fatal_error && (result= new multi_delete(thd,aux_tables,
table_count)))
if (!thd->is_fatal_error && (result= new multi_delete(thd,aux_tables,
table_count)))
{
res= mysql_select(thd, &select_lex->ref_pointer_array,
select_lex->get_table_list(),
......@@ -3085,7 +3085,7 @@ bool check_stack_overrun(THD *thd,char *buf __attribute__((unused)))
{
sprintf(errbuff[0],ER(ER_STACK_OVERRUN),stack_used,thread_stack);
my_message(ER_STACK_OVERRUN,errbuff[0],MYF(0));
thd->fatal_error=1;
thd->fatal_error();
return 1;
}
return 0;
......@@ -3155,7 +3155,7 @@ mysql_init_query(THD *thd)
thd->total_warn_count=0; // Warnings for this query
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->is_fatal_error= thd->rand_used= 0;
thd->server_status &= ~SERVER_MORE_RESULTS_EXISTS;
DBUG_VOID_RETURN;
}
......@@ -3261,7 +3261,7 @@ mysql_parse(THD *thd, char *inBuf, uint length)
if (query_cache_send_result_to_client(thd, inBuf, length) <= 0)
{
LEX *lex=lex_start(thd, (uchar*) inBuf, length);
if (!yyparse((void *)thd) && ! thd->fatal_error)
if (!yyparse((void *)thd) && ! thd->is_fatal_error)
{
if (mqh_used && thd->user_connect &&
check_mqh(thd, lex->sql_command))
......@@ -3284,7 +3284,7 @@ mysql_parse(THD *thd, char *inBuf, uint length)
else
{
DBUG_PRINT("info",("Command aborted. Fatal_error: %d",
thd->fatal_error));
thd->is_fatal_error));
#ifndef EMBEDDED_LIBRARY /* TODO query cache in embedded library*/
query_cache_abort(&thd->net);
#endif
......
......@@ -675,7 +675,7 @@ static bool parse_prepare_query(PREP_STMT *stmt,
LEX *lex=lex_start(thd, (uchar*) packet, length);
lex->safe_to_cache_query= 0;
if (!yyparse((void *)thd) && !thd->fatal_error)
if (!yyparse((void *)thd) && !thd->is_fatal_error)
error= send_prepare_results(stmt);
lex_end(lex);
DBUG_RETURN(error);
......
......@@ -443,11 +443,11 @@ JOIN::optimize()
#endif
conds= optimize_cond(conds,&cond_value);
if (thd->fatal_error || thd->net.report_error)
if (thd->net.report_error)
{
// quick abort
delete procedure;
error= thd->fatal_error ? -1 : 1;
error= thd->is_fatal_error ? -1 : 1;
DBUG_RETURN(error);
}
......@@ -483,7 +483,7 @@ JOIN::optimize()
/* Calculate how to do the join */
thd->proc_info= "statistics";
if (make_join_statistics(this, tables_list, conds, &keyuse) ||
thd->fatal_error)
thd->is_fatal_error)
DBUG_RETURN(1);
thd->proc_info= "preparing";
......@@ -593,7 +593,7 @@ JOIN::optimize()
else
group_list= 0;
}
else if (thd->fatal_error) // End of memory
else if (thd->is_fatal_error) // End of memory
DBUG_RETURN(1);
}
group_list= remove_const(this, group_list, conds, &simple_group);
......@@ -1160,7 +1160,7 @@ JOIN::exec()
memcpy(ref_pointer_array, items3, ref_pointer_array_size);
if (make_sum_func_list(curr_join, *curr_all_fields) ||
thd->fatal_error)
thd->is_fatal_error)
DBUG_VOID_RETURN;
}
if (curr_join->group_list || curr_join->order)
......@@ -2745,7 +2745,7 @@ static bool create_ref_for_key(JOIN *join, JOIN_TAB *j, KEYUSE *org_keyuse,
(char*) key_buff : 0,
keyinfo->key_part[i].length,
keyuse->val);
if (thd->fatal_error)
if (thd->is_fatal_error)
{
return TRUE;
}
......@@ -3989,7 +3989,7 @@ Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
return 0;
}
}
thd->fatal_error=1;
thd->fatal_error();
return 0; // Error
}
case Item::FIELD_ITEM:
......@@ -4243,7 +4243,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
not_all_columns || group !=0);
if (!new_field)
{
if (thd->fatal_error)
if (thd->is_fatal_error)
goto err; // Got OOM
continue; // Some kindf of const item
}
......@@ -4519,7 +4519,7 @@ create_tmp_table(THD *thd,TMP_TABLE_PARAM *param,List<Item> &fields,
0 : FIELDFLAG_BINARY;
}
}
if (thd->fatal_error) // If end of memory
if (thd->is_fatal_error) // If end of memory
goto err; /* purecov: inspected */
table->db_record_offset=1;
if (table->db_type == DB_TYPE_MYISAM)
......@@ -7081,7 +7081,7 @@ find_order_in_list(THD *thd, Item **ref_pointer_array,
order->in_field_list=0;
Item *it= *order->item;
if (it->fix_fields(thd, tables, order->item) || it->check_cols(1) ||
thd->fatal_error)
thd->is_fatal_error)
return 1; // Wrong field
uint el= all_fields.elements;
all_fields.push_front(it); // Add new field to field list
......@@ -7675,7 +7675,7 @@ change_refs_to_tmp_fields(THD *thd, Item **ref_pointer_array,
itr++;
itr.sublist(new_list1, elements);
return thd->fatal_error;
return thd->is_fatal_error;
}
......@@ -7771,7 +7771,7 @@ static bool add_ref_to_table_cond(THD *thd, JOIN_TAB *join_tab)
Item *value=join_tab->ref.items[i];
cond->add(new Item_func_equal(new Item_field(field),value));
}
if (thd->fatal_error)
if (thd->is_fatal_error)
DBUG_RETURN(TRUE);
/*
......
......@@ -114,7 +114,7 @@ int mysqld_show_open_tables(THD *thd,const char *wild)
if (protocol->send_fields(&field_list,1))
DBUG_RETURN(1);
if (!(open_list=list_open_tables(thd,wild)) && thd->fatal_error)
if (!(open_list=list_open_tables(thd,wild)) && thd->is_fatal_error)
DBUG_RETURN(-1);
for (; open_list ; open_list=open_list->next)
......
......@@ -203,7 +203,7 @@ int st_select_lex_unit::prepare(THD *thd, select_result *result,
(ORDER*) NULL,
sl, this, 0, tables_OK);
tables_OK= 0;
if (res | thd->fatal_error)
if (res | thd->is_fatal_error)
goto err;
}
item_list.empty();
......@@ -220,7 +220,7 @@ int st_select_lex_unit::prepare(THD *thd, select_result *result,
}
}
DBUG_RETURN(res | thd->fatal_error);
DBUG_RETURN(res | thd->is_fatal_error);
err:
thd->lex.current_select= lex_select_save;
DBUG_RETURN(-1);
......@@ -293,7 +293,7 @@ int st_select_lex_unit::exec()
thd->lex.select_lex.ftfunc_list= &empty_list;
#endif
if (!thd->fatal_error) // Check if EOM
if (!thd->is_fatal_error) // Check if EOM
{
SELECT_LEX *sl=thd->lex.current_select->master_unit()->first_select();
offset_limit_cnt= (sl->braces) ? global_parameters->offset_limit : 0;
......
......@@ -514,14 +514,14 @@ int multi_update::prepare(List<Item> &not_used_values, SELECT_LEX_UNIT *unit)
table_count);
values_for_table= (List_item **) thd->alloc(sizeof(List_item *) *
table_count);
if (thd->fatal_error)
if (thd->is_fatal_error)
DBUG_RETURN(1);
for (i=0 ; i < table_count ; i++)
{
fields_for_table[i]= new List_item;
values_for_table[i]= new List_item;
}
if (thd->fatal_error)
if (thd->is_fatal_error)
DBUG_RETURN(1);
/* Split fields into fields_for_table[] and values_by_table[] */
......@@ -534,7 +534,7 @@ int multi_update::prepare(List<Item> &not_used_values, SELECT_LEX_UNIT *unit)
fields_for_table[offset]->push_back(item);
values_for_table[offset]->push_back(value);
}
if (thd->fatal_error)
if (thd->is_fatal_error)
DBUG_RETURN(1);
/* Allocate copy fields */
......@@ -542,7 +542,7 @@ int multi_update::prepare(List<Item> &not_used_values, SELECT_LEX_UNIT *unit)
for (i=0 ; i < table_count ; i++)
set_if_bigger(max_fields, fields_for_table[i]->elements);
copy_field= new Copy_field[max_fields];
DBUG_RETURN(thd->fatal_error != 0);
DBUG_RETURN(thd->is_fatal_error != 0);
}
......
......@@ -24,7 +24,7 @@ extern "C" {
{
THD *thd=current_thd;
if (thd) // QQ; To be removed
thd->fatal_error=1; /* purecov: inspected */
thd->fatal_error(); /* purecov: inspected */
sql_print_error(ER(ER_OUT_OF_RESOURCES));
}
}
......
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