From 23d03a1b1e486da353f20964a1b91068bec209c0 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Mon, 27 Jun 2016 15:41:51 +0200 Subject: parse negative numbers into one item use Item->neg to convert generate negative Item_num's instead of Item_func_neg(Item_num). Based on the following commit: Author: Monty Date: Mon May 30 22:44:00 2016 +0300 Make negative number their own token The negation (-) operator will call Item->neg() one underlying numeric constants and remove itself (like the NOT() function does today for other NOT functions. This simplifies things - -1 is not anymore an expression but a basic_const_item - improves optimizer - DEFAULT -1 doesn't need special handling anymore - When we add DEFAULT expressions, -1 will be treated exactly like 1 - printing of items doesn't anymore put braces around all negative numbers Other things fixed: - Fixed that longlong converted to decimal's has a more appropriate size - Fixed that "-0.0" read into a decimal is interpreted as 0.0 --- sql/item.h | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'sql/item.h') diff --git a/sql/item.h b/sql/item.h index 67d683b15ff..22e44719706 100644 --- a/sql/item.h +++ b/sql/item.h @@ -1846,6 +1846,8 @@ public: /* how much position should be reserved for Exists2In transformation */ virtual uint exists2in_reserved_items() { return 0; }; + virtual Item *neg(THD *thd); + /** Inform the item that it is located under a NOT, which is a top-level item. */ @@ -2261,7 +2263,6 @@ class Item_num: public Item_basic_constant { public: Item_num(THD *thd): Item_basic_constant(thd) { collation.set_numeric(); } - virtual Item_num *neg(THD *thd)= 0; Item *safe_charset_converter(THD *thd, CHARSET_INFO *tocs); bool check_partition_func_processor(uchar *int_arg) { return FALSE;} bool check_vcol_func_processor(uchar *arg) { return FALSE;} @@ -2834,7 +2835,7 @@ public: bool basic_const_item() const { return 1; } Item *clone_item(THD *thd); virtual void print(String *str, enum_query_type query_type); - Item_num *neg(THD *thd) { value= -value; return this; } + Item *neg(THD *thd); uint decimal_precision() const { return (uint) (max_length - MY_TEST(value < 0)); } bool eq(const Item *item, bool binary_cmp) const @@ -2855,7 +2856,7 @@ public: String *val_str(String*); Item *clone_item(THD *thd); virtual void print(String *str, enum_query_type query_type); - Item_num *neg(THD *thd); + Item *neg(THD *thd); uint decimal_precision() const { return max_length; } }; @@ -2899,12 +2900,7 @@ public: bool basic_const_item() const { return 1; } Item *clone_item(THD *thd); virtual void print(String *str, enum_query_type query_type); - Item_num *neg(THD *thd) - { - my_decimal_neg(&decimal_value); - unsigned_flag= !decimal_value.sign(); - return this; - } + Item *neg(THD *thd); uint decimal_precision() const { return decimal_value.precision(); } bool eq(const Item *, bool binary_cmp) const; void set_decimal_value(my_decimal *value_par); @@ -2954,7 +2950,7 @@ public: my_decimal *val_decimal(my_decimal *); bool basic_const_item() const { return 1; } Item *clone_item(THD *thd); - Item_num *neg(THD *thd) { value= -value; return this; } + Item *neg(THD *thd); virtual void print(String *str, enum_query_type query_type); bool eq(const Item *item, bool binary_cmp) const { return real_eq(value, item); } -- cgit v1.2.1