summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mysql-test/r/func_hybrid_type.result10
-rw-r--r--mysql-test/r/olap.result30
-rw-r--r--mysql-test/r/sp-anchor-row-type-cursor.result21
-rw-r--r--mysql-test/r/view.result2
-rw-r--r--mysql-test/suite/compat/oracle/r/sp-cursor-decl.result22
-rw-r--r--mysql-test/suite/compat/oracle/t/sp-cursor-decl.test21
-rw-r--r--mysql-test/t/func_hybrid_type.test10
-rw-r--r--mysql-test/t/olap.test22
-rw-r--r--mysql-test/t/sp-anchor-row-type-cursor.test22
-rw-r--r--sql/item.h15
-rw-r--r--sql/item_func.h14
-rw-r--r--sql/item_sum.h5
-rw-r--r--sql/item_timefunc.h2
-rw-r--r--sql/sql_select.cc43
14 files changed, 196 insertions, 43 deletions
diff --git a/mysql-test/r/func_hybrid_type.result b/mysql-test/r/func_hybrid_type.result
index a8fd8a2d38a..e5f8af9af28 100644
--- a/mysql-test/r/func_hybrid_type.result
+++ b/mysql-test/r/func_hybrid_type.result
@@ -3547,5 +3547,15 @@ t2 CREATE TABLE `t2` (
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t2, t1;
#
+# MDEV-12875 Wrong VIEW column data type for COALESCE(int_column)
+#
+CREATE TABLE t1 (a INT);
+CREATE OR REPLACE VIEW v1 AS SELECT COALESCE(a) FROM t1;
+DESCRIBE v1;
+Field Type Null Key Default Extra
+COALESCE(a) int(11) YES NULL
+DROP VIEW v1;
+DROP TABLE t1;
+#
# End of 10.3 tests
#
diff --git a/mysql-test/r/olap.result b/mysql-test/r/olap.result
index b10f175b63e..2e06176d292 100644
--- a/mysql-test/r/olap.result
+++ b/mysql-test/r/olap.result
@@ -696,8 +696,8 @@ CREATE VIEW v1 AS
SELECT a, LENGTH(a), COUNT(*) FROM t1 GROUP BY a WITH ROLLUP;
DESC v1;
Field Type Null Key Default Extra
-a bigint(11) YES NULL
-LENGTH(a) bigint(10) YES NULL
+a int(11) YES 0
+LENGTH(a) int(10) YES NULL
COUNT(*) bigint(21) NO 0
SELECT * FROM v1;
a LENGTH(a) COUNT(*)
@@ -766,3 +766,29 @@ b
NULL
DROP TABLE t1, t2;
End of 5.0 tests
+#
+# Start of 10.3 tests
+#
+#
+# MDEV-12886 Different default for INT and BIGINT column in a VIEW for a SELECT with ROLLUP
+#
+CREATE TABLE t1 (a int(11) NOT NULL);
+INSERT INTO t1 VALUES (1),(2);
+CREATE OR REPLACE VIEW v1 AS SELECT a, LENGTH(a), COUNT(*) FROM t1 GROUP BY a WITH ROLLUP;
+DESCRIBE v1;
+Field Type Null Key Default Extra
+a int(11) YES 0
+LENGTH(a) int(10) YES NULL
+COUNT(*) bigint(21) NO 0
+DROP VIEW v1;
+DROP TABLE t1;
+CREATE TABLE t1 (a bigint(11) NOT NULL);
+INSERT INTO t1 VALUES (1),(2);
+CREATE OR REPLACE VIEW v1 AS SELECT a, LENGTH(a), COUNT(*) FROM t1 GROUP BY a WITH ROLLUP;
+DESCRIBE v1;
+Field Type Null Key Default Extra
+a bigint(20) YES 0
+LENGTH(a) int(10) YES NULL
+COUNT(*) bigint(21) NO 0
+DROP VIEW v1;
+DROP TABLE t1;
diff --git a/mysql-test/r/sp-anchor-row-type-cursor.result b/mysql-test/r/sp-anchor-row-type-cursor.result
index dd645a8b636..a2435e17f9f 100644
--- a/mysql-test/r/sp-anchor-row-type-cursor.result
+++ b/mysql-test/r/sp-anchor-row-type-cursor.result
@@ -980,3 +980,24 @@ DROP PROCEDURE p1;
#
# End of MDEV-12461 TYPE OF and ROW TYPE OF anchored data types
#
+#
+# MDEV-12916 Wrong column data type for an INT field of a cursor-anchored ROW variable
+#
+CREATE PROCEDURE p1()
+BEGIN
+DECLARE a INT DEFAULT 10;
+DECLARE cur1 CURSOR FOR SELECT a;
+BEGIN
+DECLARE rec1 ROW TYPE OF cur1;
+CREATE TABLE t1 AS SELECT rec1.a;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+END;
+END;
+$$
+CALL p1();
+Table Create Table
+t1 CREATE TABLE `t1` (
+ `rec1.a` int(11) DEFAULT NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+DROP PROCEDURE p1;
diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result
index 2bb12c3d380..e200af46b87 100644
--- a/mysql-test/r/view.result
+++ b/mysql-test/r/view.result
@@ -2843,7 +2843,7 @@ CREATE TABLE t1 (i int, j int);
CREATE VIEW v1 AS SELECT COALESCE(i,j) FROM t1;
DESCRIBE v1;
Field Type Null Key Default Extra
-COALESCE(i,j) bigint(11) YES NULL
+COALESCE(i,j) int(11) YES NULL
CREATE TABLE t2 SELECT COALESCE(i,j) FROM t1;
DESCRIBE t2;
Field Type Null Key Default Extra
diff --git a/mysql-test/suite/compat/oracle/r/sp-cursor-decl.result b/mysql-test/suite/compat/oracle/r/sp-cursor-decl.result
index 944426deb23..b75b5d5be9d 100644
--- a/mysql-test/suite/compat/oracle/r/sp-cursor-decl.result
+++ b/mysql-test/suite/compat/oracle/r/sp-cursor-decl.result
@@ -263,8 +263,28 @@ rec2.a
11
Table Create Table
t2 CREATE TABLE "t2" (
- "a" bigint(21) DEFAULT NULL,
+ "a" bigint(20) DEFAULT NULL,
"b" varchar(11) DEFAULT NULL,
"c" double DEFAULT NULL
)
DROP PROCEDURE p1;
+#
+# MDEV-12916 Wrong column data type for an INT field of a cursor-anchored ROW variable
+#
+CREATE PROCEDURE p1
+AS
+a INT DEFAULT 10;
+CURSOR cur1 IS SELECT a;
+rec1 cur1%ROWTYPE;
+BEGIN
+CREATE TABLE t1 AS SELECT rec1.a;
+SHOW CREATE TABLE t1;
+DROP TABLE t1;
+END;
+$$
+CALL p1();
+Table Create Table
+t1 CREATE TABLE "t1" (
+ "rec1.a" int(11) DEFAULT NULL
+)
+DROP PROCEDURE p1;
diff --git a/mysql-test/suite/compat/oracle/t/sp-cursor-decl.test b/mysql-test/suite/compat/oracle/t/sp-cursor-decl.test
index dd90cd8b815..21683dd4220 100644
--- a/mysql-test/suite/compat/oracle/t/sp-cursor-decl.test
+++ b/mysql-test/suite/compat/oracle/t/sp-cursor-decl.test
@@ -272,3 +272,24 @@ $$
DELIMITER ;$$
CALL p1();
DROP PROCEDURE p1;
+
+
+--echo #
+--echo # MDEV-12916 Wrong column data type for an INT field of a cursor-anchored ROW variable
+--echo #
+
+DELIMITER $$;
+CREATE PROCEDURE p1
+AS
+ a INT DEFAULT 10;
+ CURSOR cur1 IS SELECT a;
+ rec1 cur1%ROWTYPE;
+BEGIN
+ CREATE TABLE t1 AS SELECT rec1.a;
+ SHOW CREATE TABLE t1;
+ DROP TABLE t1;
+END;
+$$
+DELIMITER ;$$
+CALL p1();
+DROP PROCEDURE p1;
diff --git a/mysql-test/t/func_hybrid_type.test b/mysql-test/t/func_hybrid_type.test
index 0957dfd33ec..7db88b65512 100644
--- a/mysql-test/t/func_hybrid_type.test
+++ b/mysql-test/t/func_hybrid_type.test
@@ -535,6 +535,16 @@ SHOW CREATE TABLE t2;
DROP TABLE t2, t1;
--echo #
+--echo # MDEV-12875 Wrong VIEW column data type for COALESCE(int_column)
+--echo #
+
+CREATE TABLE t1 (a INT);
+CREATE OR REPLACE VIEW v1 AS SELECT COALESCE(a) FROM t1;
+DESCRIBE v1;
+DROP VIEW v1;
+DROP TABLE t1;
+
+--echo #
--echo # End of 10.3 tests
--echo #
diff --git a/mysql-test/t/olap.test b/mysql-test/t/olap.test
index fec5df1a1c7..1b713c5e0f7 100644
--- a/mysql-test/t/olap.test
+++ b/mysql-test/t/olap.test
@@ -404,3 +404,25 @@ SELECT DISTINCT b FROM t1, t2 GROUP BY a, b WITH ROLLUP;
DROP TABLE t1, t2;
--echo End of 5.0 tests
+
+--echo #
+--echo # Start of 10.3 tests
+--echo #
+
+--echo #
+--echo # MDEV-12886 Different default for INT and BIGINT column in a VIEW for a SELECT with ROLLUP
+--echo #
+
+CREATE TABLE t1 (a int(11) NOT NULL);
+INSERT INTO t1 VALUES (1),(2);
+CREATE OR REPLACE VIEW v1 AS SELECT a, LENGTH(a), COUNT(*) FROM t1 GROUP BY a WITH ROLLUP;
+DESCRIBE v1;
+DROP VIEW v1;
+DROP TABLE t1;
+
+CREATE TABLE t1 (a bigint(11) NOT NULL);
+INSERT INTO t1 VALUES (1),(2);
+CREATE OR REPLACE VIEW v1 AS SELECT a, LENGTH(a), COUNT(*) FROM t1 GROUP BY a WITH ROLLUP;
+DESCRIBE v1;
+DROP VIEW v1;
+DROP TABLE t1;
diff --git a/mysql-test/t/sp-anchor-row-type-cursor.test b/mysql-test/t/sp-anchor-row-type-cursor.test
index 8d17e242a50..fe4b55aaf1a 100644
--- a/mysql-test/t/sp-anchor-row-type-cursor.test
+++ b/mysql-test/t/sp-anchor-row-type-cursor.test
@@ -1071,3 +1071,25 @@ DROP PROCEDURE p1;
--echo #
--echo # End of MDEV-12461 TYPE OF and ROW TYPE OF anchored data types
--echo #
+
+
+--echo #
+--echo # MDEV-12916 Wrong column data type for an INT field of a cursor-anchored ROW variable
+--echo #
+
+DELIMITER $$;
+CREATE PROCEDURE p1()
+BEGIN
+ DECLARE a INT DEFAULT 10;
+ DECLARE cur1 CURSOR FOR SELECT a;
+ BEGIN
+ DECLARE rec1 ROW TYPE OF cur1;
+ CREATE TABLE t1 AS SELECT rec1.a;
+ SHOW CREATE TABLE t1;
+ DROP TABLE t1;
+ END;
+END;
+$$
+DELIMITER ;$$
+CALL p1();
+DROP PROCEDURE p1;
diff --git a/sql/item.h b/sql/item.h
index e4113c674ae..05badb1e7e6 100644
--- a/sql/item.h
+++ b/sql/item.h
@@ -636,11 +636,6 @@ protected:
return (null_value= item->get_date_with_conversion(ltime, fuzzydate));
}
- const Type_handler *type_handler_long_or_longlong() const
- {
- return Type_handler::type_handler_long_or_longlong(max_char_length());
- }
-
public:
/*
Cache val_str() into the own buffer, e.g. to evaluate constant
@@ -1655,7 +1650,15 @@ public:
// used in row subselects to get value of elements
virtual void bring_value() {}
- virtual Field *create_tmp_field(bool group, TABLE *table);
+ const Type_handler *type_handler_long_or_longlong() const
+ {
+ return Type_handler::type_handler_long_or_longlong(max_char_length());
+ }
+
+ virtual Field *create_tmp_field(bool group, TABLE *table)
+ {
+ return tmp_table_field_from_field_type(table);
+ }
virtual Item_field *field_for_view_update() { return 0; }
diff --git a/sql/item_func.h b/sql/item_func.h
index 79c0308dae9..e58740e80e3 100644
--- a/sql/item_func.h
+++ b/sql/item_func.h
@@ -169,11 +169,7 @@ public:
void signal_divide_by_null();
friend class udf_handler;
Field *create_field_for_create_select(TABLE *table)
- {
- return result_type() != STRING_RESULT ?
- Item::create_tmp_field(false, table) :
- tmp_table_field_from_field_type(table);
- }
+ { return tmp_table_field_from_field_type(table); }
Item *get_tmp_table_item(THD *thd);
my_decimal *val_decimal(my_decimal *);
@@ -396,10 +392,6 @@ public:
:Item_func(thd, item), Type_handler_hybrid_field_type(item) { }
const Type_handler *type_handler() const
{ return Type_handler_hybrid_field_type::type_handler(); }
- 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); }
Field::geometry_type get_geometry_type() const
{ return Type_geometry_attributes::get_geometry_type(); };
void set_geometry_type(uint type)
@@ -740,10 +732,6 @@ public:
double val_real();
String *val_str(String*str);
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() {}
};
diff --git a/sql/item_sum.h b/sql/item_sum.h
index 14a2fd0c0ec..65306ab6f48 100644
--- a/sql/item_sum.h
+++ b/sql/item_sum.h
@@ -508,10 +508,7 @@ public:
}
virtual void make_unique() { force_copy_fields= TRUE; }
Item *get_tmp_table_item(THD *thd);
- Field *create_tmp_field(bool group, TABLE *table)
- {
- return Item::create_tmp_field(group, table);
- }
+ Field *create_tmp_field(bool group, TABLE *table);
virtual bool collect_outer_ref_processor(void *param);
bool init_sum_func_check(THD *thd);
bool check_sum_func(THD *thd, Item **ref);
diff --git a/sql/item_timefunc.h b/sql/item_timefunc.h
index 2e7142336a4..4cdf7b63158 100644
--- a/sql/item_timefunc.h
+++ b/sql/item_timefunc.h
@@ -533,8 +533,6 @@ public:
bool get_date(MYSQL_TIME *res, ulonglong fuzzy_date) { DBUG_ASSERT(0); return 1; }
my_decimal *val_decimal(my_decimal *decimal_value)
{ return val_decimal_from_date(decimal_value); }
- Field *create_field_for_create_select(TABLE *table)
- { return tmp_table_field_from_field_type(table); }
int save_in_field(Field *field, bool no_conversions)
{ return save_date_in_field(field, no_conversions); }
};
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index a16ff79827f..f14ad7d2970 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -15879,7 +15879,7 @@ Field *Item::create_tmp_field_int(TABLE *table, uint convert_int_length)
}
-Field *Item::create_tmp_field(bool group, TABLE *table)
+Field *Item_sum::create_tmp_field(bool group, TABLE *table)
{
Field *UNINIT_VAR(new_field);
MEM_ROOT *mem_root= table->in_use->mem_root;
@@ -15892,7 +15892,6 @@ Field *Item::create_tmp_field(bool group, TABLE *table)
break;
}
case INT_RESULT:
- return create_tmp_field_int(table, MY_INT32_NUM_DECIMAL_DIGITS - 2);
case TIME_RESULT:
case DECIMAL_RESULT:
case STRING_RESULT:
@@ -15910,6 +15909,22 @@ Field *Item::create_tmp_field(bool group, TABLE *table)
}
+static void create_tmp_field_from_item_finalize(THD *thd,
+ Field *new_field,
+ Item *item,
+ Item ***copy_func,
+ bool modify_item)
+{
+ if (copy_func &&
+ (item->is_result_field() ||
+ (item->real_item()->is_result_field())))
+ *((*copy_func)++) = item; // Save for copy_funcs
+ if (modify_item)
+ item->set_result_field(new_field);
+ if (item->type() == Item::NULL_ITEM)
+ new_field->is_created_from_null_item= TRUE;
+}
+
/**
Create field for temporary table using type of given item.
@@ -15940,16 +15955,9 @@ static Field *create_tmp_field_from_item(THD *thd, Item *item, TABLE *table,
{
Field *UNINIT_VAR(new_field);
DBUG_ASSERT(thd == table->in_use);
- new_field= item->Item::create_tmp_field(false, table);
-
- if (copy_func &&
- (item->is_result_field() ||
- (item->real_item()->is_result_field())))
- *((*copy_func)++) = item; // Save for copy_funcs
- if (modify_item)
- item->set_result_field(new_field);
- if (item->type() == Item::NULL_ITEM)
- new_field->is_created_from_null_item= TRUE;
+ if ((new_field= item->create_tmp_field(false, table)))
+ create_tmp_field_from_item_finalize(thd, new_field, item,
+ copy_func, modify_item);
return new_field;
}
@@ -16024,6 +16032,8 @@ Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
Item::Type orig_type= type;
Item *orig_item= 0;
+ DBUG_ASSERT(thd == table->in_use);
+
if (type != Item::FIELD_ITEM &&
item->real_item()->type() == Item::FIELD_ITEM)
{
@@ -16082,9 +16092,14 @@ Field *create_tmp_field(THD *thd, TABLE *table,Item *item, Item::Type type,
else if (table_cant_handle_bit_fields && field->field->type() ==
MYSQL_TYPE_BIT)
{
+ const Type_handler *handler= item->type_handler_long_or_longlong();
*from_field= field->field;
- result= create_tmp_field_from_item(thd, item, table, copy_func,
- modify_item);
+ if ((result=
+ handler->make_and_init_table_field(&item->name,
+ Record_addr(item->maybe_null),
+ *item, table)))
+ create_tmp_field_from_item_finalize(thd, result, item,
+ copy_func, modify_item);
if (result && modify_item)
field->result_field= result;
}