Commit 90f06818 authored by Alexander Barkov's avatar Alexander Barkov

MDEV-12876 Wrong data type for CREATE..SELECT sp_var

parent 62b62319
......@@ -85,7 +85,7 @@ CREATE TABLE t1 (a INT, b VARCHAR(10), c DOUBLE, d DECIMAL(10));
CALL p1();
Table Create Table
t2 CREATE TABLE `t2` (
`rec.a` bigint(11) DEFAULT NULL,
`rec.a` int(11) DEFAULT NULL,
`rec.b` varchar(10) DEFAULT NULL,
`rec.c` double DEFAULT NULL,
`rec.d` decimal(10,0) DEFAULT NULL
......@@ -114,7 +114,7 @@ CREATE TABLE t1 (a INT, b VARCHAR(10), c DOUBLE, d DECIMAL(10));
CALL p1();
Table Create Table
t2 CREATE TABLE `t2` (
`rec.a` bigint(11) DEFAULT NULL,
`rec.a` int(11) DEFAULT NULL,
`rec.b` varchar(10) DEFAULT NULL,
`rec.c` double DEFAULT NULL,
`rec.d` decimal(10,0) DEFAULT NULL
......@@ -142,7 +142,7 @@ CREATE VIEW v1 AS SELECT * FROM t1;
CALL p1();
Table Create Table
t2 CREATE TABLE `t2` (
`rec.a` bigint(11) DEFAULT NULL,
`rec.a` int(11) DEFAULT NULL,
`rec.b` varchar(10) DEFAULT NULL,
`rec.c` double DEFAULT NULL,
`rec.d` decimal(10,0) DEFAULT NULL
......@@ -171,7 +171,7 @@ CREATE VIEW v1 AS SELECT * FROM t1;
CALL p1();
Table Create Table
t2 CREATE TABLE `t2` (
`rec.a` bigint(11) DEFAULT NULL,
`rec.a` int(11) DEFAULT NULL,
`rec.b` varchar(10) DEFAULT NULL,
`rec.c` double DEFAULT NULL,
`rec.d` decimal(10,0) DEFAULT NULL
......
......@@ -36,7 +36,7 @@ CREATE TABLE t1 (a INT, b VARCHAR(10), c DOUBLE, d DECIMAL(10));
CALL p1();
Table Create Table
t2 CREATE TABLE `t2` (
`rec.a` bigint(11) DEFAULT NULL,
`rec.a` int(11) DEFAULT NULL,
`rec.b` varchar(10) DEFAULT NULL,
`rec.c` double DEFAULT NULL,
`rec.d` decimal(10,0) DEFAULT NULL
......@@ -60,7 +60,7 @@ CREATE TABLE t1 (a INT, b VARCHAR(10), c DOUBLE, d DECIMAL(10));
CALL p1();
Table Create Table
t2 CREATE TABLE `t2` (
`rec.a` bigint(11) DEFAULT NULL,
`rec.a` int(11) DEFAULT NULL,
`rec.b` varchar(10) DEFAULT NULL,
`rec.c` double DEFAULT NULL,
`rec.d` decimal(10,0) DEFAULT NULL
......@@ -85,7 +85,7 @@ CREATE VIEW v1 AS SELECT * FROM t1;
CALL p1();
Table Create Table
t2 CREATE TABLE `t2` (
`rec.a` bigint(11) DEFAULT NULL,
`rec.a` int(11) DEFAULT NULL,
`rec.b` varchar(10) DEFAULT NULL,
`rec.c` double DEFAULT NULL,
`rec.d` decimal(10,0) DEFAULT NULL
......@@ -111,7 +111,7 @@ CREATE VIEW v1 AS SELECT * FROM t1;
CALL p1();
Table Create Table
t2 CREATE TABLE `t2` (
`rec.a` bigint(11) DEFAULT NULL,
`rec.a` int(11) DEFAULT NULL,
`rec.b` varchar(10) DEFAULT NULL,
`rec.c` double DEFAULT NULL,
`rec.d` decimal(10,0) DEFAULT NULL
......
This diff is collapsed.
......@@ -1184,3 +1184,40 @@ CALL vctest();
Warnings:
Warning 1292 Truncated incorrect DOUBLE value: 'string'
DROP PROCEDURE vctest;
#
# Start of 10.3 tests
#
CREATE PROCEDURE p1()
BEGIN
DECLARE i8 TINYINT;
DECLARE i16 SMALLINT;
DECLARE i32 INT;
DECLARE i64 BIGINT;
DECLARE f FLOAT;
DECLARE d DOUBLE;
DECLARE b8 BIT(8);
DECLARE y YEAR;
DECLARE t1 TINYTEXT;
DECLARE t2 TEXT;
DECLARE t3 MEDIUMTEXT;
DECLARE t4 LONGTEXT;
CREATE TABLE t1 AS SELECT i8, i16, i32, i64, f, d, b8, y, t1, t2, t3, t4;
END;
$$
CALL p1;
DESCRIBE t1;
Field Type Null Key Default Extra
i8 tinyint(4) YES NULL
i16 smallint(6) YES NULL
i32 int(11) YES NULL
i64 bigint(20) YES NULL
f float YES NULL
d double YES NULL
b8 bit(8) YES NULL
y year(4) YES NULL
t1 tinytext YES NULL
t2 text YES NULL
t3 mediumtext YES NULL
t4 longtext YES NULL
DROP TABLE t1;
DROP PROCEDURE p1;
......@@ -6469,7 +6469,7 @@ CALL p2(10);
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`v` bigint(11) DEFAULT NULL
`v` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t1;
......@@ -6480,7 +6480,7 @@ Warning 1366 Incorrect integer value: 'text' for column 'v' at row 1
SHOW CREATE TABLE t1;
Table Create Table
t1 CREATE TABLE `t1` (
`v` bigint(11) DEFAULT NULL
`v` int(11) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1
DROP TABLE t1;
......
......@@ -85,7 +85,7 @@ CREATE TABLE t1 (a INT, b VARCHAR(10), c DOUBLE, d DECIMAL(10));
CALL p1();
Table Create Table
t2 CREATE TABLE "t2" (
"rec.a" bigint(11) DEFAULT NULL,
"rec.a" int(11) DEFAULT NULL,
"rec.b" varchar(10) DEFAULT NULL,
"rec.c" double DEFAULT NULL,
"rec.d" decimal(10,0) DEFAULT NULL
......@@ -116,7 +116,7 @@ CREATE TABLE t1 (a INT, b VARCHAR(10), c DOUBLE, d DECIMAL(10));
CALL p1();
Table Create Table
t2 CREATE TABLE "t2" (
"rec.a" bigint(11) DEFAULT NULL,
"rec.a" int(11) DEFAULT NULL,
"rec.b" varchar(10) DEFAULT NULL,
"rec.c" double DEFAULT NULL,
"rec.d" decimal(10,0) DEFAULT NULL
......@@ -146,7 +146,7 @@ CREATE VIEW v1 AS SELECT * FROM t1;
CALL p1();
Table Create Table
t2 CREATE TABLE "t2" (
"rec.a" bigint(11) DEFAULT NULL,
"rec.a" int(11) DEFAULT NULL,
"rec.b" varchar(10) DEFAULT NULL,
"rec.c" double DEFAULT NULL,
"rec.d" decimal(10,0) DEFAULT NULL
......@@ -177,7 +177,7 @@ CREATE VIEW v1 AS SELECT * FROM t1;
CALL p1();
Table Create Table
t2 CREATE TABLE "t2" (
"rec.a" bigint(11) DEFAULT NULL,
"rec.a" int(11) DEFAULT NULL,
"rec.b" varchar(10) DEFAULT NULL,
"rec.c" double DEFAULT NULL,
"rec.d" decimal(10,0) DEFAULT NULL
......
......@@ -1487,3 +1487,31 @@ DELIMITER ;|
CALL vctest();
DROP PROCEDURE vctest;
--echo #
--echo # Start of 10.3 tests
--echo #
DELIMITER $$;
CREATE PROCEDURE p1()
BEGIN
DECLARE i8 TINYINT;
DECLARE i16 SMALLINT;
DECLARE i32 INT;
DECLARE i64 BIGINT;
DECLARE f FLOAT;
DECLARE d DOUBLE;
DECLARE b8 BIT(8);
DECLARE y YEAR;
DECLARE t1 TINYTEXT;
DECLARE t2 TEXT;
DECLARE t3 MEDIUMTEXT;
DECLARE t4 LONGTEXT;
CREATE TABLE t1 AS SELECT i8, i16, i32, i64, f, d, b8, y, t1, t2, t3, t4;
END;
$$
DELIMITER ;$$
CALL p1;
DESCRIBE t1;
DROP TABLE t1;
DROP PROCEDURE p1;
......@@ -1625,7 +1625,9 @@ Item_splocal::Item_splocal(THD *thd, const LEX_CSTRING *sp_var_name,
bool Item_splocal::fix_fields(THD *thd, Item **ref)
{
return fix_fields_from_item(thd, ref, thd->spcont->get_item(m_var_idx));
Item *item= thd->spcont->get_item(m_var_idx);
set_handler(item->type_handler());
return fix_fields_from_item(thd, ref, item);
}
......
......@@ -2281,6 +2281,18 @@ class Item_splocal :public Item_sp_variable,
bool append_for_log(THD *thd, String *str);
Item *get_copy(THD *thd, MEM_ROOT *mem_root) { return 0; }
/*
Override the inherited create_field_for_create_select(),
because we want to preserve the exact data type for:
DECLARE a1 INT;
DECLARE a2 TYPE OF t1.a2;
CREATE TABLE t1 AS SELECT a1, a2;
The inherited implementation would create a column
based on result_type(), which is less exact.
*/
Field *create_field_for_create_select(TABLE *table)
{ return tmp_table_field_from_field_type(table); }
};
......@@ -2312,23 +2324,6 @@ class Item_splocal_with_delayed_data_type: public Item_splocal
:Item_splocal(thd, sp_var_name, sp_var_idx, MYSQL_TYPE_NULL,
pos_in_q, len_in_q)
{ }
bool fix_fields(THD *thd, Item **it)
{
if (Item_splocal::fix_fields(thd, it))
return true;
set_handler(this_item()->type_handler());
return false;
}
/*
Override the inherited create_field_for_create_select(),
because we want to preserve the exact data type for:
DECLARE a t1.a%TYPE;
CREATE TABLE t1 AS SELECT a;
The inherited implementation would create a column
based on result_type(), which is less exact.
*/
Field *create_field_for_create_select(TABLE *table)
{ return tmp_table_field_from_field_type(table); }
};
......
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