diff options
author | unknown <bell@sanja.is.com.ua> | 2002-10-26 20:18:37 +0300 |
---|---|---|
committer | unknown <bell@sanja.is.com.ua> | 2002-10-26 20:18:37 +0300 |
commit | c37bbf06bb452899e5946a75282000de0699b335 (patch) | |
tree | 70cb1e5353df14c2d420c54118339b26830d0bbe /sql | |
parent | 9e82940496fcacb66bd3a4132fab048eb8e7ea7d (diff) | |
download | mariadb-git-c37bbf06bb452899e5946a75282000de0699b335.tar.gz |
code cleanup
fixed subselect error handling bug
fixed subselect UNION ALL bug
fixed thd->lex.select restoring
explain UNION subselect bug
mysql-test/r/subselect.result:
test for:
subselect UNION ALL bug
subselect error handling bug
explain UNION subselect bug
mysql-test/t/subselect.test:
test for:
subselect UNION ALL bug
subselect error handling bug
explain UNION subselect bug
sql/sql_lex.cc:
fixed subselect UNION ALL bug
sql/sql_lex.h:
fixed subselect UNION ALL bug
sql/sql_parse.cc:
fixed subselect UNION ALL bug
sql/sql_select.cc:
fixed subselect error handling bug
fixed explain UNION subselect bug
sql/sql_union.cc:
fixed thd->lex.select restoring
code cleanup
fixed subselect error handling bug
fixed subselect UNION ALL bug
sql/sql_yacc.yy:
fixed subselect UNION ALL bug
Diffstat (limited to 'sql')
-rw-r--r-- | sql/sql_lex.cc | 1 | ||||
-rw-r--r-- | sql/sql_lex.h | 3 | ||||
-rw-r--r-- | sql/sql_parse.cc | 1 | ||||
-rw-r--r-- | sql/sql_select.cc | 26 | ||||
-rw-r--r-- | sql/sql_union.cc | 55 | ||||
-rw-r--r-- | sql/sql_yacc.yy | 2 |
6 files changed, 36 insertions, 52 deletions
diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 9f09afc78a6..b68316a1e4a 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -944,6 +944,7 @@ void st_select_lex_unit::init_query() global_parameters= this; select_limit_cnt= HA_POS_ERROR; offset_limit_cnt= 0; + union_option= 0; prepared= optimized= 0; item= 0; } diff --git a/sql/sql_lex.h b/sql/sql_lex.h index de57e9f77a8..070eecb1797 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -240,6 +240,7 @@ public: bool depended; /* depended from outer select subselect */ /* not NULL if union used in subselect, point to subselect item */ Item_subselect *item; + uint union_option; void init_query(); bool create_total_list(THD *thd, st_lex *lex, TABLE_LIST **result); @@ -373,7 +374,7 @@ typedef struct st_lex enum ha_rkey_function ha_rkey_mode; enum enum_enable_or_disable alter_keys_onoff; enum enum_var_type option_type; - uint grant, grant_tot_col, which_columns, union_option; + uint grant, grant_tot_col, which_columns; uint fk_delete_opt, fk_update_opt, fk_match_option; uint param_count; bool drop_primary, drop_if_exists, local_file, olap; diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index ae32cd078f7..fc9838f57b1 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -2904,7 +2904,6 @@ mysql_init_query(THD *thd) thd->select_number= thd->lex.select_lex.select_number= 1; thd->lex.value_list.empty(); thd->free_list= 0; - thd->lex.union_option= 0; thd->lex.select= &thd->lex.select_lex; thd->lex.olap=thd->lex.describe=0; thd->lex.select->olap= UNSPECIFIED_OLAP_TYPE; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index eebce401aed..b981ae329cd 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -371,7 +371,7 @@ JOIN::optimize() #endif conds=optimize_cond(conds,&cond_value); - if (thd->fatal_error) // Out of memory + if (thd->fatal_error || thd->net.report_error) { delete procedure; error = 0; @@ -7251,16 +7251,18 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order, select_result *result=join->result; Item *item_null= new Item_null(); DBUG_ENTER("select_describe"); - + DBUG_PRINT("info", ("Select 0x%lx, type %s, message %s", + (ulong)join->select_lex, join->select_lex->type, + message)); /* Don't log this into the slow query log */ select_lex->options&= ~(QUERY_NO_INDEX_USED | QUERY_NO_GOOD_INDEX_USED); join->unit->offset_limit_cnt= 0; if (message) { - item_list.push_back(new Item_int((int32) thd->lex.select->select_number)); - item_list.push_back(new Item_string(thd->lex.select->type, - strlen(thd->lex.select->type), + item_list.push_back(new Item_int((int32) join->select_lex->select_number)); + item_list.push_back(new Item_string(join->select_lex->type, + strlen(join->select_lex->type), default_charset_info)); Item *empty= new Item_empty_string("",0); for (uint i=0 ; i < 7; i++) @@ -7285,9 +7287,10 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order, tmp2.length(0); item_list.empty(); - item_list.push_back(new Item_int((int32) thd->lex.select->select_number)); - item_list.push_back(new Item_string(thd->lex.select->type, - strlen(thd->lex.select->type), + item_list.push_back(new Item_int((int32) + join->select_lex->select_number)); + item_list.push_back(new Item_string(join->select_lex->type, + strlen(join->select_lex->type), default_charset_info)); if (tab->type == JT_ALL && tab->select && tab->select->quick) tab->type= JT_RANGE; @@ -7445,6 +7448,7 @@ static void select_describe(JOIN *join, bool need_tmp_table, bool need_order, int mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit, select_result *result) { + DBUG_ENTER("mysql_explain_union"); int res= 0; SELECT_LEX *first= unit->first_select(); for (SELECT_LEX *sl= first; @@ -7467,12 +7471,14 @@ int mysql_explain_union(THD *thd, SELECT_LEX_UNIT *unit, select_result *result) } if (res > 0) res= -res; // mysql_explain_select do not report error - return res; + DBUG_RETURN(res); } int mysql_explain_select(THD *thd, SELECT_LEX *select_lex, char const *type, select_result *result) { + DBUG_ENTER("mysql_explain_select"); + DBUG_PRINT("info", ("Select 0x%lx, type %s", (ulong)select_lex, type)) select_lex->type= type; thd->lex.select= select_lex; SELECT_LEX_UNIT *unit= select_lex->master_unit(); @@ -7485,6 +7491,6 @@ int mysql_explain_select(THD *thd, SELECT_LEX *select_lex, char const *type, (ORDER*) thd->lex.proc_list.first, select_lex->options | thd->options | SELECT_DESCRIBE, result, unit, select_lex, 0); - return res; + DBUG_RETURN(res); } diff --git a/sql/sql_union.cc b/sql/sql_union.cc index eaeec2c1e68..f1c80bf8546 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -110,7 +110,6 @@ int st_select_lex_unit::prepare(THD *thd, select_result *result) DBUG_RETURN(0); prepared= 1; union_result=0; - describe=(first_select()->options & SELECT_DESCRIBE) ? 1 : 0; res= 0; found_rows_for_union= false; TMP_TABLE_PARAM tmp_table_param; @@ -122,30 +121,11 @@ int st_select_lex_unit::prepare(THD *thd, select_result *result) if (((void*)(global_parameters)) == ((void*)this)) { found_rows_for_union= first_select()->options & OPTION_FOUND_ROWS && - !describe && global_parameters->select_limit; + global_parameters->select_limit; if (found_rows_for_union) first_select()->options ^= OPTION_FOUND_ROWS; } item_list.empty(); - if (describe) - { - Item *item; - item_list.push_back(new Item_empty_string("table",NAME_LEN)); - item_list.push_back(new Item_empty_string("type",10)); - item_list.push_back(item=new Item_empty_string("possible_keys", - NAME_LEN*MAX_KEY)); - item->maybe_null=1; - item_list.push_back(item=new Item_empty_string("key",NAME_LEN)); - item->maybe_null=1; - item_list.push_back(item=new Item_int("key_len",0,3)); - item->maybe_null=1; - item_list.push_back(item=new Item_empty_string("ref", - NAME_LEN*MAX_REF_PARTS)); - item->maybe_null=1; - item_list.push_back(new Item_real("rows",0.0,0,10)); - item_list.push_back(new Item_empty_string("Extra",255)); - } - else { Item *item; List_iterator<Item> it(first_select()->item_list); @@ -162,8 +142,7 @@ int st_select_lex_unit::prepare(THD *thd, select_result *result) bzero((char*) &tmp_table_param,sizeof(tmp_table_param)); tmp_table_param.field_count=item_list.elements; if (!(table= create_tmp_table(thd, &tmp_table_param, item_list, - (ORDER*) 0, !describe & - !thd->lex.union_option, + (ORDER*) 0, !union_option, 1, 0, (first_select()->options | thd->options | TMP_TABLE_ALL_COLUMNS), @@ -179,7 +158,7 @@ int st_select_lex_unit::prepare(THD *thd, select_result *result) if (!(union_result=new select_union(table))) goto err; - union_result->save_time_stamp=!describe; + union_result->save_time_stamp=1; union_result->tmp_table_param=&tmp_table_param; // prepare selects @@ -187,8 +166,7 @@ int st_select_lex_unit::prepare(THD *thd, select_result *result) for (sl= first_select(); sl; sl= sl->next_select()) { JOIN *join= new JOIN(thd, sl->item_list, - sl->options | thd->options | SELECT_NO_UNLOCK | - ((describe) ? SELECT_DESCRIBE : 0), + sl->options | thd->options | SELECT_NO_UNLOCK, union_result); joins.push_back(new JOIN_P(join)); thd->lex.select=sl; @@ -220,11 +198,12 @@ err: int st_select_lex_unit::exec() { DBUG_ENTER("st_select_lex_unit::exec"); + SELECT_LEX *lex_select_save= thd->lex.select; + if(depended || !item || !item->assigned()) { if (optimized && item && item->assigned()) item->assigned(0); // We will reinit & rexecute unit - SELECT_LEX *lex_select_save= thd->lex.select; for (SELECT_LEX *sl= first_select(); sl; sl= sl->next_select()) { thd->lex.select=sl; @@ -236,27 +215,28 @@ int st_select_lex_unit::exec() sl->options&= ~OPTION_FOUND_ROWS; if (!optimized) - sl->join->optimize(); + res= sl->join->optimize(); else - sl->join->reinit(); - - sl->join->exec(); - res= sl->join->error; + res= sl->join->reinit(); + if (!res) + { + sl->join->exec(); + res= sl->join->error; + } if (res) { thd->lex.select= lex_select_save; DBUG_RETURN(res); } } - thd->lex.select= lex_select_save; optimized= 1; } if (union_result->flush()) { - res= 1; // Error is already sent - DBUG_RETURN(res); + thd->lex.select= lex_select_save; + DBUG_RETURN(1); } /* Send result to 'result' */ @@ -289,12 +269,8 @@ int st_select_lex_unit::exec() select_limit_cnt= HA_POS_ERROR; // no limit if (select_limit_cnt == HA_POS_ERROR) thd->options&= ~OPTION_FOUND_ROWS; - if (describe) - select_limit_cnt= HA_POS_ERROR; // no limit res= mysql_select(thd,&result_table_list, item_list, NULL, - (describe) ? - 0: (ORDER*)global_parameters->order_list.first, (ORDER*) NULL, NULL, (ORDER*) NULL, thd->options, result, this, first_select(), 1); @@ -303,6 +279,7 @@ int st_select_lex_unit::exec() } } thd->lex.select_lex.ftfunc_list= &thd->lex.select_lex.ftfunc_list_alloc; + thd->lex.select= lex_select_save; DBUG_RETURN(res); } diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 83de03026f1..7d68278e39f 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -4150,7 +4150,7 @@ optional_order_or_limit: union_option: /* empty */ {} - | ALL {Lex->union_option=1;}; + | ALL {Select->master_unit()->union_option= 1;}; singleval_subselect: subselect_start singleval_subselect_init |