From ae5b31fe52e272a2cebbdf9bf8c230d622dc8ec3 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Thu, 4 May 2017 13:17:12 +0400 Subject: [PATCH] A cleanup for MDEV-12619 UNION creates excessive integer column types for integer literals Fixing result set metadata for Item_int to match type_handler(), i.e. MYSQL_TYPE_LONG for small numbers and MYSQL_TYPE_LONGLONG for big numbers. --- mysql-test/r/metadata.result | 96 +++++++++++++++++++++++++++++++++++- mysql-test/t/metadata.test | 45 +++++++++++++++++ sql/item.h | 5 +- sql/sp_head.cc | 2 +- 4 files changed, 144 insertions(+), 4 deletions(-) diff --git a/mysql-test/r/metadata.result b/mysql-test/r/metadata.result index d31b2c5efe0..3ff332e03cc 100644 --- a/mysql-test/r/metadata.result +++ b/mysql-test/r/metadata.result @@ -1,13 +1,105 @@ drop table if exists t1,t2; select 1, 1.0, -1, "hello", NULL; Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr -def 1 8 1 1 N 32897 0 63 +def 1 3 1 1 N 32897 0 63 def 1.0 246 4 3 N 32897 1 63 -def -1 8 2 2 N 32897 0 63 +def -1 3 2 2 N 32897 0 63 def hello 253 5 5 N 1 39 8 def NULL 6 0 0 Y 32896 0 63 1 1.0 -1 hello NULL 1 1.0 -1 hello NULL +SELECT +1 AS c1, +11 AS c2, +111 AS c3, +1111 AS c4, +11111 AS c5, +111111 AS c6, +1111111 AS c7, +11111111 AS c8, +111111111 AS c9, +1111111111 AS c10, +11111111111 AS c11, +111111111111 AS c12, +1111111111111 AS c13, +11111111111111 AS c14, +111111111111111 AS c15, +1111111111111111 AS c16, +11111111111111111 AS c17, +111111111111111111 AS c18, +1111111111111111111 AS c19, +11111111111111111111 AS c20, +111111111111111111111 AS c21; +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def c1 3 1 1 N 32897 0 63 +def c2 3 2 2 N 32897 0 63 +def c3 3 3 3 N 32897 0 63 +def c4 3 4 4 N 32897 0 63 +def c5 3 5 5 N 32897 0 63 +def c6 3 6 6 N 32897 0 63 +def c7 3 7 7 N 32897 0 63 +def c8 3 8 8 N 32897 0 63 +def c9 3 9 9 N 32897 0 63 +def c10 8 10 10 N 32897 0 63 +def c11 8 11 11 N 32897 0 63 +def c12 8 12 12 N 32897 0 63 +def c13 8 13 13 N 32897 0 63 +def c14 8 14 14 N 32897 0 63 +def c15 8 15 15 N 32897 0 63 +def c16 8 16 16 N 32897 0 63 +def c17 8 17 17 N 32897 0 63 +def c18 8 18 18 N 32897 0 63 +def c19 8 19 19 N 32897 0 63 +def c20 8 20 20 N 32929 0 63 +def c21 246 22 21 N 32897 0 63 +c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 c21 +1 11 111 1111 11111 111111 1111111 11111111 111111111 1111111111 11111111111 111111111111 1111111111111 11111111111111 111111111111111 1111111111111111 11111111111111111 111111111111111111 1111111111111111111 11111111111111111111 111111111111111111111 +SELECT +-1 AS c1, +-11 AS c2, +-111 AS c3, +-1111 AS c4, +-11111 AS c5, +-111111 AS c6, +-1111111 AS c7, +-11111111 AS c8, +-111111111 AS c9, +-1111111111 AS c10, +-11111111111 AS c11, +-111111111111 AS c12, +-1111111111111 AS c13, +-11111111111111 AS c14, +-111111111111111 AS c15, +-1111111111111111 AS c16, +-11111111111111111 AS c17, +-111111111111111111 AS c18, +-1111111111111111111 AS c19, +-11111111111111111111 AS c20, +-111111111111111111111 AS c21; +Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr +def c1 3 2 2 N 32897 0 63 +def c2 3 3 3 N 32897 0 63 +def c3 3 4 4 N 32897 0 63 +def c4 3 5 5 N 32897 0 63 +def c5 3 6 6 N 32897 0 63 +def c6 3 7 7 N 32897 0 63 +def c7 3 8 8 N 32897 0 63 +def c8 3 9 9 N 32897 0 63 +def c9 8 10 10 N 32897 0 63 +def c10 8 11 11 N 32897 0 63 +def c11 8 12 12 N 32897 0 63 +def c12 8 13 13 N 32897 0 63 +def c13 8 14 14 N 32897 0 63 +def c14 8 15 15 N 32897 0 63 +def c15 8 16 16 N 32897 0 63 +def c16 8 17 17 N 32897 0 63 +def c17 8 18 18 N 32897 0 63 +def c18 8 19 19 N 32897 0 63 +def c19 8 20 20 N 32897 0 63 +def c20 246 21 21 N 32897 0 63 +def c21 246 22 22 N 32897 0 63 +c1 c2 c3 c4 c5 c6 c7 c8 c9 c10 c11 c12 c13 c14 c15 c16 c17 c18 c19 c20 c21 +-1 -11 -111 -1111 -11111 -111111 -1111111 -11111111 -111111111 -1111111111 -11111111111 -111111111111 -1111111111111 -11111111111111 -111111111111111 -1111111111111111 -11111111111111111 -111111111111111111 -1111111111111111111 -11111111111111111111 -111111111111111111111 create table t1 (a tinyint, b smallint, c mediumint, d int, e bigint, f float(3,2), g double(4,3), h decimal(5,4), i year, j date, k timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, l datetime, m enum('a','b'), n set('a','b'), o char(10)); select * from t1; Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr diff --git a/mysql-test/t/metadata.test b/mysql-test/t/metadata.test index f5ed65cf7e2..60c7470cb67 100644 --- a/mysql-test/t/metadata.test +++ b/mysql-test/t/metadata.test @@ -14,6 +14,51 @@ drop table if exists t1,t2; # select 1, 1.0, -1, "hello", NULL; +SELECT + 1 AS c1, + 11 AS c2, + 111 AS c3, + 1111 AS c4, + 11111 AS c5, + 111111 AS c6, + 1111111 AS c7, + 11111111 AS c8, + 111111111 AS c9, + 1111111111 AS c10, + 11111111111 AS c11, + 111111111111 AS c12, + 1111111111111 AS c13, + 11111111111111 AS c14, + 111111111111111 AS c15, + 1111111111111111 AS c16, + 11111111111111111 AS c17, + 111111111111111111 AS c18, + 1111111111111111111 AS c19, + 11111111111111111111 AS c20, + 111111111111111111111 AS c21; + +SELECT + -1 AS c1, + -11 AS c2, + -111 AS c3, + -1111 AS c4, + -11111 AS c5, + -111111 AS c6, + -1111111 AS c7, + -11111111 AS c8, + -111111111 AS c9, + -1111111111 AS c10, + -11111111111 AS c11, + -111111111111 AS c12, + -1111111111111 AS c13, + -11111111111111 AS c14, + -111111111111111 AS c15, + -1111111111111111 AS c16, + -11111111111111111 AS c17, + -111111111111111111 AS c18, + -1111111111111111111 AS c19, + -11111111111111111111 AS c20, + -111111111111111111111 AS c21; create table t1 (a tinyint, b smallint, c mediumint, d int, e bigint, f float(3,2), g double(4,3), h decimal(5,4), i year, j date, k timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, l datetime, m enum('a','b'), n set('a','b'), o char(10)); select * from t1; diff --git a/sql/item.h b/sql/item.h index 0e004571395..6cdaed84388 100644 --- a/sql/item.h +++ b/sql/item.h @@ -3151,7 +3151,10 @@ public: Item_int(THD *thd, const char *str_arg, uint length=64); enum Type type() const { return INT_ITEM; } enum Item_result result_type () const { return INT_RESULT; } - enum_field_types field_type() const { return MYSQL_TYPE_LONGLONG; } + enum_field_types field_type() const + { + return Item_int::type_handler()->field_type(); + } const Type_handler *type_handler() const { // The same condition is repeated in Item::create_tmp_field() diff --git a/sql/sp_head.cc b/sql/sp_head.cc index eea93f53b01..fc4c05a670b 100644 --- a/sql/sp_head.cc +++ b/sql/sp_head.cc @@ -2985,7 +2985,7 @@ sp_head::show_routine_code(THD *thd) push_warning(thd, Sql_condition::WARN_LEVEL_WARN, ER_UNKNOWN_ERROR, tmp); } protocol->prepare_for_resend(); - protocol->store((longlong)ip); + protocol->store_long(ip); buffer.set("", 0, system_charset_info); i->print(&buffer);