Loading mysql-test/r/view.result +17 −0 Original line number Diff line number Diff line Loading @@ -1726,3 +1726,20 @@ sum(a) drop procedure p1; drop view v1; drop table t1; create table t1 (s1 int); create view v1 as select sum(distinct s1) from t1; select * from v1; sum(distinct s1) NULL drop view v1; create view v1 as select avg(distinct s1) from t1; select * from v1; avg(distinct s1) NULL drop view v1; drop table t1; create view v1 as select cast(1 as decimal); select * from v1; cast(1 as decimal) 1.00 drop view v1; mysql-test/t/view.test +18 −0 Original line number Diff line number Diff line Loading @@ -1569,3 +1569,21 @@ drop procedure p1; drop view v1; drop table t1; # # using sum(distinct ) & avg(distinct ) in views (BUG#7015) # create table t1 (s1 int); create view v1 as select sum(distinct s1) from t1; select * from v1; drop view v1; create view v1 as select avg(distinct s1) from t1; select * from v1; drop view v1; drop table t1; # # using cast(... as decimal) in views (BUG#11387); # create view v1 as select cast(1 as decimal); select * from v1; drop view v1; sql/item.h +12 −0 Original line number Diff line number Diff line Loading @@ -468,6 +468,18 @@ class Item { */ virtual bool const_during_execution() const { return (used_tables() & ~PARAM_TABLE_BIT) == 0; } /* This is an essential method for correct functioning of VIEWS. To save a view in an .frm file we need its unequivocal definition in SQL that takes into account sql_mode and environmental settings. Currently such definition is restored by traversing through the parsed tree of a view and print()'ing SQL syntax of every node to a String buffer. This method is used to print the SQL definition of an item. The second use of this method is for EXPLAIN EXTENDED, to print the SQL of a query after all optimizations of the parsed tree have been done. */ virtual void print(String *str_arg) { str_arg->append(full_name()); } void print_item_w_name(String *); virtual void update_used_tables() {} Loading sql/item_func.cc +9 −1 Original line number Diff line number Diff line Loading @@ -1061,6 +1061,14 @@ my_decimal *Item_decimal_typecast::val_decimal(my_decimal *dec) } void Item_decimal_typecast::print(String *str) { str->append("cast(", 5); args[0]->print(str); str->append(" as decimal)", 12); } double Item_func_plus::real_op() { double value= args[0]->val_real() + args[1]->val_real(); Loading Loading @@ -4111,7 +4119,7 @@ bool Item_func_get_user_var::eq(const Item *item, bool binary_cmp) const return 1; // Same item is same. /* Check if other type is also a get_user_var() object */ if (item->type() != FUNC_ITEM || ((Item_func*) item)->func_name() != func_name()) ((Item_func*) item)->functype() != functype()) return 0; Item_func_get_user_var *other=(Item_func_get_user_var*) item; return (name.length == other->name.length && Loading sql/item_func.h +26 −13 Original line number Diff line number Diff line Loading @@ -54,7 +54,8 @@ class Item_func :public Item_result_field SP_POINTN,SP_GEOMETRYN,SP_INTERIORRINGN, NOT_FUNC, NOT_ALL_FUNC, NOW_FUNC, TRIG_COND_FUNC, GUSERVAR_FUNC}; GUSERVAR_FUNC, COLLATE_FUNC, EXTRACT_FUNC, CHAR_TYPECAST_FUNC }; enum optimize_type { OPTIMIZE_NONE,OPTIMIZE_KEY,OPTIMIZE_OP, OPTIMIZE_NULL, OPTIMIZE_EQUAL }; enum Type type() const { return FUNC_ITEM; } Loading Loading @@ -123,7 +124,17 @@ class Item_func :public Item_result_field virtual optimize_type select_optimize() const { return OPTIMIZE_NONE; } virtual bool have_rev_func() const { return 0; } virtual Item *key_item() const { return args[0]; } virtual const char *func_name() const { return "?"; } /* This method is used for debug purposes to print the name of an item to the debug log. The second use of this method is as a helper function of print(), where it is applicable. To suit both goals it should return a meaningful, distinguishable and sintactically correct string. This method should not be used for runtime type identification, use enum {Sum}Functype and Item_func::functype()/Item_sum::sum_func() instead. */ virtual const char *func_name() const= 0; virtual bool const_item() const { return const_item_cache; } inline Item **arguments() const { return args; } void set_arguments(List<Item> &list); Loading Loading @@ -306,6 +317,8 @@ class Item_decimal_typecast :public Item_func enum Item_result result_type () const { return DECIMAL_RESULT; } enum_field_types field_type() const { return MYSQL_TYPE_NEWDECIMAL; } void fix_length_and_dec() {}; const char *func_name() const { return "decimal_typecast"; } void print(String *); }; Loading Loading
mysql-test/r/view.result +17 −0 Original line number Diff line number Diff line Loading @@ -1726,3 +1726,20 @@ sum(a) drop procedure p1; drop view v1; drop table t1; create table t1 (s1 int); create view v1 as select sum(distinct s1) from t1; select * from v1; sum(distinct s1) NULL drop view v1; create view v1 as select avg(distinct s1) from t1; select * from v1; avg(distinct s1) NULL drop view v1; drop table t1; create view v1 as select cast(1 as decimal); select * from v1; cast(1 as decimal) 1.00 drop view v1;
mysql-test/t/view.test +18 −0 Original line number Diff line number Diff line Loading @@ -1569,3 +1569,21 @@ drop procedure p1; drop view v1; drop table t1; # # using sum(distinct ) & avg(distinct ) in views (BUG#7015) # create table t1 (s1 int); create view v1 as select sum(distinct s1) from t1; select * from v1; drop view v1; create view v1 as select avg(distinct s1) from t1; select * from v1; drop view v1; drop table t1; # # using cast(... as decimal) in views (BUG#11387); # create view v1 as select cast(1 as decimal); select * from v1; drop view v1;
sql/item.h +12 −0 Original line number Diff line number Diff line Loading @@ -468,6 +468,18 @@ class Item { */ virtual bool const_during_execution() const { return (used_tables() & ~PARAM_TABLE_BIT) == 0; } /* This is an essential method for correct functioning of VIEWS. To save a view in an .frm file we need its unequivocal definition in SQL that takes into account sql_mode and environmental settings. Currently such definition is restored by traversing through the parsed tree of a view and print()'ing SQL syntax of every node to a String buffer. This method is used to print the SQL definition of an item. The second use of this method is for EXPLAIN EXTENDED, to print the SQL of a query after all optimizations of the parsed tree have been done. */ virtual void print(String *str_arg) { str_arg->append(full_name()); } void print_item_w_name(String *); virtual void update_used_tables() {} Loading
sql/item_func.cc +9 −1 Original line number Diff line number Diff line Loading @@ -1061,6 +1061,14 @@ my_decimal *Item_decimal_typecast::val_decimal(my_decimal *dec) } void Item_decimal_typecast::print(String *str) { str->append("cast(", 5); args[0]->print(str); str->append(" as decimal)", 12); } double Item_func_plus::real_op() { double value= args[0]->val_real() + args[1]->val_real(); Loading Loading @@ -4111,7 +4119,7 @@ bool Item_func_get_user_var::eq(const Item *item, bool binary_cmp) const return 1; // Same item is same. /* Check if other type is also a get_user_var() object */ if (item->type() != FUNC_ITEM || ((Item_func*) item)->func_name() != func_name()) ((Item_func*) item)->functype() != functype()) return 0; Item_func_get_user_var *other=(Item_func_get_user_var*) item; return (name.length == other->name.length && Loading
sql/item_func.h +26 −13 Original line number Diff line number Diff line Loading @@ -54,7 +54,8 @@ class Item_func :public Item_result_field SP_POINTN,SP_GEOMETRYN,SP_INTERIORRINGN, NOT_FUNC, NOT_ALL_FUNC, NOW_FUNC, TRIG_COND_FUNC, GUSERVAR_FUNC}; GUSERVAR_FUNC, COLLATE_FUNC, EXTRACT_FUNC, CHAR_TYPECAST_FUNC }; enum optimize_type { OPTIMIZE_NONE,OPTIMIZE_KEY,OPTIMIZE_OP, OPTIMIZE_NULL, OPTIMIZE_EQUAL }; enum Type type() const { return FUNC_ITEM; } Loading Loading @@ -123,7 +124,17 @@ class Item_func :public Item_result_field virtual optimize_type select_optimize() const { return OPTIMIZE_NONE; } virtual bool have_rev_func() const { return 0; } virtual Item *key_item() const { return args[0]; } virtual const char *func_name() const { return "?"; } /* This method is used for debug purposes to print the name of an item to the debug log. The second use of this method is as a helper function of print(), where it is applicable. To suit both goals it should return a meaningful, distinguishable and sintactically correct string. This method should not be used for runtime type identification, use enum {Sum}Functype and Item_func::functype()/Item_sum::sum_func() instead. */ virtual const char *func_name() const= 0; virtual bool const_item() const { return const_item_cache; } inline Item **arguments() const { return args; } void set_arguments(List<Item> &list); Loading Loading @@ -306,6 +317,8 @@ class Item_decimal_typecast :public Item_func enum Item_result result_type () const { return DECIMAL_RESULT; } enum_field_types field_type() const { return MYSQL_TYPE_NEWDECIMAL; } void fix_length_and_dec() {}; const char *func_name() const { return "decimal_typecast"; } void print(String *); }; Loading