From 85f397781bc32fbc2edb82ce57e46cd613a591f0 Mon Sep 17 00:00:00 2001 From: "bell@laptop.sanja.is.com.ua" <> Date: Sat, 16 Aug 2003 13:26:48 +0300 Subject: [PATCH] Code cleanup --- sql/item.cc | 14 -------------- sql/item.h | 27 --------------------------- sql/item_subselect.cc | 12 +++++++----- sql/mysql_priv.h | 1 - sql/sql_delete.cc | 3 +-- sql/sql_derived.cc | 8 +++----- sql/sql_lex.cc | 14 ++++++++++++-- sql/sql_lex.h | 1 + sql/sql_select.cc | 18 +----------------- sql/sql_table.cc | 3 +-- sql/sql_union.cc | 8 +++----- sql/sql_update.cc | 3 +-- 12 files changed, 30 insertions(+), 82 deletions(-) diff --git a/sql/item.cc b/sql/item.cc index 921f588e5d3..9249df16d3d 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -722,20 +722,6 @@ bool Item::fix_fields(THD *thd, return 0; } -bool Item_ref_on_list_position::fix_fields(THD *thd, - struct st_table_list *tables, - Item ** reference) -{ - if (select_lex->item_list.elements <= pos) - { - ref= 0; - my_error(ER_CARDINALITY_COL, MYF(0), pos); - return 1; - } - ref= select_lex->ref_pointer_array + pos; - return Item_ref_null_helper::fix_fields(thd, tables, reference); -} - double Item_ref_null_helper::val() { double tmp= (*ref)->val_result(); diff --git a/sql/item.h b/sql/item.h index ce8b4062580..6b7730f77db 100644 --- a/sql/item.h +++ b/sql/item.h @@ -637,33 +637,6 @@ public: {} }; -/* - Used to find item in list of select items after '*' items processing. - - Because item '*' can be used in item list. when we create - Item_ref_on_list_position we do not know how item list will be changed, but - we know number of item position (I mean queries like "select * from t"). -*/ -class Item_ref_on_list_position: public Item_ref_null_helper -{ -protected: - /* - select_lex used for: - 1) receiving expanded variant of item list (to check max possible - number of elements); - 2) to have access to ref_pointer_array, via wich item will refered. - */ - st_select_lex *select_lex; - uint pos; -public: - Item_ref_on_list_position(Item_in_subselect* master, - st_select_lex *sl, uint num, - char *table_name, char *field_name): - Item_ref_null_helper(master, 0, table_name, field_name), - select_lex(sl), pos(num) {} - bool fix_fields(THD *, struct st_table_list *, Item ** ref); -}; - /* The following class is used to optimize comparing of date columns We need to save the original item, to be able to set the field to the diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 06418b74b16..36b65ef486e 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -650,15 +650,17 @@ Item_in_subselect::row_value_transformer(JOIN *join, uint n= left_expr->cols(); select_lex->dependent= 1; - + select_lex->setup_ref_array(thd, + select_lex->order_list.elements + + select_lex->group_list.elements); Item *item= 0; List_iterator_fast li(select_lex->item_list); for (uint i= 0; i < n; i++) { - Item *func= - new Item_ref_on_list_position(this, select_lex, i, - (char *) "", - (char *) ""); + Item *func= new Item_ref_null_helper(this, + select_lex->ref_pointer_array+i, + (char *) "", + (char *) ""); func= Item_bool_func2::eq_creator(new Item_ref((*optimizer->get_cache())-> addr(i), diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h index 204a7cb7b1a..75e64222f28 100644 --- a/sql/mysql_priv.h +++ b/sql/mysql_priv.h @@ -411,7 +411,6 @@ int mysql_preload_keys(THD* thd, TABLE_LIST* table_list); bool check_simple_select(); SORT_FIELD * make_unireg_sortorder(ORDER *order, uint *length); -int setup_ref_array(THD *thd, Item ***rref_pointer_array, uint elements); int setup_order(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables, List &fields, List &all_fields, ORDER *order); int setup_group(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables, diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 876c4f9e670..a3be2d42d3b 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -126,8 +126,7 @@ int mysql_delete(THD *thd, TABLE_LIST *table_list, COND *conds, ORDER *order, table->sort.io_cache = (IO_CACHE *) my_malloc(sizeof(IO_CACHE), MYF(MY_FAE | MY_ZEROFILL)); - if (setup_ref_array(thd, &thd->lex.select_lex.ref_pointer_array, - all_fields.elements)|| + if (thd->lex.select_lex.setup_ref_array(thd, 0) || setup_order(thd, thd->lex.select_lex.ref_pointer_array, &tables, fields, all_fields, order) || !(sortorder=make_unireg_sortorder(order, &length)) || diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc index b71a803edb8..771d68e8462 100644 --- a/sql/sql_derived.cc +++ b/sql/sql_derived.cc @@ -135,11 +135,9 @@ int mysql_derived(THD *thd, LEX *lex, SELECT_LEX_UNIT *unit, item_list= select_cursor->item_list; select_cursor->with_wild= 0; - if (setup_ref_array(thd, &select_cursor->ref_pointer_array, - (item_list.elements + - select_cursor->select_n_having_items + - select_cursor->order_list.elements + - select_cursor->group_list.elements)) || + if (select_cursor->setup_ref_array(thd, + select_cursor->order_list.elements + + select_cursor->group_list.elements) || setup_fields(thd, select_cursor->ref_pointer_array, first_table, item_list, 0, 0, 1)) { diff --git a/sql/sql_lex.cc b/sql/sql_lex.cc index 2d1d08aa596..d6cfd555c40 100644 --- a/sql/sql_lex.cc +++ b/sql/sql_lex.cc @@ -981,6 +981,7 @@ void st_select_lex::init_query() resolve_mode= NOMATTER_MODE; cond_count= with_wild= 0; ref_pointer_array= 0; + select_n_having_items= 0; } void st_select_lex::init_select() @@ -989,7 +990,6 @@ void st_select_lex::init_select() group_list.empty(); type= db= db1= table1= db2= table2= 0; having= 0; - group_list.empty(); use_index_ptr= ignore_index_ptr= 0; table_join_options= 0; in_sum_expr= with_wild= 0; @@ -1007,7 +1007,6 @@ void st_select_lex::init_select() order_list.next= (byte**) &order_list.first; select_limit= HA_POS_ERROR; offset_limit= 0; - select_n_having_items= 0; with_sum_func= 0; parsing_place= SELECT_LEX_NODE::NO_MATTER; } @@ -1410,6 +1409,17 @@ ulong st_select_lex::get_table_join_options() return table_join_options; } +bool st_select_lex::setup_ref_array(THD *thd, uint order_group_num) +{ + if (ref_pointer_array) + return 0; + return (ref_pointer_array= + (Item **)thd->alloc(sizeof(Item*) * + (item_list.elements + + select_n_having_items + + order_group_num)* 5)) == 0; +} + /* There are st_select_lex::add_table_to_list & st_select_lex::set_lock_for_tables in sql_parse.cc diff --git a/sql/sql_lex.h b/sql/sql_lex.h index fb336faa2a6..000a5f65042 100644 --- a/sql/sql_lex.h +++ b/sql/sql_lex.h @@ -449,6 +449,7 @@ public: init_query(); init_select(); } + bool setup_ref_array(THD *thd, uint order_group_num); }; typedef class st_select_lex SELECT_LEX; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index 5607ff65b85..24a4efdfcc0 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -294,10 +294,7 @@ JOIN::prepare(Item ***rref_pointer_array, setup_wild(thd, tables_list, fields_list, &all_fields, wild_num))) || - setup_ref_array(thd, rref_pointer_array, (fields_list.elements + - select_lex-> - select_n_having_items + - og_num)) || + select_lex->setup_ref_array(thd, og_num) || setup_fields(thd, (*rref_pointer_array), tables_list, fields_list, 1, &all_fields, 1) || setup_without_group(thd, (*rref_pointer_array), tables_list, fields_list, @@ -7483,19 +7480,6 @@ find_order_in_list(THD *thd, Item **ref_pointer_array, return 0; } -/* - Allocate array of references to address all_fileds list elements -*/ - -int setup_ref_array(THD* thd, Item ***rref_pointer_array, uint elements) -{ - if (*rref_pointer_array) - return 0; - - return (*rref_pointer_array= - (Item **)thd->alloc(sizeof(Item*) * elements * 5)) == 0; -} - /* Change order to point at item in select list. If item isn't a number and doesn't exits in the select list, add it the the field list. diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 7cb8dfaae0d..99865001317 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -2501,8 +2501,7 @@ copy_data_between_tables(TABLE *from,TABLE *to, tables.db = from->table_cache_key; error=1; - if (setup_ref_array(thd, &thd->lex.select_lex.ref_pointer_array, - order_num)|| + if (thd->lex.select_lex.setup_ref_array(thd, order_num) || setup_order(thd, thd->lex.select_lex.ref_pointer_array, &tables, fields, all_fields, order) || !(sortorder=make_unireg_sortorder(order, &length)) || diff --git a/sql/sql_union.cc b/sql/sql_union.cc index 09d9c42ed95..3b5666f1ee2 100644 --- a/sql/sql_union.cc +++ b/sql/sql_union.cc @@ -156,11 +156,9 @@ int st_select_lex_unit::prepare(THD *thd, select_result *sel_result, Item *item; item_list= select_cursor->item_list; select_cursor->with_wild= 0; - if (setup_ref_array(thd, &select_cursor->ref_pointer_array, - (item_list.elements + - select_cursor->select_n_having_items + - select_cursor->order_list.elements + - select_cursor->group_list.elements)) || + if (select_cursor->setup_ref_array(thd, + select_cursor->order_list.elements + + select_cursor->group_list.elements) || setup_fields(thd, select_cursor->ref_pointer_array, first_table, item_list, 0, 0, 1)) goto err; diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 21d0a5aeb42..5a6b5523cd3 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -94,8 +94,7 @@ int mysql_update(THD *thd, if (setup_tables(update_table_list) || setup_conds(thd,update_table_list,&conds) || - setup_ref_array(thd, &thd->lex.select_lex.ref_pointer_array, - order_num) || + thd->lex.select_lex.setup_ref_array(thd, order_num) || setup_order(thd, thd->lex.select_lex.ref_pointer_array, &tables, all_fields, all_fields, order) || setup_ftfuncs(&thd->lex.select_lex))