From f83cf4144065c12cad4007767e2e70d444fd0e05 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 17 Mar 2004 14:26:26 +0200 Subject: DBUG_ASSERT(fixed == 0) added to fix_fields() sql/item.cc: layout fixed fixed bug in prepared statements with subqueries and outer references sql/item.h: neg_transformer get thd argument to call fix_fields sql/item_cmpfunc.cc: DBUG_ASSERT(fixed == 0) added to fix_fields() fixed Item_in_optimizer fixed flag neg_arguments(), neg_transformer() call fix_field() on created items to avoid bouble fix field or non-called fixfields() sql/item_cmpfunc.h: neg_transformer get thd argument to call fix_fields fixed forgoten cleanup() call of parent class sql/item_func.cc: DBUG_ASSERT(fixed == 0) and fixed flag check added to fix_fields() sql/item_func.h: DBUG_ASSERT(fixed == 0) added to fix_fields() fixed forgoten cleanup() call of parent class sql/item_row.cc: DBUG_ASSERT(fixed == 0) added to fix_fields() added forgoten 'fixed' flag set sql/item_subselect.cc: DBUG_ASSERT(fixed == 0) added to fix_fields() fixed subquery transformation sql/sql_base.cc: check of fixed flag added sql/sql_derived.cc: fixed cleunup union in derived table during EXPLAIN command processing sql/sql_select.cc: thd argument add to function to allow call fix_fields() of new created items fixed EXPLAIN double preparation check of fixed flag added eliminate_not_funcs fixed for corrcet fix_fields call of new created items sql/sql_select.h: thd argument add to function to allow call fix_fields() of new created items sql/sql_union.cc: union processing fixed tests/client_test.c: layout fixed new test of outer references fron subqueries --- sql/item.h | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'sql/item.h') diff --git a/sql/item.h b/sql/item.h index 832fc775016..27f427c1ef4 100644 --- a/sql/item.h +++ b/sql/item.h @@ -233,7 +233,7 @@ public: Field *tmp_table_field_from_field_type(TABLE *table); /* Used in sql_select.cc:eliminate_not_funcs() */ - virtual Item *neg_transformer() { return NULL; } + virtual Item *neg_transformer(THD *thd) { return NULL; } void delete_self() { cleanup(); @@ -245,6 +245,7 @@ public: class st_select_lex; class Item_ident :public Item { + Item **changed_during_fix_field; public: const char *db_name; const char *table_name; @@ -254,7 +255,9 @@ public: const char *field_name_par); Item_ident(THD *thd, Item_ident *item); const char *full_name() const; - + void cleanup(); + void register_item_tree_changing(Item **ref) + { changed_during_fix_field= ref; } bool remove_dependence_processor(byte * arg); }; @@ -264,11 +267,17 @@ class Item_field :public Item_ident void set_field(Field *field); public: Field *field,*result_field; - // Item_field() {} +#ifndef DBUG_OFF + bool double_fix; +#endif Item_field(const char *db_par,const char *table_name_par, const char *field_name_par) - :Item_ident(db_par,table_name_par,field_name_par),field(0),result_field(0) + :Item_ident(db_par,table_name_par,field_name_par), + field(0), result_field(0) +#ifndef DBUG_OFF + ,double_fix(0) +#endif { collation.set(DERIVATION_IMPLICIT); } // Constructor need to process subselect with temporary tables (see Item) Item_field(THD *thd, Item_field *item); @@ -324,6 +333,7 @@ public: enum_field_types field_type() const { return MYSQL_TYPE_NULL; } bool fix_fields(THD *thd, struct st_table_list *list, Item **item) { + DBUG_ASSERT(fixed == 0); bool res= Item::fix_fields(thd, list, item); max_length=0; return res; @@ -413,7 +423,8 @@ public: int save_in_field(Field *field, bool no_conversions); bool basic_const_item() const { return 1; } Item *new_item() { return new Item_int(name,value,max_length); } - void cleanup() { fixed= 1; } // to prevent drop fixed flag + // to prevent drop fixed flag (no need parent cleanup call) + void cleanup() { fixed= 1; } void print(String *str); }; @@ -422,14 +433,17 @@ class Item_uint :public Item_int { public: Item_uint(const char *str_arg, uint length) : - Item_int(str_arg, (longlong) strtoull(str_arg,(char**) 0,10), length) {} - Item_uint(uint32 i) :Item_int((longlong) i, 10) {} + Item_int(str_arg, (longlong) strtoull(str_arg,(char**) 0,10), length) + { fixed= 0; } + Item_uint(uint32 i) :Item_int((longlong) i, 10) + { fixed= 0; } double val() { return ulonglong2double((ulonglong)value); } String *val_str(String*); Item *new_item() { return new Item_uint(name,max_length); } int save_in_field(Field *field, bool no_conversions); bool fix_fields(THD *thd, struct st_table_list *list, Item **item) { + DBUG_ASSERT(fixed == 0); bool res= Item::fix_fields(thd, list, item); unsigned_flag= 1; return res; @@ -903,7 +917,8 @@ public: static Item_cache* get_cache(Item_result type); table_map used_tables() const { return used_table_map; } virtual void keep_array() {} - void cleanup() { fixed= 1; } // to prevent drop fixed flag + // to prevent drop fixed flag (no need parent cleanup call) + void cleanup() { fixed= 1; } void print(String *str); }; -- cgit v1.2.1 From 1a81e0414515cef6275b5d2f3f27b950aa1ff91f Mon Sep 17 00:00:00 2001 From: unknown Date: Thu, 18 Mar 2004 15:14:36 +0200 Subject: DBUG_ASSERT(fixed == 1); added to val* small optimisation in signed_literal sql/field.cc: layout fixed sql/item.cc: DBUG_ASSERT(fixed == 1); added to val* layout fixed fixed= 1; added where it was forgoten in fix_fields Item_string can be used without fix_fields sql/item.h: DBUG_ASSERT(fixed == 1); added to val* Item_string can be used without fix_fields sql/item_cmpfunc.cc: DBUG_ASSERT(fixed == 1); added to val* sql/item_cmpfunc.h: fixed layout and getting Item statistic sql/item_func.cc: DBUG_ASSERT(fixed == 1); added to val* sql/item_func.h: DBUG_ASSERT(fixed == 1); added to val* sql/item_geofunc.cc: DBUG_ASSERT(fixed == 1); added to val* sql/item_strfunc.cc: DBUG_ASSERT(fixed == 1); added to val* layout fixed sql/item_strfunc.h: DBUG_ASSERT(fixed == 1); added to val* sql/item_subselect.cc: DBUG_ASSERT(fixed == 1); added to val* sql/item_sum.cc: DBUG_ASSERT(fixed == 1); added to val* sql/item_sum.h: DBUG_ASSERT(fixed == 1); added to val* sql/item_timefunc.cc: DBUG_ASSERT(fixed == 1); added to val* sql/item_timefunc.h: DBUG_ASSERT(fixed == 1); added to val* sql/item_uniq.h: DBUG_ASSERT(fixed == 1); added to val* sql/sql_base.cc: Item creation revised sql/sql_help.cc: Item creation revised sql/sql_load.cc: Item creation revised sql/sql_parse.cc: fix_field call added sql/sql_select.cc: Item creation revised sql/sql_show.cc: Item creation revised sql/sql_union.cc: Item creation revised sql/sql_update.cc: Item creation revised sql/sql_yacc.yy: Item creation revised small optimisation in signed_literal --- sql/item.h | 62 ++++++++++++++++++++++++++++++++++++++++++++++---------------- 1 file changed, 46 insertions(+), 16 deletions(-) (limited to 'sql/item.h') diff --git a/sql/item.h b/sql/item.h index 27f427c1ef4..7bf3bd07436 100644 --- a/sql/item.h +++ b/sql/item.h @@ -281,7 +281,7 @@ public: { collation.set(DERIVATION_IMPLICIT); } // Constructor need to process subselect with temporary tables (see Item) Item_field(THD *thd, Item_field *item); - Item_field(Field *field); + Item_field(Field *field, bool already_fixed); enum Type type() const { return FIELD_ITEM; } bool eq(const Item *item, bool binary_cmp) const; double val(); @@ -417,8 +417,8 @@ public: enum Type type() const { return INT_ITEM; } enum Item_result result_type () const { return INT_RESULT; } enum_field_types field_type() const { return MYSQL_TYPE_LONGLONG; } - longlong val_int() { return value; } - double val() { return (double) value; } + longlong val_int() { DBUG_ASSERT(fixed == 1); return value; } + double val() { DBUG_ASSERT(fixed == 1); return (double) value; } String *val_str(String*); int save_in_field(Field *field, bool no_conversions); bool basic_const_item() const { return 1; } @@ -437,7 +437,8 @@ public: { fixed= 0; } Item_uint(uint32 i) :Item_int((longlong) i, 10) { fixed= 0; } - double val() { return ulonglong2double((ulonglong)value); } + double val() + { DBUG_ASSERT(fixed == 1); return ulonglong2double((ulonglong)value); } String *val_str(String*); Item *new_item() { return new Item_uint(name,max_length); } int save_in_field(Field *field, bool no_conversions); @@ -474,8 +475,12 @@ public: int save_in_field(Field *field, bool no_conversions); enum Type type() const { return REAL_ITEM; } enum_field_types field_type() const { return MYSQL_TYPE_DOUBLE; } - double val() { return value; } - longlong val_int() { return (longlong) (value+(value > 0 ? 0.5 : -0.5));} + double val() { DBUG_ASSERT(fixed == 1); return value; } + longlong val_int() + { + DBUG_ASSERT(fixed == 1); + return (longlong) (value+(value > 0 ? 0.5 : -0.5)); + } String *val_str(String*); bool basic_const_item() const { return 1; } Item *new_item() { return new Item_real(name,value,decimals,max_length); } @@ -510,6 +515,8 @@ public: max_length= str_value.numchars()*cs->mbmaxlen; set_name(str, length, cs); decimals=NOT_FIXED_DEC; + // it is constant => can be used without fix_fields (and frequently used) + fixed= 1; } Item_string(const char *name_par, const char *str, uint length, CHARSET_INFO *cs, Derivation dv= DERIVATION_COERCIBLE) @@ -519,21 +526,29 @@ public: max_length= str_value.numchars()*cs->mbmaxlen; set_name(name_par,0,cs); decimals=NOT_FIXED_DEC; + // it is constant => can be used without fix_fields (and frequently used) + fixed= 1; } enum Type type() const { return STRING_ITEM; } double val() - { + { + DBUG_ASSERT(fixed == 1); int err; return my_strntod(str_value.charset(), (char*) str_value.ptr(), str_value.length(), (char**) 0, &err); } longlong val_int() { + DBUG_ASSERT(fixed == 1); int err; return my_strntoll(str_value.charset(), str_value.ptr(), str_value.length(), 10, (char**) 0, &err); } - String *val_str(String*) { return (String*) &str_value; } + String *val_str(String*) + { + DBUG_ASSERT(fixed == 1); + return (String*) &str_value; + } int save_in_field(Field *field, bool no_conversions); enum Item_result result_type () const { return STRING_RESULT; } enum_field_types field_type() const { return MYSQL_TYPE_STRING; } @@ -547,6 +562,11 @@ public: String *const_string() { return &str_value; } inline void append(char *str, uint length) { str_value.append(str, length); } void print(String *str); + void cleanup() + { + // it is constant => can be used without fix_fields (and frequently used) + fixed= 1; + } }; /* for show tables */ @@ -588,9 +608,10 @@ class Item_varbinary :public Item public: Item_varbinary(const char *str,uint str_length); enum Type type() const { return VARBIN_ITEM; } - double val() { return (double) Item_varbinary::val_int(); } + double val() + { DBUG_ASSERT(fixed == 1); return (double) Item_varbinary::val_int(); } longlong val_int(); - String *val_str(String*) { return &str_value; } + String *val_str(String*) { DBUG_ASSERT(fixed == 1); return &str_value; } int save_in_field(Field *field, bool no_conversions); enum Item_result result_type () const { return STRING_RESULT; } enum_field_types field_type() const { return MYSQL_TYPE_STRING; } @@ -929,9 +950,14 @@ public: Item_cache_int(): Item_cache() {} void store(Item *item); - double val() { return (double) value; } - longlong val_int() { return value; } - String* val_str(String *str) { str->set(value, default_charset()); return str; } + double val() { DBUG_ASSERT(fixed == 1); return (double) value; } + longlong val_int() { DBUG_ASSERT(fixed == 1); return value; } + String* val_str(String *str) + { + DBUG_ASSERT(fixed == 1); + str->set(value, default_charset()); + return str; + } enum Item_result result_type() const { return INT_RESULT; } }; @@ -942,8 +968,12 @@ public: Item_cache_real(): Item_cache() {} void store(Item *item); - double val() { return value; } - longlong val_int() { return (longlong) (value+(value > 0 ? 0.5 : -0.5)); } + double val() { DBUG_ASSERT(fixed == 1); return value; } + longlong val_int() + { + DBUG_ASSERT(fixed == 1); + return (longlong) (value+(value > 0 ? 0.5 : -0.5)); + } String* val_str(String *str) { str->set(value, decimals, default_charset()); @@ -962,7 +992,7 @@ public: void store(Item *item); double val(); longlong val_int(); - String* val_str(String *) { return value; } + String* val_str(String *) { DBUG_ASSERT(fixed == 1); return value; } enum Item_result result_type() const { return STRING_RESULT; } CHARSET_INFO *charset() const { return value->charset(); }; }; -- cgit v1.2.1