diff options
-rw-r--r-- | mysql-test/r/func_math.result | 21 | ||||
-rw-r--r-- | mysql-test/r/metadata.result | 13 | ||||
-rw-r--r-- | mysql-test/t/func_math.test | 16 | ||||
-rw-r--r-- | mysql-test/t/metadata.test | 12 | ||||
-rw-r--r-- | sql/item_cmpfunc.h | 4 | ||||
-rw-r--r-- | sql/item_func.h | 24 | ||||
-rw-r--r-- | sql/item_timefunc.h | 5 | ||||
-rw-r--r-- | sql/item_xmlfunc.cc | 8 |
8 files changed, 81 insertions, 22 deletions
diff --git a/mysql-test/r/func_math.result b/mysql-test/r/func_math.result index 931604cec7a..c681505a676 100644 --- a/mysql-test/r/func_math.result +++ b/mysql-test/r/func_math.result @@ -856,3 +856,24 @@ t1 CREATE TABLE `t1` ( `c3` double DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t1; +# +# MDEV-12857 Out-of-range errors on CREATE..SELECT 2222222222 DIV 1 +# +SET sql_mode=STRICT_ALL_TABLES; +CREATE OR REPLACE TABLE t1 AS SELECT +2 DIV 1 AS d01, +222222222 DIV 1 AS d09, +2222222222 DIV 1 AS d10; +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `d01` int(1) DEFAULT NULL, + `d09` int(9) DEFAULT NULL, + `d10` bigint(10) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t1; +d01 2 +d09 222222222 +d10 2222222222 +DROP TABLE t1; +SET sql_mode=DEFAULT; diff --git a/mysql-test/r/metadata.result b/mysql-test/r/metadata.result index bebd97610d4..c378a48ee56 100644 --- a/mysql-test/r/metadata.result +++ b/mysql-test/r/metadata.result @@ -536,3 +536,16 @@ Catalog Database Table Table_alias Column Column_alias Type Length Max length Is def TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01') 8 21 1 Y 32896 0 63 TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01') 3 +# +# MDEV-12856 Wrong result set metadata for DIV +# +SELECT +2 DIV 1 AS d0l, +222222222 DIV 1 AS d09, +2222222222 DIV 1 AS d10; +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def d0l 3 1 1 Y 32896 0 63 +def d09 3 9 9 Y 32896 0 63 +def d10 8 10 10 Y 32896 0 63 +d0l d09 d10 +2 222222222 2222222222 diff --git a/mysql-test/t/func_math.test b/mysql-test/t/func_math.test index 03e9923bc52..fd000211145 100644 --- a/mysql-test/t/func_math.test +++ b/mysql-test/t/func_math.test @@ -624,3 +624,19 @@ CREATE OR REPLACE TABLE t1 AS SELECT ROUND(10e0,NULL) AS c3; SHOW CREATE TABLE t1; DROP TABLE t1; + +--echo # +--echo # MDEV-12857 Out-of-range errors on CREATE..SELECT 2222222222 DIV 1 +--echo # + +SET sql_mode=STRICT_ALL_TABLES; +CREATE OR REPLACE TABLE t1 AS SELECT + 2 DIV 1 AS d01, + 222222222 DIV 1 AS d09, + 2222222222 DIV 1 AS d10; +SHOW CREATE TABLE t1; +--vertical_results +SELECT * FROM t1; +--horizontal_results +DROP TABLE t1; +SET sql_mode=DEFAULT; diff --git a/mysql-test/t/metadata.test b/mysql-test/t/metadata.test index 0bd1b98c07d..7c50dadea0b 100644 --- a/mysql-test/t/metadata.test +++ b/mysql-test/t/metadata.test @@ -326,3 +326,15 @@ SELECT LAST_INSERT_ID(); SELECT ROW_COUNT(), FOUND_ROWS(); SELECT TIMESTAMPDIFF(MONTH,'2003-02-01','2003-05-01'); --disable_metadata + + +--echo # +--echo # MDEV-12856 Wrong result set metadata for DIV +--echo # + +--enable_metadata +SELECT + 2 DIV 1 AS d0l, + 222222222 DIV 1 AS d09, + 2222222222 DIV 1 AS d10; +--disable_metadata diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index 5be8ab4f705..10e8993c98e 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -206,10 +206,6 @@ public: Item_bool_func(THD *thd, Item_bool_func *item) :Item_int_func(thd, item) {} const Type_handler *type_handler() const { return &type_handler_long; } bool is_bool_type() { return true; } - Field *create_tmp_field(bool group, TABLE *table) - { return tmp_table_field_from_field_type(table); } - Field *create_field_for_create_select(TABLE *table) - { return tmp_table_field_from_field_type(table); } virtual CHARSET_INFO *compare_collation() const { return NULL; } void fix_length_and_dec() { decimals=0; max_length=1; } uint decimal_precision() const { return 1; } diff --git a/sql/item_func.h b/sql/item_func.h index f7cbc165951..8dcf35720a0 100644 --- a/sql/item_func.h +++ b/sql/item_func.h @@ -738,7 +738,11 @@ public: { collation.set_numeric(); } double val_real(); String *val_str(String*str); - const Type_handler *type_handler() const { return &type_handler_longlong; } + const Type_handler *type_handler() const= 0; + Field *create_tmp_field(bool group, TABLE *table) + { return tmp_table_field_from_field_type(table); } + Field *create_field_for_create_select(TABLE *table) + { return tmp_table_field_from_field_type(table); } void fix_length_and_dec() {} }; @@ -753,10 +757,6 @@ public: Item_long_func(THD *thd, List<Item> &list): Item_int_func(thd, list) { } Item_long_func(THD *thd, Item_long_func *item) :Item_int_func(thd, item) {} const Type_handler *type_handler() const { return &type_handler_long; } - Field *create_tmp_field(bool group, TABLE *table) - { return tmp_table_field_from_field_type(table); } - Field *create_field_for_create_select(TABLE *table) - { return tmp_table_field_from_field_type(table); } void fix_length_and_dec() { max_length= 11; } }; @@ -773,10 +773,6 @@ public: Item_longlong_func(THD *thd, List<Item> &list): Item_int_func(thd, list) { } Item_longlong_func(THD *thd, Item_longlong_func *item) :Item_int_func(thd, item) {} const Type_handler *type_handler() const { return &type_handler_longlong; } - Field *create_tmp_field(bool group, TABLE *table) - { return tmp_table_field_from_field_type(table); } - Field *create_field_for_create_select(TABLE *table) - { return tmp_table_field_from_field_type(table); } }; @@ -843,6 +839,7 @@ public: unsigned_flag= 0; } const char *func_name() const { return "cast_as_signed"; } + const Type_handler *type_handler() const { return &type_handler_longlong; } Field *create_tmp_field(bool group, TABLE *table) { return Item::create_tmp_field(false, table, @@ -1074,6 +1071,13 @@ public: longlong val_int(); const char *func_name() const { return "DIV"; } enum precedence precedence() const { return MUL_PRECEDENCE; } + const Type_handler *type_handler() const + { + // The same condition is repeated in Item::create_tmp_field() + if (max_length > MY_INT32_NUM_DECIMAL_DIGITS - 2) + return &type_handler_longlong; + return &type_handler_long; + } void fix_length_and_dec(); void print(String *str, enum_query_type query_type) { @@ -2095,6 +2099,7 @@ public: Item_int_func(thd) {} Item_func_udf_int(THD *thd, udf_func *udf_arg, List<Item> &list): Item_int_func(thd, list) {} + const Type_handler *type_handler() const { return &type_handler_longlong; } longlong val_int() { DBUG_ASSERT(fixed == 1); return 0; } }; @@ -2106,6 +2111,7 @@ public: Item_int_func(thd) {} Item_func_udf_decimal(THD *thd, udf_func *udf_arg, List<Item> &list): Item_int_func(thd, list) {} + const Type_handler *type_handler() const { return &type_handler_longlong; } my_decimal *val_decimal(my_decimal *) { DBUG_ASSERT(fixed == 1); return 0; } }; diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h index d09a573aa2d..4890a2a7f08 100644 --- a/sql/item_timefunc.h +++ b/sql/item_timefunc.h @@ -1012,11 +1012,6 @@ class Item_extract :public Item_int_func } return true; } - Field *create_tmp_field(bool group, TABLE *table) - { return tmp_table_field_from_field_type(table); } - Field *create_field_for_create_select(TABLE *table) - { return tmp_table_field_from_field_type(table); } - Item *get_copy(THD *thd, MEM_ROOT *mem_root) { return get_item_copy<Item_extract>(thd, mem_root, this); } }; diff --git a/sql/item_xmlfunc.cc b/sql/item_xmlfunc.cc index 90df6e27f6c..86b470eed6f 100644 --- a/sql/item_xmlfunc.cc +++ b/sql/item_xmlfunc.cc @@ -461,13 +461,13 @@ public: }; -class Item_func_xpath_position :public Item_int_func +class Item_func_xpath_position :public Item_long_func { String *pxml; String tmp_value; public: Item_func_xpath_position(THD *thd, Item *a, String *p): - Item_int_func(thd, a), pxml(p) {} + Item_long_func(thd, a), pxml(p) {} const char *func_name() const { return "xpath_position"; } void fix_length_and_dec() { max_length=10; } longlong val_int() @@ -482,13 +482,13 @@ public: }; -class Item_func_xpath_count :public Item_int_func +class Item_func_xpath_count :public Item_long_func { String *pxml; String tmp_value; public: Item_func_xpath_count(THD *thd, Item *a, String *p): - Item_int_func(thd, a), pxml(p) {} + Item_long_func(thd, a), pxml(p) {} const char *func_name() const { return "xpath_count"; } void fix_length_and_dec() { max_length=10; } longlong val_int() |