Commit 8c479820 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-12856 Wrong .. metadata for DIV + MDEV-12857..errors on CREATE..SELECT..DIV

This is a joint patch for:

MDEV-12856 Wrong result set metadata for DIV
MDEV-12857 Out-of-range errors on CREATE..SELECT 2222222222 DIV 1
parent a8caa8e0
......@@ -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;
......@@ -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
......@@ -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;
......@@ -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
......@@ -206,10 +206,6 @@ class Item_bool_func :public Item_int_func
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; }
......
......@@ -738,7 +738,11 @@ class Item_int_func :public Item_func
{ 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 @@ class Item_long_func: public Item_int_func
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 @@ class Item_longlong_func: public Item_int_func
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 @@ class Item_func_signed :public Item_int_func
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 @@ class Item_func_int_div :public Item_int_func
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 @@ class Item_func_udf_int :public Item_int_func
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 @@ class Item_func_udf_decimal :public Item_int_func
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; }
};
......
......@@ -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); }
};
......
......@@ -461,13 +461,13 @@ class Item_nodeset_context_cache :public Item_nodeset_func
};
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 @@ class Item_func_xpath_position :public Item_int_func
};
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()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment