From c6efbc543d6fb3004f320ef9d02542a4692ca88a Mon Sep 17 00:00:00 2001 From: Alexey Botchkov Date: Tue, 30 Jul 2019 21:57:48 +0400 Subject: [PATCH 01/14] MDEV-17544 No warning when trying to name a primary key constraint. Warning added. --- mysql-test/main/create.result | 4 ++++ mysql-test/main/create.test | 7 +++++++ mysql-test/main/ctype_collate.result | 2 ++ mysql-test/main/ctype_latin2_ch.result | 2 ++ mysql-test/main/gis.result | 4 ++++ mysql-test/main/join_cache.result | 2 ++ mysql-test/main/system_mysql_db_fix50117.test | 16 ++++++++-------- .../suite/binlog_encryption/multisource.result | 2 ++ mysql-test/suite/galera/r/GAL-382.result | 4 ++++ .../innodb/r/innodb-index-online-fk.result | 6 ++++++ .../innodb/r/innodb-virtual-columns.result | 8 ++++++++ .../suite/innodb/r/innodb_bug51378.result | 2 ++ .../suite/innodb/r/innodb_bug60229.result | 6 ++++++ mysql-test/suite/innodb_gis/r/1.result | 4 ++++ mysql-test/suite/innodb_gis/r/gis.result | 4 ++++ mysql-test/suite/innodb_zip/r/page_size.result | 4 ++++ .../r/prefix_index_liftedlimit.result | 4 ++++ .../suite/multi_source/multisource.result | 2 ++ .../parts/r/alter_data_directory_innodb.result | 4 ++++ mysql-test/suite/rpl/r/rpl_blackhole.result | 2 ++ .../rpl/r/rpl_blackhole_row_annotate.result | 2 ++ mysql-test/suite/versioning/r/online.result | 4 +++- mysql-test/suite/versioning/r/trx_id.result | 4 +++- scripts/mysql_system_tables.sql | 18 +++++++++--------- sql/sql_table.cc | 11 +++++++++++ ...index_multiple_column_select_varchar.result | 2 ++ .../rocksdb/r/add_index_inplace.result | 2 ++ .../rocksdb/r/index_key_block_size.result | 2 ++ 28 files changed, 115 insertions(+), 19 deletions(-) diff --git a/mysql-test/main/create.result b/mysql-test/main/create.result index fd017c0967b..03f36c801e1 100644 --- a/mysql-test/main/create.result +++ b/mysql-test/main/create.result @@ -2093,3 +2093,7 @@ create table t1 (i int, j int, key(i), key(i)) as select 1 as i, 2 as j; Warnings: Note 1831 Duplicate index `i_2`. This is deprecated and will be disallowed in a future release drop table t1; +CREATE TABLE t1 ( id1 INT, id2 INT, CONSTRAINT `foo` PRIMARY KEY (id1), CONSTRAINT `bar` UNIQUE KEY(id2)); +Warnings: +Warning 1280 Name 'foo' ignored for PRIMARY key. +DROP TABLE t1; diff --git a/mysql-test/main/create.test b/mysql-test/main/create.test index af5c427852c..9cd3d9909f0 100644 --- a/mysql-test/main/create.test +++ b/mysql-test/main/create.test @@ -1941,3 +1941,10 @@ create table t1; # create table t1 (i int, j int, key(i), key(i)) as select 1 as i, 2 as j; drop table t1; + +# +# MDEV-17544 No warning when trying to name a primary key constraint. +# +CREATE TABLE t1 ( id1 INT, id2 INT, CONSTRAINT `foo` PRIMARY KEY (id1), CONSTRAINT `bar` UNIQUE KEY(id2)); +DROP TABLE t1; + diff --git a/mysql-test/main/ctype_collate.result b/mysql-test/main/ctype_collate.result index 5e8c5adac8f..93bf07908b5 100644 --- a/mysql-test/main/ctype_collate.result +++ b/mysql-test/main/ctype_collate.result @@ -732,6 +732,8 @@ CREATE TABLE t1 ( b LONGTEXT CHARACTER SET "latin1" COLLATE "latin1_bin", PRIMARY KEY b (b(32)) ); +Warnings: +Warning 1280 Name 'b' ignored for PRIMARY key. INSERT INTO t1 (b) VALUES ('a'), (_binary 0x1), (_binary 0x0), (''); explain select hex(b) from t1 force index (PRIMARY) where b<'zzz'; diff --git a/mysql-test/main/ctype_latin2_ch.result b/mysql-test/main/ctype_latin2_ch.result index a396bc77fb6..962c29f7ab4 100644 --- a/mysql-test/main/ctype_latin2_ch.result +++ b/mysql-test/main/ctype_latin2_ch.result @@ -10,6 +10,8 @@ tt char(255) not null insert into t1 values (1,'Aa'); insert into t1 values (2,'Aas'); alter table t1 add primary key aaa(tt); +Warnings: +Warning 1280 Name 'aaa' ignored for PRIMARY key. select * from t1 where tt like 'Aa%'; id tt 1 Aa diff --git a/mysql-test/main/gis.result b/mysql-test/main/gis.result index b154df24585..3c9446b41a3 100644 --- a/mysql-test/main/gis.result +++ b/mysql-test/main/gis.result @@ -816,11 +816,15 @@ POINT(1 1) drop function fn3; create table t1(pt POINT); alter table t1 add primary key pti(pt); +Warnings: +Warning 1280 Name 'pti' ignored for PRIMARY key. drop table t1; create table t1(pt GEOMETRY); alter table t1 add primary key pti(pt); ERROR 42000: BLOB/TEXT column 'pt' used in key specification without a key length alter table t1 add primary key pti(pt(20)); +Warnings: +Warning 1280 Name 'pti' ignored for PRIMARY key. drop table t1; create table t1 select GeomFromText('point(1 1)'); desc t1; diff --git a/mysql-test/main/join_cache.result b/mysql-test/main/join_cache.result index 256a6eda97e..9bb64c0b32c 100644 --- a/mysql-test/main/join_cache.result +++ b/mysql-test/main/join_cache.result @@ -3103,6 +3103,8 @@ CREATE TABLE t2 ( a2 int, b2 int, filler2 char(64) default ' ', PRIMARY KEY idx(a2,b2,filler2) ) ; +Warnings: +Warning 1280 Name 'idx' ignored for PRIMARY key. CREATE TABLE t3 (b3 int, c3 int, INDEX idx(b3)); INSERT INTO t1(a1) VALUES (4), (7), (1), (9), (8), (5), (3), (6), (2); diff --git a/mysql-test/main/system_mysql_db_fix50117.test b/mysql-test/main/system_mysql_db_fix50117.test index f8bef3da162..d7c825817cb 100644 --- a/mysql-test/main/system_mysql_db_fix50117.test +++ b/mysql-test/main/system_mysql_db_fix50117.test @@ -27,13 +27,13 @@ use test; # create system tables as in mysql-5.1.17 -CREATE TABLE IF NOT EXISTS db ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Event_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Trigger_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, PRIMARY KEY Host (Host,Db,User), KEY User (User) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Database privileges'; +CREATE TABLE IF NOT EXISTS db ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Event_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Trigger_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, PRIMARY KEY (Host,Db,User), KEY User (User) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Database privileges'; -CREATE TABLE IF NOT EXISTS host ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Trigger_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, PRIMARY KEY Host (Host,Db) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Host privileges; Merged with database privileges'; +CREATE TABLE IF NOT EXISTS host ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Trigger_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, PRIMARY KEY (Host,Db) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Host privileges; Merged with database privileges'; -CREATE TABLE IF NOT EXISTS user ( Host char(60) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Password char(41) character set latin1 collate latin1_bin DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Reload_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Shutdown_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Process_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, File_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_db_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Super_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Repl_slave_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Repl_client_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_user_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Event_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Trigger_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, ssl_type enum('','ANY','X509', 'SPECIFIED') COLLATE utf8_general_ci DEFAULT '' NOT NULL, ssl_cipher BLOB NOT NULL, x509_issuer BLOB NOT NULL, x509_subject BLOB NOT NULL, max_questions int(11) unsigned DEFAULT 0 NOT NULL, max_updates int(11) unsigned DEFAULT 0 NOT NULL, max_connections int(11) unsigned DEFAULT 0 NOT NULL, max_user_connections int(11) unsigned DEFAULT 0 NOT NULL, PRIMARY KEY Host (Host,User) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Users and global privileges'; +CREATE TABLE IF NOT EXISTS user ( Host char(60) binary DEFAULT '' NOT NULL, User char(16) binary DEFAULT '' NOT NULL, Password char(41) character set latin1 collate latin1_bin DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Reload_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Shutdown_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Process_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, File_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_db_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Super_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Repl_slave_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Repl_client_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_user_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Event_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Trigger_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, ssl_type enum('','ANY','X509', 'SPECIFIED') COLLATE utf8_general_ci DEFAULT '' NOT NULL, ssl_cipher BLOB NOT NULL, x509_issuer BLOB NOT NULL, x509_subject BLOB NOT NULL, max_questions int(11) unsigned DEFAULT 0 NOT NULL, max_updates int(11) unsigned DEFAULT 0 NOT NULL, max_connections int(11) unsigned DEFAULT 0 NOT NULL, max_user_connections int(11) unsigned DEFAULT 0 NOT NULL, PRIMARY KEY (Host,User) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Users and global privileges'; CREATE TABLE IF NOT EXISTS func ( name char(64) binary DEFAULT '' NOT NULL, ret tinyint(1) DEFAULT '0' NOT NULL, dl char(128) DEFAULT '' NOT NULL, type enum ('function','aggregate') COLLATE utf8_general_ci NOT NULL, PRIMARY KEY (name) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='User defined functions'; @@ -62,19 +62,19 @@ CREATE TABLE IF NOT EXISTS help_relation ( help_topic_id int unsigned not null r CREATE TABLE IF NOT EXISTS help_keyword ( help_keyword_id int unsigned not null, name char(64) not null, primary key (help_keyword_id), unique index (name) ) engine=MyISAM CHARACTER SET utf8 comment='help keywords'; -CREATE TABLE IF NOT EXISTS time_zone_name ( Name char(64) NOT NULL, Time_zone_id int unsigned NOT NULL, PRIMARY KEY Name (Name) ) engine=MyISAM CHARACTER SET utf8 comment='Time zone names'; +CREATE TABLE IF NOT EXISTS time_zone_name ( Name char(64) NOT NULL, Time_zone_id int unsigned NOT NULL, PRIMARY KEY (Name) ) engine=MyISAM CHARACTER SET utf8 comment='Time zone names'; -CREATE TABLE IF NOT EXISTS time_zone ( Time_zone_id int unsigned NOT NULL auto_increment, Use_leap_seconds enum('Y','N') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, PRIMARY KEY TzId (Time_zone_id) ) engine=MyISAM CHARACTER SET utf8 comment='Time zones'; +CREATE TABLE IF NOT EXISTS time_zone ( Time_zone_id int unsigned NOT NULL auto_increment, Use_leap_seconds enum('Y','N') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, PRIMARY KEY (Time_zone_id) ) engine=MyISAM CHARACTER SET utf8 comment='Time zones'; -CREATE TABLE IF NOT EXISTS time_zone_transition ( Time_zone_id int unsigned NOT NULL, Transition_time bigint signed NOT NULL, Transition_type_id int unsigned NOT NULL, PRIMARY KEY TzIdTranTime (Time_zone_id, Transition_time) ) engine=MyISAM CHARACTER SET utf8 comment='Time zone transitions'; +CREATE TABLE IF NOT EXISTS time_zone_transition ( Time_zone_id int unsigned NOT NULL, Transition_time bigint signed NOT NULL, Transition_type_id int unsigned NOT NULL, PRIMARY KEY (Time_zone_id, Transition_time) ) engine=MyISAM CHARACTER SET utf8 comment='Time zone transitions'; -CREATE TABLE IF NOT EXISTS time_zone_transition_type ( Time_zone_id int unsigned NOT NULL, Transition_type_id int unsigned NOT NULL, Offset int signed DEFAULT 0 NOT NULL, Is_DST tinyint unsigned DEFAULT 0 NOT NULL, Abbreviation char(8) DEFAULT '' NOT NULL, PRIMARY KEY TzIdTrTId (Time_zone_id, Transition_type_id) ) engine=MyISAM CHARACTER SET utf8 comment='Time zone transition types'; +CREATE TABLE IF NOT EXISTS time_zone_transition_type ( Time_zone_id int unsigned NOT NULL, Transition_type_id int unsigned NOT NULL, Offset int signed DEFAULT 0 NOT NULL, Is_DST tinyint unsigned DEFAULT 0 NOT NULL, Abbreviation char(8) DEFAULT '' NOT NULL, PRIMARY KEY (Time_zone_id, Transition_type_id) ) engine=MyISAM CHARACTER SET utf8 comment='Time zone transition types'; -CREATE TABLE IF NOT EXISTS time_zone_leap_second ( Transition_time bigint signed NOT NULL, Correction int signed NOT NULL, PRIMARY KEY TranTime (Transition_time) ) engine=MyISAM CHARACTER SET utf8 comment='Leap seconds information for time zones'; +CREATE TABLE IF NOT EXISTS time_zone_leap_second ( Transition_time bigint signed NOT NULL, Correction int signed NOT NULL, PRIMARY KEY (Transition_time) ) engine=MyISAM CHARACTER SET utf8 comment='Leap seconds information for time zones'; CREATE TABLE IF NOT EXISTS proc ( db char(64) collate utf8_bin DEFAULT '' NOT NULL, name char(64) DEFAULT '' NOT NULL, type enum('FUNCTION','PROCEDURE') NOT NULL, specific_name char(64) DEFAULT '' NOT NULL, language enum('SQL') DEFAULT 'SQL' NOT NULL, sql_data_access enum('CONTAINS_SQL', 'NO_SQL', 'READS_SQL_DATA', 'MODIFIES_SQL_DATA' ) DEFAULT 'CONTAINS_SQL' NOT NULL, is_deterministic enum('YES','NO') DEFAULT 'NO' NOT NULL, security_type enum('INVOKER','DEFINER') DEFAULT 'DEFINER' NOT NULL, param_list blob NOT NULL, returns char(64) DEFAULT '' NOT NULL, body longblob NOT NULL, definer char(77) collate utf8_bin DEFAULT '' NOT NULL, created timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, modified timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', sql_mode set( 'REAL_AS_FLOAT', 'PIPES_AS_CONCAT', 'ANSI_QUOTES', 'IGNORE_SPACE', 'NOT_USED', 'ONLY_FULL_GROUP_BY', 'NO_UNSIGNED_SUBTRACTION', 'NO_DIR_IN_CREATE', 'POSTGRESQL', 'ORACLE', 'MSSQL', 'DB2', 'MAXDB', 'NO_KEY_OPTIONS', 'NO_TABLE_OPTIONS', 'NO_FIELD_OPTIONS', 'MYSQL323', 'MYSQL40', 'ANSI', 'NO_AUTO_VALUE_ON_ZERO', 'NO_BACKSLASH_ESCAPES', 'STRICT_TRANS_TABLES', 'STRICT_ALL_TABLES', 'NO_ZERO_IN_DATE', 'NO_ZERO_DATE', 'INVALID_DATES', 'ERROR_FOR_DIVISION_BY_ZERO', 'TRADITIONAL', 'NO_AUTO_CREATE_USER', 'HIGH_NOT_PRECEDENCE' ) DEFAULT '' NOT NULL, comment char(64) collate utf8_bin DEFAULT '' NOT NULL, PRIMARY KEY (db,name,type) ) engine=MyISAM character set utf8 comment='Stored Procedures'; diff --git a/mysql-test/suite/binlog_encryption/multisource.result b/mysql-test/suite/binlog_encryption/multisource.result index d99a377f0c5..928c9799854 100644 --- a/mysql-test/suite/binlog_encryption/multisource.result +++ b/mysql-test/suite/binlog_encryption/multisource.result @@ -47,6 +47,8 @@ drop database if exists db1; create database db1; use db1; create table t1 (i int auto_increment, f1 varchar(16), primary key pk (i,f1)) engine=MyISAM; +Warnings: +Warning 1280 Name 'pk' ignored for PRIMARY key. insert into t1 (f1) values ('one'),('two'); connection slave; select * from db1.t1; diff --git a/mysql-test/suite/galera/r/GAL-382.result b/mysql-test/suite/galera/r/GAL-382.result index fb7c229bd56..c16c46d2e58 100644 --- a/mysql-test/suite/galera/r/GAL-382.result +++ b/mysql-test/suite/galera/r/GAL-382.result @@ -1,7 +1,11 @@ connection node_1; create table t1 (i int, j int, k int, primary key pk(i)) engine=innodb; +Warnings: +Warning 1280 Name 'pk' ignored for PRIMARY key. insert into t1 values (1, 1, 1), (2, 2, 2), (3, 3, 3); create table t2 (i int, j int, k int, primary key pk(i, j, k), index idx(i, k, j)) engine=innodb; +Warnings: +Warning 1280 Name 'pk' ignored for PRIMARY key. replace into t2 (i, j, k) select /*!99997 */ i, k, j from t1; DROP TABLE t1; DROP TABLE t2; diff --git a/mysql-test/suite/innodb/r/innodb-index-online-fk.result b/mysql-test/suite/innodb/r/innodb-index-online-fk.result index 47fc8e8b840..854afd95aaf 100644 --- a/mysql-test/suite/innodb/r/innodb-index-online-fk.result +++ b/mysql-test/suite/innodb/r/innodb-index-online-fk.result @@ -326,6 +326,8 @@ ALTER TABLE child ADD PRIMARY KEY idx (a3), CHANGE a1 a3 INT, ADD CONSTRAINT fk_1 FOREIGN KEY (a2) REFERENCES parent(b) ON DELETE SET NULL ON UPDATE CASCADE, ALGORITHM = INPLACE; +Warnings: +Warning 1280 Name 'idx' ignored for PRIMARY key. SELECT * FROM INFORMATION_SCHEMA.INNODB_SYS_FOREIGN; ID FOR_NAME REF_NAME N_COLS TYPE test/fk_1 test/child test/parent 1 6 @@ -363,6 +365,8 @@ ALTER TABLE child ADD PRIMARY KEY idx (a1), ADD CONSTRAINT fk_1 FOREIGN KEY (a2) REFERENCES parent(b) ON DELETE SET NULL ON UPDATE CASCADE, ALGORITHM = INPLACE; +Warnings: +Warning 1280 Name 'idx' ignored for PRIMARY key. SELECT * from information_schema.INNODB_SYS_FOREIGN; ID FOR_NAME REF_NAME N_COLS TYPE test/fk_1 test/child test/parent 1 6 @@ -556,6 +560,8 @@ ADD CONSTRAINT fk_new_1 FOREIGN KEY (a1) REFERENCES parent(b), ADD CONSTRAINT fk_new_2 FOREIGN KEY (a2) REFERENCES parent(a), ADD CONSTRAINT fk_new_3 FOREIGN KEY (a3) REFERENCES parent(a), ALGORITHM = INPLACE; +Warnings: +Warning 1280 Name 'idx' ignored for PRIMARY key. SHOW CREATE TABLE child; Table Create Table child CREATE TABLE `child` ( diff --git a/mysql-test/suite/innodb/r/innodb-virtual-columns.result b/mysql-test/suite/innodb/r/innodb-virtual-columns.result index bf21e352681..4b2df7eb287 100644 --- a/mysql-test/suite/innodb/r/innodb-virtual-columns.result +++ b/mysql-test/suite/innodb/r/innodb-virtual-columns.result @@ -6,6 +6,8 @@ wdraw_rsn varchar(4) NOT NULL DEFAULT '', admit_term char(4) NOT NULL DEFAULT '', CONSTRAINT gso_grad_supr_pky PRIMARY KEY (uw_id, term) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +Warnings: +Warning 1280 Name 'gso_grad_supr_pky' ignored for PRIMARY key. INSERT INTO `gso_grad_supr` VALUES ('1031',2,'CSM','','1009'); INSERT INTO `gso_grad_supr` VALUES ('1035',2,'CSM','ACAD','1009'); CREATE TABLE IF NOT EXISTS grad_degree ( @@ -23,6 +25,8 @@ deg_start_term char(4) NOT NULL DEFAULT '' COMMENT 'Educated guess at the beginn deg_as_of_term char(4) NOT NULL COMMENT 'In most cases also end term', CONSTRAINT grad_degree_stu_plan_admit_pky PRIMARY KEY (student_id, plan, admit_term) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +Warnings: +Warning 1280 Name 'grad_degree_stu_plan_admit_pky' ignored for PRIMARY key. SHOW CREATE TABLE grad_degree; Table Create Table grad_degree CREATE TABLE `grad_degree` ( @@ -129,6 +133,8 @@ deg_start_term char(4) NOT NULL DEFAULT '' COMMENT 'Educated guess at the beginn deg_as_of_term char(4) NOT NULL COMMENT 'In most cases also end term', CONSTRAINT grad_degree_stu_plan_admit_pky PRIMARY KEY (student_id, plan, admit_term) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +Warnings: +Warning 1280 Name 'grad_degree_stu_plan_admit_pky' ignored for PRIMARY key. SHOW CREATE TABLE grad_degree; Table Create Table grad_degree CREATE TABLE `grad_degree` ( @@ -263,6 +269,8 @@ deg_start_term char(4) NOT NULL DEFAULT '' COMMENT 'Educated guess at the beginn deg_as_of_term char(4) NOT NULL COMMENT 'In most cases also end term', CONSTRAINT grad_degree_stu_plan_admit_pky PRIMARY KEY (student_id, plan, admit_term) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; +Warnings: +Warning 1280 Name 'grad_degree_stu_plan_admit_pky' ignored for PRIMARY key. SHOW CREATE TABLE grad_degree; Table Create Table grad_degree CREATE TABLE `grad_degree` ( diff --git a/mysql-test/suite/innodb/r/innodb_bug51378.result b/mysql-test/suite/innodb/r/innodb_bug51378.result index 532fd703af6..2ffd533279b 100644 --- a/mysql-test/suite/innodb/r/innodb_bug51378.result +++ b/mysql-test/suite/innodb/r/innodb_bug51378.result @@ -28,6 +28,8 @@ bug51378 CREATE TABLE `bug51378` ( UNIQUE KEY `idx2` (`col1`,`col2`(31)) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 alter table bug51378 add primary key idx3(col1, col2(31)); +Warnings: +Warning 1280 Name 'idx3' ignored for PRIMARY key. SHOW CREATE TABLE bug51378; Table Create Table bug51378 CREATE TABLE `bug51378` ( diff --git a/mysql-test/suite/innodb/r/innodb_bug60229.result b/mysql-test/suite/innodb/r/innodb_bug60229.result index a3971876193..588f3855764 100644 --- a/mysql-test/suite/innodb/r/innodb_bug60229.result +++ b/mysql-test/suite/innodb/r/innodb_bug60229.result @@ -4,6 +4,8 @@ DOB VARCHAR(50) NOT NULL, NAME NVARCHAR(255) NOT NULL, CONSTRAINT PK_PERSON PRIMARY KEY (PERSON_ID, DOB) )Engine=InnoDB; +Warnings: +Warning 1280 Name 'PK_PERSON' ignored for PRIMARY key. CREATE TABLE PHOTO ( PERSON_ID VARCHAR(50) NOT NULL, DOB VARCHAR(50) NOT NULL, @@ -11,6 +13,8 @@ PHOTO_DETAILS VARCHAR(50) NULL, CONSTRAINT PK_PHOTO PRIMARY KEY (PERSON_ID, DOB), CONSTRAINT FK_PHOTO_2_PERSON FOREIGN KEY (PERSON_ID, DOB) REFERENCES PERSON (PERSON_ID, DOB) )Engine=InnoDB; +Warnings: +Warning 1280 Name 'PK_PHOTO' ignored for PRIMARY key. CREATE TABLE ADDRESS ( PERSON_ID VARCHAR(50) NOT NULL, DOB VARCHAR(50) NOT NULL, @@ -19,6 +23,8 @@ ADDRESS_DETAILS NVARCHAR(250) NULL, CONSTRAINT PK_ADDRESS PRIMARY KEY (PERSON_ID, DOB, ADDRESS_ID), CONSTRAINT FK_ADDRESS_2_PERSON FOREIGN KEY (PERSON_ID, DOB) REFERENCES PERSON (PERSON_ID, DOB) ON DELETE CASCADE )Engine=InnoDB; +Warnings: +Warning 1280 Name 'PK_ADDRESS' ignored for PRIMARY key. INSERT INTO PERSON VALUES("10", "11011999", "John"); INSERT INTO PHOTO VALUES("10", "11011999", "new photo"); DROP TABLE PHOTO; diff --git a/mysql-test/suite/innodb_gis/r/1.result b/mysql-test/suite/innodb_gis/r/1.result index 84e7bec53cd..bb99ba6fca4 100644 --- a/mysql-test/suite/innodb_gis/r/1.result +++ b/mysql-test/suite/innodb_gis/r/1.result @@ -796,11 +796,15 @@ POINT(1 1) drop function fn3; create table t1(pt POINT); alter table t1 add primary key pti(pt); +Warnings: +Warning 1280 Name 'pti' ignored for PRIMARY key. drop table t1; create table t1(pt GEOMETRY); alter table t1 add primary key pti(pt); ERROR 42000: BLOB/TEXT column 'pt' used in key specification without a key length alter table t1 add primary key pti(pt(20)); +Warnings: +Warning 1280 Name 'pti' ignored for PRIMARY key. drop table t1; create table t1 select ST_GeomFromText('point(1 1)'); desc t1; diff --git a/mysql-test/suite/innodb_gis/r/gis.result b/mysql-test/suite/innodb_gis/r/gis.result index 65d1e940cd3..eb5a3d100c1 100644 --- a/mysql-test/suite/innodb_gis/r/gis.result +++ b/mysql-test/suite/innodb_gis/r/gis.result @@ -792,11 +792,15 @@ POINT(1 1) drop function fn3; create table t1(pt POINT); alter table t1 add primary key pti(pt); +Warnings: +Warning 1280 Name 'pti' ignored for PRIMARY key. drop table t1; create table t1(pt GEOMETRY); alter table t1 add primary key pti(pt); ERROR 42000: BLOB/TEXT column 'pt' used in key specification without a key length alter table t1 add primary key pti(pt(20)); +Warnings: +Warning 1280 Name 'pti' ignored for PRIMARY key. drop table t1; create table t1 select ST_GeomFromText('point(1 1)'); desc t1; diff --git a/mysql-test/suite/innodb_zip/r/page_size.result b/mysql-test/suite/innodb_zip/r/page_size.result index 85ff027781e..3cf6e7a7a58 100644 --- a/mysql-test/suite/innodb_zip/r/page_size.result +++ b/mysql-test/suite/innodb_zip/r/page_size.result @@ -515,6 +515,8 @@ pk09,pk10,pk11,pk12,pk13,pk14,pk15,pk16), KEY pk(sk01,sk02,sk03,sk04,sk05,sk06,sk07,sk08, sk09,sk10,sk11,sk12,sk13,sk14,sk15,sk16)) ROW_FORMAT=Redundant ENGINE=InnoDB; +Warnings: +Warning 1280 Name 'pk' ignored for PRIMARY key. SET @r = repeat('a', 48); INSERT INTO t1 VALUES(@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r, @r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r); @@ -546,6 +548,8 @@ pk09,pk10,pk11,pk12,pk13,pk14,pk15,pk16), KEY pk(sk01,sk02,sk03,sk04,sk05,sk06,sk07,sk08, sk09,sk10,sk11,sk12,sk13,sk14,sk15,sk16)) ROW_FORMAT=Compressed KEY_BLOCK_SIZE=4 ENGINE=InnoDB; +Warnings: +Warning 1280 Name 'pk' ignored for PRIMARY key. SET @r = repeat('a', 48); INSERT INTO t1 VALUES(@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r, @r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r,@r); diff --git a/mysql-test/suite/innodb_zip/r/prefix_index_liftedlimit.result b/mysql-test/suite/innodb_zip/r/prefix_index_liftedlimit.result index 96e51e506f2..f2bbd86e9c8 100644 --- a/mysql-test/suite/innodb_zip/r/prefix_index_liftedlimit.result +++ b/mysql-test/suite/innodb_zip/r/prefix_index_liftedlimit.result @@ -1070,6 +1070,8 @@ CREATE TABLE worklog5743 ( col_1_varchar VARCHAR (4000) , col_2_varchar VARCHAR (4000) , PRIMARY KEY `prefix_primary` (col_1_varchar(3072)) ) ROW_FORMAT=DYNAMIC, engine = innodb; +Warnings: +Warning 1280 Name 'prefix_primary' ignored for PRIMARY key. INSERT INTO worklog5743 VALUES(REPEAT("a", 4000) , REPEAT("o", 4000)); CREATE INDEX prefix_idx ON worklog5743(col_1_varchar (3072)); INSERT INTO worklog5743 VALUES(REPEAT("b", 4000) , REPEAT("p", 4000)); @@ -1101,6 +1103,8 @@ CREATE TABLE worklog5743 ( col_1_varchar VARCHAR (4000) , col_2_varchar VARCHAR (4000) , PRIMARY KEY `prefix_primary` (col_1_varchar(3072)) ) ROW_FORMAT=DYNAMIC, engine = innodb; +Warnings: +Warning 1280 Name 'prefix_primary' ignored for PRIMARY key. INSERT INTO worklog5743 VALUES(REPEAT("a", 4000) , REPEAT("o", 4000)); CREATE INDEX prefix_idx ON worklog5743(col_1_varchar (3072)); INSERT INTO worklog5743 VALUES(REPEAT("b", 4000) , REPEAT("p", 4000)); diff --git a/mysql-test/suite/multi_source/multisource.result b/mysql-test/suite/multi_source/multisource.result index d99a377f0c5..928c9799854 100644 --- a/mysql-test/suite/multi_source/multisource.result +++ b/mysql-test/suite/multi_source/multisource.result @@ -47,6 +47,8 @@ drop database if exists db1; create database db1; use db1; create table t1 (i int auto_increment, f1 varchar(16), primary key pk (i,f1)) engine=MyISAM; +Warnings: +Warning 1280 Name 'pk' ignored for PRIMARY key. insert into t1 (f1) values ('one'),('two'); connection slave; select * from db1.t1; diff --git a/mysql-test/suite/parts/r/alter_data_directory_innodb.result b/mysql-test/suite/parts/r/alter_data_directory_innodb.result index d0ad8cd074c..8a43588ea52 100644 --- a/mysql-test/suite/parts/r/alter_data_directory_innodb.result +++ b/mysql-test/suite/parts/r/alter_data_directory_innodb.result @@ -18,6 +18,8 @@ t CREATE TABLE `t` ( (PARTITION `p1` DATA DIRECTORY = 'MYSQLTEST_VARDIR/tmp/partitions_here' ENGINE = InnoDB, PARTITION `p2` DATA DIRECTORY = 'MYSQLTEST_VARDIR/tmp/partitions_here' ENGINE = InnoDB) ALTER TABLE t ADD PRIMARY KEY pk(a), ALGORITHM=INPLACE; +Warnings: +Warning 1280 Name 'pk' ignored for PRIMARY key. SHOW CREATE TABLE t; Table Create Table t CREATE TABLE `t` ( @@ -39,6 +41,8 @@ t CREATE TABLE `t` ( SET @TMP = @@GLOBAL.INNODB_FILE_PER_TABLE; SET GLOBAL INNODB_FILE_PER_TABLE=OFF; ALTER TABLE t ADD PRIMARY KEY pk(a), ALGORITHM=INPLACE; +Warnings: +Warning 1280 Name 'pk' ignored for PRIMARY key. SHOW CREATE TABLE t; Table Create Table t CREATE TABLE `t` ( diff --git a/mysql-test/suite/rpl/r/rpl_blackhole.result b/mysql-test/suite/rpl/r/rpl_blackhole.result index 178c23b9f98..a87ba9a9d2d 100644 --- a/mysql-test/suite/rpl/r/rpl_blackhole.result +++ b/mysql-test/suite/rpl/r/rpl_blackhole.result @@ -42,6 +42,8 @@ COUNT(*) >>> Something was written to binary log <<< connection master; ALTER TABLE t1 ADD PRIMARY KEY pk_t1 (a,b); +Warnings: +Warning 1280 Name 'pk_t1' ignored for PRIMARY key. connection slave; connection master; INSERT INTO t1 VALUES (1,2,1),(2,2,2),(3,2,3),(4,2,4); diff --git a/mysql-test/suite/rpl/r/rpl_blackhole_row_annotate.result b/mysql-test/suite/rpl/r/rpl_blackhole_row_annotate.result index d92c3dce55b..3c5711855d8 100644 --- a/mysql-test/suite/rpl/r/rpl_blackhole_row_annotate.result +++ b/mysql-test/suite/rpl/r/rpl_blackhole_row_annotate.result @@ -47,6 +47,8 @@ COUNT(*) >>> Something was written to binary log <<< connection master; ALTER TABLE t1 ADD PRIMARY KEY pk_t1 (a,b); +Warnings: +Warning 1280 Name 'pk_t1' ignored for PRIMARY key. connection slave; connection master; INSERT INTO t1 VALUES (1,2,1),(2,2,2),(3,2,3),(4,2,4); diff --git a/mysql-test/suite/versioning/r/online.result b/mysql-test/suite/versioning/r/online.result index 21441acb6b2..f3a7241d884 100644 --- a/mysql-test/suite/versioning/r/online.result +++ b/mysql-test/suite/versioning/r/online.result @@ -66,7 +66,9 @@ alter table t2 change a a int with system versioning, add primary key pk (a); affected rows: 0 -info: Records: 0 Duplicates: 0 Warnings: 0 +info: Records: 0 Duplicates: 0 Warnings: 1 +Warnings: +Warning 1280 Name 'pk' ignored for PRIMARY key. update t1 set a=2; select count(*) from t1 for system_time all; count(*) diff --git a/mysql-test/suite/versioning/r/trx_id.result b/mysql-test/suite/versioning/r/trx_id.result index 951e5ce3dd9..98543caadbc 100644 --- a/mysql-test/suite/versioning/r/trx_id.result +++ b/mysql-test/suite/versioning/r/trx_id.result @@ -421,7 +421,9 @@ ALTER TABLE t CHANGE a a INT WITH SYSTEM VERSIONING, ADD PRIMARY KEY pk(a); affected rows: 0 -info: Records: 0 Duplicates: 0 Warnings: 0 +info: Records: 0 Duplicates: 0 Warnings: 1 +Warnings: +Warning 1280 Name 'pk' ignored for PRIMARY key. SELECT c.prtype FROM INFORMATION_SCHEMA.INNODB_SYS_COLUMNS AS c INNER JOIN INFORMATION_SCHEMA.INNODB_SYS_TABLES AS t ON c.table_id=t.table_id diff --git a/scripts/mysql_system_tables.sql b/scripts/mysql_system_tables.sql index 8f289764c64..8126f5fbb77 100644 --- a/scripts/mysql_system_tables.sql +++ b/scripts/mysql_system_tables.sql @@ -28,14 +28,14 @@ set system_versioning_alter_history=keep; set @have_innodb= (select count(engine) from information_schema.engines where engine='INNODB' and support != 'NO'); SET @innodb_or_myisam=IF(@have_innodb <> 0, 'InnoDB', 'MyISAM'); -CREATE TABLE IF NOT EXISTS db ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, User char(80) binary DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Event_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Trigger_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_history_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, PRIMARY KEY Host (Host,Db,User), KEY User (User) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Database privileges'; +CREATE TABLE IF NOT EXISTS db ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, User char(80) binary DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Event_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Trigger_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_history_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, PRIMARY KEY /*Host */(Host,Db,User), KEY User (User) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Database privileges'; -- Remember for later if db table already existed set @had_db_table= @@warning_count != 0; -CREATE TABLE IF NOT EXISTS host ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Trigger_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, PRIMARY KEY Host (Host,Db) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Host privileges; Merged with database privileges'; +CREATE TABLE IF NOT EXISTS host ( Host char(60) binary DEFAULT '' NOT NULL, Db char(64) binary DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Trigger_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, PRIMARY KEY /*Host*/ (Host,Db) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Host privileges; Merged with database privileges'; -CREATE TABLE IF NOT EXISTS user ( Host char(60) binary DEFAULT '' NOT NULL, User char(80) binary DEFAULT '' NOT NULL, Password char(41) character set latin1 collate latin1_bin DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Reload_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Shutdown_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Process_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, File_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_db_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Super_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Repl_slave_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Repl_client_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_user_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Event_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Trigger_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tablespace_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_history_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, ssl_type enum('','ANY','X509', 'SPECIFIED') COLLATE utf8_general_ci DEFAULT '' NOT NULL, ssl_cipher BLOB NOT NULL, x509_issuer BLOB NOT NULL, x509_subject BLOB NOT NULL, max_questions int(11) unsigned DEFAULT 0 NOT NULL, max_updates int(11) unsigned DEFAULT 0 NOT NULL, max_connections int(11) unsigned DEFAULT 0 NOT NULL, max_user_connections int(11) DEFAULT 0 NOT NULL, plugin char(64) CHARACTER SET latin1 DEFAULT '' NOT NULL, authentication_string TEXT NOT NULL, password_expired ENUM('N', 'Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, is_role enum('N', 'Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, default_role char(80) binary DEFAULT '' NOT NULL, max_statement_time decimal(12,6) DEFAULT 0 NOT NULL, PRIMARY KEY Host (Host,User) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Users and global privileges'; +CREATE TABLE IF NOT EXISTS user ( Host char(60) binary DEFAULT '' NOT NULL, User char(80) binary DEFAULT '' NOT NULL, Password char(41) character set latin1 collate latin1_bin DEFAULT '' NOT NULL, Select_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Insert_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Update_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Drop_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Reload_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Shutdown_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Process_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, File_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Grant_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, References_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Index_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_db_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Super_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tmp_table_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Lock_tables_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Execute_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Repl_slave_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Repl_client_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Show_view_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Alter_routine_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_user_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Event_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Trigger_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Create_tablespace_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, Delete_history_priv enum('N','Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, ssl_type enum('','ANY','X509', 'SPECIFIED') COLLATE utf8_general_ci DEFAULT '' NOT NULL, ssl_cipher BLOB NOT NULL, x509_issuer BLOB NOT NULL, x509_subject BLOB NOT NULL, max_questions int(11) unsigned DEFAULT 0 NOT NULL, max_updates int(11) unsigned DEFAULT 0 NOT NULL, max_connections int(11) unsigned DEFAULT 0 NOT NULL, max_user_connections int(11) DEFAULT 0 NOT NULL, plugin char(64) CHARACTER SET latin1 DEFAULT '' NOT NULL, authentication_string TEXT NOT NULL, password_expired ENUM('N', 'Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, is_role enum('N', 'Y') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, default_role char(80) binary DEFAULT '' NOT NULL, max_statement_time decimal(12,6) DEFAULT 0 NOT NULL, PRIMARY KEY /*Host*/ (Host,User) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='Users and global privileges'; -- Remember for later if user table already existed set @had_user_table= @@warning_count != 0; @@ -68,19 +68,19 @@ CREATE TABLE IF NOT EXISTS help_relation ( help_topic_id int unsigned not null r CREATE TABLE IF NOT EXISTS help_keyword ( help_keyword_id int unsigned not null, name char(64) not null, primary key (help_keyword_id), unique index (name) ) engine=MyISAM CHARACTER SET utf8 comment='help keywords'; -CREATE TABLE IF NOT EXISTS time_zone_name ( Name char(64) NOT NULL, Time_zone_id int unsigned NOT NULL, PRIMARY KEY Name (Name) ) engine=MyISAM CHARACTER SET utf8 comment='Time zone names'; +CREATE TABLE IF NOT EXISTS time_zone_name ( Name char(64) NOT NULL, Time_zone_id int unsigned NOT NULL, PRIMARY KEY /*Name*/ (Name) ) engine=MyISAM CHARACTER SET utf8 comment='Time zone names'; -CREATE TABLE IF NOT EXISTS time_zone ( Time_zone_id int unsigned NOT NULL auto_increment, Use_leap_seconds enum('Y','N') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, PRIMARY KEY TzId (Time_zone_id) ) engine=MyISAM CHARACTER SET utf8 comment='Time zones'; +CREATE TABLE IF NOT EXISTS time_zone ( Time_zone_id int unsigned NOT NULL auto_increment, Use_leap_seconds enum('Y','N') COLLATE utf8_general_ci DEFAULT 'N' NOT NULL, PRIMARY KEY /*TzId*/ (Time_zone_id) ) engine=MyISAM CHARACTER SET utf8 comment='Time zones'; -CREATE TABLE IF NOT EXISTS time_zone_transition ( Time_zone_id int unsigned NOT NULL, Transition_time bigint signed NOT NULL, Transition_type_id int unsigned NOT NULL, PRIMARY KEY TzIdTranTime (Time_zone_id, Transition_time) ) engine=MyISAM CHARACTER SET utf8 comment='Time zone transitions'; +CREATE TABLE IF NOT EXISTS time_zone_transition ( Time_zone_id int unsigned NOT NULL, Transition_time bigint signed NOT NULL, Transition_type_id int unsigned NOT NULL, PRIMARY KEY /*TzIdTranTime*/ (Time_zone_id, Transition_time) ) engine=MyISAM CHARACTER SET utf8 comment='Time zone transitions'; -CREATE TABLE IF NOT EXISTS time_zone_transition_type ( Time_zone_id int unsigned NOT NULL, Transition_type_id int unsigned NOT NULL, Offset int signed DEFAULT 0 NOT NULL, Is_DST tinyint unsigned DEFAULT 0 NOT NULL, Abbreviation char(8) DEFAULT '' NOT NULL, PRIMARY KEY TzIdTrTId (Time_zone_id, Transition_type_id) ) engine=MyISAM CHARACTER SET utf8 comment='Time zone transition types'; +CREATE TABLE IF NOT EXISTS time_zone_transition_type ( Time_zone_id int unsigned NOT NULL, Transition_type_id int unsigned NOT NULL, Offset int signed DEFAULT 0 NOT NULL, Is_DST tinyint unsigned DEFAULT 0 NOT NULL, Abbreviation char(8) DEFAULT '' NOT NULL, PRIMARY KEY /*TzIdTrTId*/ (Time_zone_id, Transition_type_id) ) engine=MyISAM CHARACTER SET utf8 comment='Time zone transition types'; -CREATE TABLE IF NOT EXISTS time_zone_leap_second ( Transition_time bigint signed NOT NULL, Correction int signed NOT NULL, PRIMARY KEY TranTime (Transition_time) ) engine=MyISAM CHARACTER SET utf8 comment='Leap seconds information for time zones'; +CREATE TABLE IF NOT EXISTS time_zone_leap_second ( Transition_time bigint signed NOT NULL, Correction int signed NOT NULL, PRIMARY KEY /*TranTime*/ (Transition_time) ) engine=MyISAM CHARACTER SET utf8 comment='Leap seconds information for time zones'; CREATE TABLE IF NOT EXISTS proc (db char(64) collate utf8_bin DEFAULT '' NOT NULL, name char(64) DEFAULT '' NOT NULL, type enum('FUNCTION','PROCEDURE','PACKAGE','PACKAGE BODY') NOT NULL, specific_name char(64) DEFAULT '' NOT NULL, language enum('SQL') DEFAULT 'SQL' NOT NULL, sql_data_access enum( 'CONTAINS_SQL', 'NO_SQL', 'READS_SQL_DATA', 'MODIFIES_SQL_DATA') DEFAULT 'CONTAINS_SQL' NOT NULL, is_deterministic enum('YES','NO') DEFAULT 'NO' NOT NULL, security_type enum('INVOKER','DEFINER') DEFAULT 'DEFINER' NOT NULL, param_list blob NOT NULL, returns longblob NOT NULL, body longblob NOT NULL, definer char(141) collate utf8_bin DEFAULT '' NOT NULL, created timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, modified timestamp NOT NULL DEFAULT '0000-00-00 00:00:00', sql_mode set( 'REAL_AS_FLOAT', 'PIPES_AS_CONCAT', 'ANSI_QUOTES', 'IGNORE_SPACE', 'IGNORE_BAD_TABLE_OPTIONS', 'ONLY_FULL_GROUP_BY', 'NO_UNSIGNED_SUBTRACTION', 'NO_DIR_IN_CREATE', 'POSTGRESQL', 'ORACLE', 'MSSQL', 'DB2', 'MAXDB', 'NO_KEY_OPTIONS', 'NO_TABLE_OPTIONS', 'NO_FIELD_OPTIONS', 'MYSQL323', 'MYSQL40', 'ANSI', 'NO_AUTO_VALUE_ON_ZERO', 'NO_BACKSLASH_ESCAPES', 'STRICT_TRANS_TABLES', 'STRICT_ALL_TABLES', 'NO_ZERO_IN_DATE', 'NO_ZERO_DATE', 'INVALID_DATES', 'ERROR_FOR_DIVISION_BY_ZERO', 'TRADITIONAL', 'NO_AUTO_CREATE_USER', 'HIGH_NOT_PRECEDENCE', 'NO_ENGINE_SUBSTITUTION', 'PAD_CHAR_TO_FULL_LENGTH', 'EMPTY_STRING_IS_NULL', 'SIMULTANEOUS_ASSIGNMENT') DEFAULT '' NOT NULL, comment text collate utf8_bin NOT NULL, character_set_client char(32) collate utf8_bin, collation_connection char(32) collate utf8_bin, db_collation char(32) collate utf8_bin, body_utf8 longblob, aggregate enum('NONE', 'GROUP') DEFAULT 'NONE' NOT NULL, PRIMARY KEY (db,name,type)) engine=MyISAM character set utf8 comment='Stored Procedures'; @@ -229,7 +229,7 @@ SET @str=CONCAT(@cmd, ' ENGINE=', @innodb_or_myisam); #EXECUTE stmt; #DROP PREPARE stmt; -CREATE TABLE IF NOT EXISTS proxies_priv (Host char(60) binary DEFAULT '' NOT NULL, User char(80) binary DEFAULT '' NOT NULL, Proxied_host char(60) binary DEFAULT '' NOT NULL, Proxied_user char(80) binary DEFAULT '' NOT NULL, With_grant BOOL DEFAULT 0 NOT NULL, Grantor char(141) DEFAULT '' NOT NULL, Timestamp timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY Host (Host,User,Proxied_host,Proxied_user), KEY Grantor (Grantor) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='User proxy privileges'; +CREATE TABLE IF NOT EXISTS proxies_priv (Host char(60) binary DEFAULT '' NOT NULL, User char(80) binary DEFAULT '' NOT NULL, Proxied_host char(60) binary DEFAULT '' NOT NULL, Proxied_user char(80) binary DEFAULT '' NOT NULL, With_grant BOOL DEFAULT 0 NOT NULL, Grantor char(141) DEFAULT '' NOT NULL, Timestamp timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, PRIMARY KEY /*Host*/ (Host,User,Proxied_host,Proxied_user), KEY Grantor (Grantor) ) engine=MyISAM CHARACTER SET utf8 COLLATE utf8_bin comment='User proxy privileges'; -- Remember for later if proxies_priv table already existed set @had_proxies_priv_table= @@warning_count != 0; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index af2e686167c..62f7a7c4952 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -3671,6 +3671,17 @@ mysql_prepare_create_table(THD *thd, HA_CREATE_INFO *create_info, my_error(ER_WRONG_NAME_FOR_INDEX, MYF(0), key->name.str); DBUG_RETURN(TRUE); } + if (key->type == Key::PRIMARY && key->name.str && + my_strcasecmp(system_charset_info, key->name.str, primary_key_name) != 0) + { + bool sav_abort_on_warning= thd->abort_on_warning; + thd->abort_on_warning= FALSE; /* Don't make an error out of this. */ + push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, + ER_WRONG_NAME_FOR_INDEX, + "Name '%-.100s' ignored for PRIMARY key.", + key->name.str); + thd->abort_on_warning= sav_abort_on_warning; + } } tmp=file->max_keys(); if (*key_count > tmp) diff --git a/storage/mroonga/mysql-test/mroonga/storage/r/index_multiple_column_select_varchar.result b/storage/mroonga/mysql-test/mroonga/storage/r/index_multiple_column_select_varchar.result index 53fbccda2b4..543a9012efe 100644 --- a/storage/mroonga/mysql-test/mroonga/storage/r/index_multiple_column_select_varchar.result +++ b/storage/mroonga/mysql-test/mroonga/storage/r/index_multiple_column_select_varchar.result @@ -6,6 +6,8 @@ family_name varchar(30) not null, score int not null, primary key property (given_name, family_name, score) ) default charset utf8; +Warnings: +Warning 1280 Name 'property' ignored for PRIMARY key. show create table scores; Table Create Table scores CREATE TABLE `scores` ( diff --git a/storage/rocksdb/mysql-test/rocksdb/r/add_index_inplace.result b/storage/rocksdb/mysql-test/rocksdb/r/add_index_inplace.result index 32c0537c780..3ba0f30a22d 100644 --- a/storage/rocksdb/mysql-test/rocksdb/r/add_index_inplace.result +++ b/storage/rocksdb/mysql-test/rocksdb/r/add_index_inplace.result @@ -469,6 +469,8 @@ DROP TABLE t1; SET @prior_rocksdb_table_stats_sampling_pct = @@rocksdb_table_stats_sampling_pct; set global rocksdb_table_stats_sampling_pct = 100; CREATE TABLE t1 (a INT, b INT, PRIMARY KEY ka(a)) ENGINE=RocksDB; +Warnings: +Warning 1280 Name 'ka' ignored for PRIMARY key. INSERT INTO t1 (a, b) VALUES (1, 10); INSERT INTO t1 (a, b) VALUES (2, 10); INSERT INTO t1 (a, b) VALUES (3, 20); diff --git a/storage/rocksdb/mysql-test/rocksdb/r/index_key_block_size.result b/storage/rocksdb/mysql-test/rocksdb/r/index_key_block_size.result index b0113d79bb2..5b804828e69 100644 --- a/storage/rocksdb/mysql-test/rocksdb/r/index_key_block_size.result +++ b/storage/rocksdb/mysql-test/rocksdb/r/index_key_block_size.result @@ -23,6 +23,8 @@ CREATE TABLE t1 (a INT, b CHAR(8), PRIMARY KEY ind2(b(1) DESC) KEY_BLOCK_SIZE=32768 COMMENT 'big key_block_size value' ) ENGINE=rocksdb; +Warnings: +Warning 1280 Name 'ind2' ignored for PRIMARY key. SHOW INDEX IN t1; Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment t1 0 PRIMARY 1 b A # 1 NULL LSMTREE big key_block_size value From fde7eb9ab2752724d7b2b2db79ef432da4bc9aae Mon Sep 17 00:00:00 2001 From: Anel Husakovic Date: Wed, 31 Jul 2019 02:51:20 -0700 Subject: [PATCH 02/14] Fix README --- mysql-test/README | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/mysql-test/README b/mysql-test/README index d925964fed5..f1c38f11716 100644 --- a/mysql-test/README +++ b/mysql-test/README @@ -51,7 +51,7 @@ options with which the server is started, restart the server during execution, etc.) You can create your own test cases. To create a test case, create a new -file in the t subdirectory using a text editor. The file should have a .test +file in the main subdirectory using a text editor. The file should have a .test extension. For example: # xemacs t/test_case_name.test @@ -60,7 +60,7 @@ In the file, put a set of SQL statements that create some tables, load test data, and run some queries to manipulate it. Your test should begin by dropping the tables you are going to create and -end by dropping them again. This ensures that you can run the test over +end by dropping them again. This ensures that you can run the test over and over again. If you are using mysqltest commands in your test case, you should create @@ -81,7 +81,7 @@ comments, you can create the result file in one of the following ways: # mysqltest --record --database test --result-file=r/test_case_name.result < t/test_case_name.test -When this is done, take a look at r/test_case_name.result . +When this is done, take a look at r/test_case_name.result. If the result is incorrect, you have found a bug. In this case, you should edit the test result to the correct results so that we can verify that the bug is corrected in future releases. From e1e142e7fca77f24a26a789fd6116896391e852a Mon Sep 17 00:00:00 2001 From: Daniel Bartholomew Date: Wed, 31 Jul 2019 09:58:59 -0400 Subject: [PATCH 03/14] bump the VERSION --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index 070cdafdf2e..f8eaedc3ab8 100644 --- a/VERSION +++ b/VERSION @@ -1,4 +1,4 @@ MYSQL_VERSION_MAJOR=10 MYSQL_VERSION_MINOR=3 -MYSQL_VERSION_PATCH=17 +MYSQL_VERSION_PATCH=18 SERVER_MATURITY=stable From 6b48bdf269cb86e95e1655d28d2f32443918b4fa Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Mon, 5 Aug 2019 15:25:31 +0400 Subject: [PATCH 04/14] MDEV-18456 Assertion `item->maybe_null' failed in Type_handler_temporal_result::make_sort_key Adding tests only. This problem was earlier fixed in 10.4 by MDEV-17325 and backported to 10.3 with this commit: f4019f5b3544a18f3ddf32df2c5214c3f8dabdce --- mysql-test/main/func_hybrid_type.result | 15 +++++++++++++++ mysql-test/main/func_hybrid_type.test | 10 ++++++++++ 2 files changed, 25 insertions(+) diff --git a/mysql-test/main/func_hybrid_type.result b/mysql-test/main/func_hybrid_type.result index c7ec29f1a49..c6b94ab61b0 100644 --- a/mysql-test/main/func_hybrid_type.result +++ b/mysql-test/main/func_hybrid_type.result @@ -3915,5 +3915,20 @@ t1 CREATE TABLE `t1` ( DROP TABLE t1; SET sql_mode=DEFAULT; # +# MDEV-18456 Assertion `item->maybe_null' failed in Type_handler_temporal_result::make_sort_key +# +CREATE TABLE t1 (t TIME NOT NULL); +INSERT INTO t1 VALUES ('00:20:11'),('14:52:05'); +SELECT GREATEST('9999', t) FROM t1 ORDER BY 1; +GREATEST('9999', t) +NULL +NULL +Warnings: +Warning 1292 Truncated incorrect time value: '9999' +Warning 1292 Truncated incorrect time value: '9999' +Warning 1292 Truncated incorrect time value: '9999' +Warning 1292 Truncated incorrect time value: '9999' +DROP TABLE t1; +# # End of 10.3 tests # diff --git a/mysql-test/main/func_hybrid_type.test b/mysql-test/main/func_hybrid_type.test index 9736485bb9f..7d986130d7f 100644 --- a/mysql-test/main/func_hybrid_type.test +++ b/mysql-test/main/func_hybrid_type.test @@ -710,6 +710,16 @@ SHOW CREATE TABLE t1; DROP TABLE t1; SET sql_mode=DEFAULT; +--echo # +--echo # MDEV-18456 Assertion `item->maybe_null' failed in Type_handler_temporal_result::make_sort_key +--echo # + +CREATE TABLE t1 (t TIME NOT NULL); +INSERT INTO t1 VALUES ('00:20:11'),('14:52:05'); +SELECT GREATEST('9999', t) FROM t1 ORDER BY 1; +DROP TABLE t1; + + --echo # --echo # End of 10.3 tests --echo # From 4c4e379ba983553ea4df07eb1fe90745d173a866 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Mon, 5 Aug 2019 16:03:33 +0400 Subject: [PATCH 05/14] MDEV-20101 Assertion failure on select @@global.'m2'.replicate_ignore_table; - Removing the wrong assert - Re-enabling multi_source.mdev-8874 --- mysql-test/suite/multi_source/disabled.def | 1 - .../sys_vars/r/replicate_ignore_table_basic.result | 10 ++++++++++ .../suite/sys_vars/t/replicate_ignore_table_basic.test | 7 +++++++ sql/sql_class.cc | 1 - 4 files changed, 17 insertions(+), 2 deletions(-) diff --git a/mysql-test/suite/multi_source/disabled.def b/mysql-test/suite/multi_source/disabled.def index 45c8a6c8891..e69de29bb2d 100644 --- a/mysql-test/suite/multi_source/disabled.def +++ b/mysql-test/suite/multi_source/disabled.def @@ -1 +0,0 @@ -mdev-8874 : MDEV-20101 Assertion failure diff --git a/mysql-test/suite/sys_vars/r/replicate_ignore_table_basic.result b/mysql-test/suite/sys_vars/r/replicate_ignore_table_basic.result index db97ce14c93..a1701635f0e 100644 --- a/mysql-test/suite/sys_vars/r/replicate_ignore_table_basic.result +++ b/mysql-test/suite/sys_vars/r/replicate_ignore_table_basic.result @@ -46,3 +46,13 @@ SELECT @@GLOBAL.replicate_ignore_table; # Cleanup. SET @@GLOBAL.replicate_ignore_table = @save_replicate_ignore_table; +# +# MDEV-20101 Assertion failure on select @@global.'m2'.replicate_ignore_table +# +SET NAMES latin1; +SELECT @@global.'m2'.replicate_ignore_table; +@@global.'m2'.replicate_ignore_table +NULL +Warnings: +Warning 1617 There is no master connection 'm2' +Warning 1617 There is no master connection 'm2' diff --git a/mysql-test/suite/sys_vars/t/replicate_ignore_table_basic.test b/mysql-test/suite/sys_vars/t/replicate_ignore_table_basic.test index 56cf7f17c7f..1cf6f010eca 100644 --- a/mysql-test/suite/sys_vars/t/replicate_ignore_table_basic.test +++ b/mysql-test/suite/sys_vars/t/replicate_ignore_table_basic.test @@ -49,3 +49,10 @@ SELECT @@GLOBAL.replicate_ignore_table; --echo # Cleanup. SET @@GLOBAL.replicate_ignore_table = @save_replicate_ignore_table; + +--echo # +--echo # MDEV-20101 Assertion failure on select @@global.'m2'.replicate_ignore_table +--echo # + +SET NAMES latin1; +SELECT @@global.'m2'.replicate_ignore_table; diff --git a/sql/sql_class.cc b/sql/sql_class.cc index fafac28cf8e..0e6fe2a0c51 100644 --- a/sql/sql_class.cc +++ b/sql/sql_class.cc @@ -2400,7 +2400,6 @@ bool THD::check_string_for_wellformedness(const char *str, size_t length, CHARSET_INFO *cs) const { - DBUG_ASSERT(charset_is_system_charset); size_t wlen= Well_formed_prefix(cs, str, length).length(); if (wlen < length) { From f36c0189b15b7ba0bd2de187223fe59f2359186e Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Tue, 6 Aug 2019 14:37:08 +0300 Subject: [PATCH 06/14] MDEV-17544: No warning when trying to name a primary key constraint Part#2: update .result files for affected MyRocks tests --- .../rocksdb/r/add_unique_index_inplace.result | 8 ++++++++ .../rocksdb/r/type_blob_indexes.result | 10 ++++++++++ .../rocksdb/r/type_text_indexes.result | 16 ++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/storage/rocksdb/mysql-test/rocksdb/r/add_unique_index_inplace.result b/storage/rocksdb/mysql-test/rocksdb/r/add_unique_index_inplace.result index f7c4bab685d..e998cfb43c1 100644 --- a/storage/rocksdb/mysql-test/rocksdb/r/add_unique_index_inplace.result +++ b/storage/rocksdb/mysql-test/rocksdb/r/add_unique_index_inplace.result @@ -1,5 +1,7 @@ drop table if exists t1; CREATE TABLE t1 (a INT, b INT, PRIMARY KEY ka(a)) ENGINE=RocksDB; +Warnings: +Warning 1280 Name 'ka' ignored for PRIMARY key. INSERT INTO t1 (a, b) VALUES (1, 5); INSERT INTO t1 (a, b) VALUES (2, 6); INSERT INTO t1 (a, b) VALUES (3, 7); @@ -15,6 +17,8 @@ t1 CREATE TABLE `t1` ( ) ENGINE=ROCKSDB DEFAULT CHARSET=latin1 DROP TABLE t1; CREATE TABLE t1 (a INT, b INT, PRIMARY KEY ka(a)) ENGINE=RocksDB; +Warnings: +Warning 1280 Name 'ka' ignored for PRIMARY key. INSERT INTO t1 (a, b) VALUES (1, 5); INSERT INTO t1 (a, b) VALUES (2, 6); INSERT INTO t1 (a, b) VALUES (3, 7); @@ -38,6 +42,8 @@ a b 5 8 DROP TABLE t1; CREATE TABLE t1 (a INT, b INT, PRIMARY KEY ka(a)) ENGINE=RocksDB; +Warnings: +Warning 1280 Name 'ka' ignored for PRIMARY key. INSERT INTO t1 (a, b) VALUES (1, 5); INSERT INTO t1 (a, b) VALUES (2, NULL); INSERT INTO t1 (a, b) VALUES (3, NULL); @@ -56,6 +62,8 @@ COUNT(*) 4 DROP TABLE t1; CREATE TABLE t1 (a INT, b INT, c INT, PRIMARY KEY ka(a)) ENGINE=RocksDB; +Warnings: +Warning 1280 Name 'ka' ignored for PRIMARY key. INSERT INTO t1 (a,b,c) VALUES (1,1,NULL); INSERT INTO t1 (a,b,c) VALUES (2,1,NULL); INSERT INTO t1 (a,b,c) VALUES (3,1,NULL); diff --git a/storage/rocksdb/mysql-test/rocksdb/r/type_blob_indexes.result b/storage/rocksdb/mysql-test/rocksdb/r/type_blob_indexes.result index 26726e0f6d1..1e614a2bbf1 100644 --- a/storage/rocksdb/mysql-test/rocksdb/r/type_blob_indexes.result +++ b/storage/rocksdb/mysql-test/rocksdb/r/type_blob_indexes.result @@ -8,6 +8,8 @@ m MEDIUMBLOB, l LONGBLOB, PRIMARY KEY b (b(32)) ) ENGINE=rocksdb; +Warnings: +Warning 1280 Name 'b' ignored for PRIMARY key. SHOW INDEX IN t1; Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment t1 0 PRIMARY 1 b A 1000 32 NULL LSMTREE @@ -133,6 +135,8 @@ CREATE TABLE t1 ( b BLOB, PRIMARY KEY b (b(32)) ) ENGINE=rocksdb; +Warnings: +Warning 1280 Name 'b' ignored for PRIMARY key. INSERT INTO t1 (b) VALUES ('00000000000000000000000000000000'), ('00000000000000000000000000000001'), @@ -147,6 +151,8 @@ CREATE TABLE t1 ( b TINYBLOB, PRIMARY KEY b (b(32)) ) ENGINE=rocksdb; +Warnings: +Warning 1280 Name 'b' ignored for PRIMARY key. INSERT INTO t1 (b) VALUES ('00000000000000000000000000000000'), ('00000000000000000000000000000001'), @@ -161,6 +167,8 @@ CREATE TABLE t1 ( b MEDIUMBLOB, PRIMARY KEY b (b(32)) ) ENGINE=rocksdb; +Warnings: +Warning 1280 Name 'b' ignored for PRIMARY key. INSERT INTO t1 (b) VALUES ('00000000000000000000000000000000'), ('00000000000000000000000000000001'), @@ -175,6 +183,8 @@ CREATE TABLE t1 ( b LONGBLOB, PRIMARY KEY b (b(32)) ) ENGINE=rocksdb; +Warnings: +Warning 1280 Name 'b' ignored for PRIMARY key. INSERT INTO t1 (b) VALUES ('00000000000000000000000000000000'), ('00000000000000000000000000000001'), diff --git a/storage/rocksdb/mysql-test/rocksdb/r/type_text_indexes.result b/storage/rocksdb/mysql-test/rocksdb/r/type_text_indexes.result index 22318316596..7db5c23c53f 100644 --- a/storage/rocksdb/mysql-test/rocksdb/r/type_text_indexes.result +++ b/storage/rocksdb/mysql-test/rocksdb/r/type_text_indexes.result @@ -8,6 +8,8 @@ m MEDIUMTEXT, l LONGTEXT, PRIMARY KEY t (t(32)) ) ENGINE=rocksdb; +Warnings: +Warning 1280 Name 't' ignored for PRIMARY key. SHOW INDEX IN t1; Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment t1 0 PRIMARY 1 t A 1000 32 NULL LSMTREE @@ -55,6 +57,8 @@ pk MEDIUMTEXT, PRIMARY KEY mt (pk(1)), INDEX (m(128)) ) ENGINE=rocksdb; +Warnings: +Warning 1280 Name 'mt' ignored for PRIMARY key. SHOW INDEX IN t1; Table Non_unique Key_name Seq_in_index Column_name Collation Cardinality Sub_part Packed Null Index_type Comment Index_comment t1 0 PRIMARY 1 pk A 1000 1 NULL LSMTREE @@ -80,6 +84,8 @@ CREATE TABLE t1 ( b TEXT, PRIMARY KEY b (b(32)) ) ENGINE=rocksdb; +Warnings: +Warning 1280 Name 'b' ignored for PRIMARY key. INSERT INTO t1 (b) VALUES ('00000000000000000000000000000000'), ('00000000000000000000000000000001'), @@ -94,6 +100,8 @@ CREATE TABLE t1 ( b TINYTEXT, PRIMARY KEY b (b(32)) ) ENGINE=rocksdb; +Warnings: +Warning 1280 Name 'b' ignored for PRIMARY key. INSERT INTO t1 (b) VALUES ('00000000000000000000000000000000'), ('00000000000000000000000000000001'), @@ -108,6 +116,8 @@ CREATE TABLE t1 ( b MEDIUMTEXT, PRIMARY KEY b (b(32)) ) ENGINE=rocksdb; +Warnings: +Warning 1280 Name 'b' ignored for PRIMARY key. INSERT INTO t1 (b) VALUES ('00000000000000000000000000000000'), ('00000000000000000000000000000001'), @@ -122,6 +132,8 @@ CREATE TABLE t1 ( b LONGTEXT, PRIMARY KEY b (b(32)) ) ENGINE=rocksdb; +Warnings: +Warning 1280 Name 'b' ignored for PRIMARY key. INSERT INTO t1 (b) VALUES ('00000000000000000000000000000000'), ('00000000000000000000000000000001'), @@ -136,6 +148,8 @@ CREATE TABLE t1 ( b LONGTEXT CHARACTER SET "binary" COLLATE "binary", PRIMARY KEY b (b(32)) ) ENGINE=rocksdb; +Warnings: +Warning 1280 Name 'b' ignored for PRIMARY key. INSERT INTO t1 (b) VALUES ('00000000000000000000000000000000'), ('00000000000000000000000000000001'), @@ -154,6 +168,8 @@ CREATE TABLE t1 ( b LONGTEXT CHARACTER SET "latin1" COLLATE "latin1_bin", PRIMARY KEY b (b(32)) ) ENGINE=rocksdb; +Warnings: +Warning 1280 Name 'b' ignored for PRIMARY key. INSERT INTO t1 (b) VALUES (''), (_binary 0x0), (' '); ERROR 23000: Duplicate entry ' ' for key 'PRIMARY' INSERT INTO t1 (b) VALUES (''), (_binary 0x0); From a8def12e8a65cee915029de46d6e37b338ee9289 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Tue, 6 Aug 2019 18:02:03 +0400 Subject: [PATCH 07/14] MDEV-20263 sql_mode=ORACLE: BLOB(65535) should not translate to LONGBLOB --- .../compat/oracle/r/column_compression.result | 6 +++--- mysql-test/suite/compat/oracle/r/sp.result | 2 +- .../suite/compat/oracle/r/type_blob.result | 18 ++++++++++++++++++ .../suite/compat/oracle/t/type_blob.test | 13 +++++++++++++ sql/field.cc | 4 ++++ sql/sql_yacc.yy | 7 ++++++- sql/sql_yacc_ora.yy | 7 ++++++- 7 files changed, 51 insertions(+), 6 deletions(-) diff --git a/mysql-test/suite/compat/oracle/r/column_compression.result b/mysql-test/suite/compat/oracle/r/column_compression.result index 1b828ca17b0..7a12c7b8233 100644 --- a/mysql-test/suite/compat/oracle/r/column_compression.result +++ b/mysql-test/suite/compat/oracle/r/column_compression.result @@ -515,7 +515,7 @@ CREATE TABLE t1 (a TEXT COMPRESSED BYTE); SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE "t1" ( - "a" blob /*!100301 COMPRESSED*/ DEFAULT NULL + "a" blob(65535) /*!100301 COMPRESSED*/ DEFAULT NULL ) DROP TABLE t1; CREATE TABLE t1 (a TEXT COMPRESSED ASCII); @@ -547,7 +547,7 @@ CREATE TABLE t1 (a TEXT COMPRESSED BYTE DEFAULT ''); SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE "t1" ( - "a" blob /*!100301 COMPRESSED*/ DEFAULT '' + "a" blob(65535) /*!100301 COMPRESSED*/ DEFAULT '' ) DROP TABLE t1; CREATE TABLE t1 (a TEXT COMPRESSED BINARY DEFAULT ''); @@ -605,7 +605,7 @@ Warning 1287 ' ... COMPRESSED...' is deprecate SHOW CREATE TABLE t1; Table Create Table t1 CREATE TABLE "t1" ( - "a" blob /*!100301 COMPRESSED*/ DEFAULT NULL + "a" blob(65535) /*!100301 COMPRESSED*/ DEFAULT NULL ) DROP TABLE t1; # diff --git a/mysql-test/suite/compat/oracle/r/sp.result b/mysql-test/suite/compat/oracle/r/sp.result index 8fa49c4092a..2d4244110f9 100644 --- a/mysql-test/suite/compat/oracle/r/sp.result +++ b/mysql-test/suite/compat/oracle/r/sp.result @@ -2072,7 +2072,7 @@ t1 CREATE TABLE "t1" ( "tables_table_name" varchar(64) CHARACTER SET utf8 DEFAULT NULL, "tables_table_rows" bigint(21) unsigned DEFAULT NULL, "processlist_info" longtext CHARACTER SET utf8 DEFAULT NULL, - "processlist_info_binary" blob DEFAULT NULL + "processlist_info_binary" blob(65535) DEFAULT NULL ) DROP TABLE t1; DROP PROCEDURE p1; diff --git a/mysql-test/suite/compat/oracle/r/type_blob.result b/mysql-test/suite/compat/oracle/r/type_blob.result index fe0a78e6ceb..27740947a10 100644 --- a/mysql-test/suite/compat/oracle/r/type_blob.result +++ b/mysql-test/suite/compat/oracle/r/type_blob.result @@ -6,3 +6,21 @@ t1 CREATE TABLE "t1" ( "a" longblob DEFAULT NULL ) DROP TABLE t1; +# +# MDEV-20263 sql_mode=ORACLE: BLOB(65535) should not translate to LONGBLOB +# +CREATE TABLE t1 ( +c1 BLOB(100), +c2 BLOB(65535), +c3 BLOB(16777215), +c4 BLOB(16777216) +); +SHOW CREATE TABLE t1; +Table Create Table +t1 CREATE TABLE "t1" ( + "c1" tinyblob DEFAULT NULL, + "c2" blob(65535) DEFAULT NULL, + "c3" mediumblob DEFAULT NULL, + "c4" longblob DEFAULT NULL +) +DROP TABLE t1; diff --git a/mysql-test/suite/compat/oracle/t/type_blob.test b/mysql-test/suite/compat/oracle/t/type_blob.test index 2bfaa77560d..989581ee4f6 100644 --- a/mysql-test/suite/compat/oracle/t/type_blob.test +++ b/mysql-test/suite/compat/oracle/t/type_blob.test @@ -2,3 +2,16 @@ SET sql_mode=ORACLE; CREATE TABLE t1 (a BLOB); SHOW CREATE TABLE t1; DROP TABLE t1; + +--echo # +--echo # MDEV-20263 sql_mode=ORACLE: BLOB(65535) should not translate to LONGBLOB +--echo # + +CREATE TABLE t1 ( + c1 BLOB(100), + c2 BLOB(65535), + c3 BLOB(16777215), + c4 BLOB(16777216) +); +SHOW CREATE TABLE t1; +DROP TABLE t1; diff --git a/sql/field.cc b/sql/field.cc index 842f92e858f..fc5ca7675ac 100644 --- a/sql/field.cc +++ b/sql/field.cc @@ -8593,7 +8593,11 @@ void Field_blob::sql_type(String &res) const } res.set_ascii(str,length); if (charset() == &my_charset_bin) + { res.append(STRING_WITH_LEN("blob")); + if (packlength == 2 && (get_thd()->variables.sql_mode & MODE_ORACLE)) + res.append(STRING_WITH_LEN("(65535)")); + } else { res.append(STRING_WITH_LEN("text")); diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index f5aecf37ecc..d5e579e9df5 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -7086,7 +7086,12 @@ field_type_lob: Lex->charset=&my_charset_bin; $$.set(&type_handler_blob, $2); } - | BLOB_ORACLE_SYM opt_field_length opt_compressed + | BLOB_ORACLE_SYM field_length opt_compressed + { + Lex->charset=&my_charset_bin; + $$.set(&type_handler_blob, $2); + } + | BLOB_ORACLE_SYM opt_compressed { Lex->charset=&my_charset_bin; $$.set(&type_handler_long_blob); diff --git a/sql/sql_yacc_ora.yy b/sql/sql_yacc_ora.yy index ef7f7d92c0a..45f770b0c88 100644 --- a/sql/sql_yacc_ora.yy +++ b/sql/sql_yacc_ora.yy @@ -6984,7 +6984,12 @@ field_type_lob: Lex->charset=&my_charset_bin; $$.set(&type_handler_blob, $2); } - | BLOB_ORACLE_SYM opt_field_length opt_compressed + | BLOB_ORACLE_SYM field_length opt_compressed + { + Lex->charset=&my_charset_bin; + $$.set(&type_handler_blob, $2); + } + | BLOB_ORACLE_SYM opt_compressed { Lex->charset=&my_charset_bin; $$.set(&type_handler_long_blob); From e978efd96b9a8146ba2c80a1f3aea755568ac73a Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Wed, 7 Aug 2019 14:13:44 +0400 Subject: [PATCH 08/14] MDEV-20273 Add class Item_sum_min_max --- sql/item_cmpfunc.h | 4 +- sql/item_subselect.cc | 2 +- sql/item_sum.cc | 76 +++++++++++++++++------------------ sql/item_sum.h | 50 +++++++++++++++-------- sql/item_windowfunc.h | 15 +++---- sql/sql_type.cc | 30 +++++++------- sql/sql_type.h | 22 +++++----- storage/spider/spd_db_conn.cc | 4 +- 8 files changed, 108 insertions(+), 95 deletions(-) diff --git a/sql/item_cmpfunc.h b/sql/item_cmpfunc.h index 21f4a5ba1e2..f2cf91ffb7e 100644 --- a/sql/item_cmpfunc.h +++ b/sql/item_cmpfunc.h @@ -654,7 +654,7 @@ public: class Item_func_not_all :public Item_func_not { /* allow to check presence of values in max/min optimization */ - Item_sum_hybrid *test_sum_item; + Item_sum_min_max *test_sum_item; Item_maxmin_subselect *test_sub_item; public: @@ -670,7 +670,7 @@ public: bool fix_fields(THD *thd, Item **ref) {return Item_func::fix_fields(thd, ref);} virtual void print(String *str, enum_query_type query_type); - void set_sum_test(Item_sum_hybrid *item) { test_sum_item= item; test_sub_item= 0; }; + void set_sum_test(Item_sum_min_max *item) { test_sum_item= item; test_sub_item= 0; }; void set_sub_test(Item_maxmin_subselect *item) { test_sub_item= item; test_sum_item= 0;}; bool empty_underlying_subquery(); Item *neg_transformer(THD *thd); diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 1bac7b6e527..8b024715aac 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -1966,7 +1966,7 @@ bool Item_allany_subselect::transform_into_max_min(JOIN *join) (!select_lex->ref_pointer_array[0]->maybe_null || /*4*/ substype() != Item_subselect::ALL_SUBS)) /*4*/ { - Item_sum_hybrid *item; + Item_sum_min_max *item; nesting_map save_allow_sum_func; if (func->l_op()) { diff --git a/sql/item_sum.cc b/sql/item_sum.cc index 111dc88a1e3..081db08e943 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -1152,9 +1152,9 @@ Item_sum_num::fix_fields(THD *thd, Item **ref) bool -Item_sum_hybrid::fix_fields(THD *thd, Item **ref) +Item_sum_min_max::fix_fields(THD *thd, Item **ref) { - DBUG_ENTER("Item_sum_hybrid::fix_fields"); + DBUG_ENTER("Item_sum_min_max::fix_fields"); DBUG_ASSERT(fixed == 0); if (init_sum_func_check(thd)) @@ -1184,11 +1184,11 @@ Item_sum_hybrid::fix_fields(THD *thd, Item **ref) } -bool Item_sum_hybrid::fix_length_and_dec() +bool Item_sum_min_max::fix_length_and_dec() { DBUG_ASSERT(args[0]->field_type() == args[0]->real_item()->field_type()); DBUG_ASSERT(args[0]->result_type() == args[0]->real_item()->result_type()); - return args[0]->type_handler()->Item_sum_hybrid_fix_length_and_dec(this); + return args[0]->type_handler()->Item_sum_min_max_fix_length_and_dec(this); } @@ -1209,9 +1209,9 @@ bool Item_sum_hybrid::fix_length_and_dec() and Item_sum_min::add() to use different values! */ -void Item_sum_hybrid::setup_hybrid(THD *thd, Item *item, Item *value_arg) +void Item_sum_min_max::setup_hybrid(THD *thd, Item *item, Item *value_arg) { - DBUG_ENTER("Item_sum_hybrid::setup_hybrid"); + DBUG_ENTER("Item_sum_min_max::setup_hybrid"); if (!(value= item->get_cache(thd))) DBUG_VOID_RETURN; value->setup(thd, item); @@ -1232,9 +1232,9 @@ void Item_sum_hybrid::setup_hybrid(THD *thd, Item *item, Item *value_arg) } -Field *Item_sum_hybrid::create_tmp_field(bool group, TABLE *table) +Field *Item_sum_min_max::create_tmp_field(bool group, TABLE *table) { - DBUG_ENTER("Item_sum_hybrid::create_tmp_field"); + DBUG_ENTER("Item_sum_min_max::create_tmp_field"); if (args[0]->type() == Item::FIELD_ITEM) { @@ -2314,9 +2314,9 @@ Item *Item_sum_variance::result_item(THD *thd, Field *field) /* min & max */ -void Item_sum_hybrid::clear() +void Item_sum_min_max::clear() { - DBUG_ENTER("Item_sum_hybrid::clear"); + DBUG_ENTER("Item_sum_min_max::clear"); value->clear(); null_value= 1; DBUG_VOID_RETURN; @@ -2324,7 +2324,7 @@ void Item_sum_hybrid::clear() bool -Item_sum_hybrid::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) +Item_sum_min_max::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) { DBUG_ASSERT(fixed == 1); if (null_value) @@ -2336,9 +2336,9 @@ Item_sum_hybrid::get_date(MYSQL_TIME *ltime, ulonglong fuzzydate) } -void Item_sum_hybrid::direct_add(Item *item) +void Item_sum_min_max::direct_add(Item *item) { - DBUG_ENTER("Item_sum_hybrid::direct_add"); + DBUG_ENTER("Item_sum_min_max::direct_add"); DBUG_PRINT("info", ("item: %p", item)); direct_added= TRUE; direct_item= item; @@ -2346,9 +2346,9 @@ void Item_sum_hybrid::direct_add(Item *item) } -double Item_sum_hybrid::val_real() +double Item_sum_min_max::val_real() { - DBUG_ENTER("Item_sum_hybrid::val_real"); + DBUG_ENTER("Item_sum_min_max::val_real"); DBUG_ASSERT(fixed == 1); if (null_value) DBUG_RETURN(0.0); @@ -2358,9 +2358,9 @@ double Item_sum_hybrid::val_real() DBUG_RETURN(retval); } -longlong Item_sum_hybrid::val_int() +longlong Item_sum_min_max::val_int() { - DBUG_ENTER("Item_sum_hybrid::val_int"); + DBUG_ENTER("Item_sum_min_max::val_int"); DBUG_ASSERT(fixed == 1); if (null_value) DBUG_RETURN(0); @@ -2371,9 +2371,9 @@ longlong Item_sum_hybrid::val_int() } -my_decimal *Item_sum_hybrid::val_decimal(my_decimal *val) +my_decimal *Item_sum_min_max::val_decimal(my_decimal *val) { - DBUG_ENTER("Item_sum_hybrid::val_decimal"); + DBUG_ENTER("Item_sum_min_max::val_decimal"); DBUG_ASSERT(fixed == 1); if (null_value) DBUG_RETURN(0); @@ -2385,9 +2385,9 @@ my_decimal *Item_sum_hybrid::val_decimal(my_decimal *val) String * -Item_sum_hybrid::val_str(String *str) +Item_sum_min_max::val_str(String *str) { - DBUG_ENTER("Item_sum_hybrid::val_str"); + DBUG_ENTER("Item_sum_min_max::val_str"); DBUG_ASSERT(fixed == 1); if (null_value) DBUG_RETURN(0); @@ -2398,9 +2398,9 @@ Item_sum_hybrid::val_str(String *str) } -void Item_sum_hybrid::cleanup() +void Item_sum_min_max::cleanup() { - DBUG_ENTER("Item_sum_hybrid::cleanup"); + DBUG_ENTER("Item_sum_min_max::cleanup"); Item_sum::cleanup(); if (cmp) delete cmp; @@ -2416,9 +2416,9 @@ void Item_sum_hybrid::cleanup() DBUG_VOID_RETURN; } -void Item_sum_hybrid::no_rows_in_result() +void Item_sum_min_max::no_rows_in_result() { - DBUG_ENTER("Item_sum_hybrid::no_rows_in_result"); + DBUG_ENTER("Item_sum_min_max::no_rows_in_result"); /* We may be called here twice in case of ref field in function */ if (was_values) { @@ -2429,7 +2429,7 @@ void Item_sum_hybrid::no_rows_in_result() DBUG_VOID_RETURN; } -void Item_sum_hybrid::restore_to_before_no_rows_in_result() +void Item_sum_min_max::restore_to_before_no_rows_in_result() { if (!was_values) { @@ -2693,10 +2693,10 @@ void Item_sum_num::reset_field() } -void Item_sum_hybrid::reset_field() +void Item_sum_min_max::reset_field() { Item *UNINIT_VAR(tmp_item), *arg0; - DBUG_ENTER("Item_sum_hybrid::reset_field"); + DBUG_ENTER("Item_sum_min_max::reset_field"); arg0= args[0]; if (unlikely(direct_added)) @@ -3049,9 +3049,9 @@ Item *Item_sum_avg::result_item(THD *thd, Field *field) } -void Item_sum_hybrid::update_field() +void Item_sum_min_max::update_field() { - DBUG_ENTER("Item_sum_hybrid::update_field"); + DBUG_ENTER("Item_sum_min_max::update_field"); Item *UNINIT_VAR(tmp_item); if (unlikely(direct_added)) { @@ -3081,9 +3081,9 @@ void Item_sum_hybrid::update_field() void -Item_sum_hybrid::min_max_update_str_field() +Item_sum_min_max::min_max_update_str_field() { - DBUG_ENTER("Item_sum_hybrid::min_max_update_str_field"); + DBUG_ENTER("Item_sum_min_max::min_max_update_str_field"); DBUG_ASSERT(cmp); String *res_str=args[0]->val_str(&cmp->value1); @@ -3104,11 +3104,11 @@ Item_sum_hybrid::min_max_update_str_field() void -Item_sum_hybrid::min_max_update_real_field() +Item_sum_min_max::min_max_update_real_field() { double nr,old_nr; - DBUG_ENTER("Item_sum_hybrid::min_max_update_real_field"); + DBUG_ENTER("Item_sum_min_max::min_max_update_real_field"); old_nr=result_field->val_real(); nr= args[0]->val_real(); if (!args[0]->null_value) @@ -3126,11 +3126,11 @@ Item_sum_hybrid::min_max_update_real_field() void -Item_sum_hybrid::min_max_update_int_field() +Item_sum_min_max::min_max_update_int_field() { longlong nr,old_nr; - DBUG_ENTER("Item_sum_hybrid::min_max_update_int_field"); + DBUG_ENTER("Item_sum_min_max::min_max_update_int_field"); old_nr=result_field->val_int(); nr=args[0]->val_int(); if (!args[0]->null_value) @@ -3161,9 +3161,9 @@ Item_sum_hybrid::min_max_update_int_field() optimize: do not get result_field in case of args[0] is NULL */ void -Item_sum_hybrid::min_max_update_decimal_field() +Item_sum_min_max::min_max_update_decimal_field() { - DBUG_ENTER("Item_sum_hybrid::min_max_update_decimal_field"); + DBUG_ENTER("Item_sum_min_max::min_max_update_decimal_field"); my_decimal old_val, nr_val; const my_decimal *old_nr; const my_decimal *nr= args[0]->val_decimal(&nr_val); diff --git a/sql/item_sum.h b/sql/item_sum.h index ef849782464..df37d0dbfa4 100644 --- a/sql/item_sum.h +++ b/sql/item_sum.h @@ -1025,10 +1025,32 @@ class Item_sum_std :public Item_sum_variance { return get_item_copy(thd, this); } }; + +class Item_sum_hybrid: public Item_sum, + public Type_handler_hybrid_field_type +{ +public: + Item_sum_hybrid(THD *thd, Item *item_par): + Item_sum(thd, item_par), + Type_handler_hybrid_field_type(&type_handler_longlong) + { collation.set(&my_charset_bin); } + Item_sum_hybrid(THD *thd, Item *a, Item *b): + Item_sum(thd, a, b), + Type_handler_hybrid_field_type(&type_handler_longlong) + { collation.set(&my_charset_bin); } + Item_sum_hybrid(THD *thd, Item_sum_hybrid *item) + :Item_sum(thd, item), + Type_handler_hybrid_field_type(item) + { } + const Type_handler *type_handler() const + { return Type_handler_hybrid_field_type::type_handler(); } +}; + + // This class is a string or number function depending on num_func class Arg_comparator; class Item_cache; -class Item_sum_hybrid :public Item_sum, public Type_handler_hybrid_field_type +class Item_sum_min_max :public Item_sum_hybrid { protected: bool direct_added; @@ -1039,16 +1061,14 @@ protected: bool was_values; // Set if we have found at least one row (for max/min only) bool was_null_value; - public: - Item_sum_hybrid(THD *thd, Item *item_par,int sign): - Item_sum(thd, item_par), - Type_handler_hybrid_field_type(&type_handler_longlong), +public: + Item_sum_min_max(THD *thd, Item *item_par,int sign): + Item_sum_hybrid(thd, item_par), direct_added(FALSE), value(0), arg_cache(0), cmp(0), cmp_sign(sign), was_values(TRUE) { collation.set(&my_charset_bin); } - Item_sum_hybrid(THD *thd, Item_sum_hybrid *item) - :Item_sum(thd, item), - Type_handler_hybrid_field_type(item), + Item_sum_min_max(THD *thd, Item_sum_min_max *item) + :Item_sum_hybrid(thd, item), direct_added(FALSE), value(item->value), arg_cache(0), cmp_sign(item->cmp_sign), was_values(item->was_values) { } @@ -1067,8 +1087,6 @@ protected: { return get_arg(0)->real_type_handler(); } - const Type_handler *type_handler() const - { return Type_handler_hybrid_field_type::type_handler(); } TYPELIB *get_typelib() const { return args[0]->get_typelib(); } void update_field(); void min_max_update_str_field(); @@ -1084,11 +1102,11 @@ protected: }; -class Item_sum_min :public Item_sum_hybrid +class Item_sum_min :public Item_sum_min_max { public: - Item_sum_min(THD *thd, Item *item_par): Item_sum_hybrid(thd, item_par, 1) {} - Item_sum_min(THD *thd, Item_sum_min *item) :Item_sum_hybrid(thd, item) {} + Item_sum_min(THD *thd, Item *item_par): Item_sum_min_max(thd, item_par, 1) {} + Item_sum_min(THD *thd, Item_sum_min *item) :Item_sum_min_max(thd, item) {} enum Sumfunctype sum_func () const {return MIN_FUNC;} bool add(); @@ -1099,11 +1117,11 @@ public: }; -class Item_sum_max :public Item_sum_hybrid +class Item_sum_max :public Item_sum_min_max { public: - Item_sum_max(THD *thd, Item *item_par): Item_sum_hybrid(thd, item_par, -1) {} - Item_sum_max(THD *thd, Item_sum_max *item) :Item_sum_hybrid(thd, item) {} + Item_sum_max(THD *thd, Item *item_par): Item_sum_min_max(thd, item_par, -1) {} + Item_sum_max(THD *thd, Item_sum_max *item) :Item_sum_min_max(thd, item) {} enum Sumfunctype sum_func () const {return MAX_FUNC;} bool add(); diff --git a/sql/item_windowfunc.h b/sql/item_windowfunc.h index 144deb18d8c..37376501d1f 100644 --- a/sql/item_windowfunc.h +++ b/sql/item_windowfunc.h @@ -292,21 +292,18 @@ class Item_sum_dense_rank: public Item_sum_int { return get_item_copy(thd, this); } }; -class Item_sum_hybrid_simple : public Item_sum, - public Type_handler_hybrid_field_type +class Item_sum_hybrid_simple : public Item_sum_hybrid { public: Item_sum_hybrid_simple(THD *thd, Item *arg): - Item_sum(thd, arg), - Type_handler_hybrid_field_type(&type_handler_longlong), + Item_sum_hybrid(thd, arg), value(NULL) - { collation.set(&my_charset_bin); } + { } Item_sum_hybrid_simple(THD *thd, Item *arg1, Item *arg2): - Item_sum(thd, arg1, arg2), - Type_handler_hybrid_field_type(&type_handler_longlong), + Item_sum_hybrid(thd, arg1, arg2), value(NULL) - { collation.set(&my_charset_bin); } + { } bool add(); bool fix_fields(THD *, Item **); @@ -317,8 +314,6 @@ class Item_sum_hybrid_simple : public Item_sum, void reset_field(); String *val_str(String *); bool get_date(MYSQL_TIME *ltime, ulonglong fuzzydate); - const Type_handler *type_handler() const - { return Type_handler_hybrid_field_type::type_handler(); } void update_field(); Field *create_tmp_field(bool group, TABLE *table); void clear() diff --git a/sql/sql_type.cc b/sql/sql_type.cc index 665ccd28595..573d9721fc1 100644 --- a/sql/sql_type.cc +++ b/sql/sql_type.cc @@ -365,7 +365,7 @@ Type_handler::blob_type_handler(const Item *item) /** This method is used by: - - Item_sum_hybrid, e.g. MAX(item), MIN(item). + - Item_sum_min_max, e.g. MAX(item), MIN(item). - Item_func_set_user_var */ const Type_handler * @@ -3086,9 +3086,9 @@ bool Type_handler_real_result:: QQ: Items should probably be fixed to preserve the exact type. */ bool Type_handler_numeric:: - Item_sum_hybrid_fix_length_and_dec_numeric(Item_sum_hybrid *func, - const Type_handler *handler) - const + Item_sum_min_max_fix_length_and_dec_numeric(Item_sum_min_max *func, + const Type_handler *handler) + const { Item *item= func->arguments()[0]; Item *item2= item->real_item(); @@ -3104,28 +3104,28 @@ bool Type_handler_numeric:: bool Type_handler_int_result:: - Item_sum_hybrid_fix_length_and_dec(Item_sum_hybrid *func) const + Item_sum_min_max_fix_length_and_dec(Item_sum_min_max *func) const { - return Item_sum_hybrid_fix_length_and_dec_numeric(func, - &type_handler_longlong); + return Item_sum_min_max_fix_length_and_dec_numeric(func, + &type_handler_longlong); } bool Type_handler_real_result:: - Item_sum_hybrid_fix_length_and_dec(Item_sum_hybrid *func) const + Item_sum_min_max_fix_length_and_dec(Item_sum_min_max *func) const { - (void) Item_sum_hybrid_fix_length_and_dec_numeric(func, - &type_handler_double); + (void) Item_sum_min_max_fix_length_and_dec_numeric(func, + &type_handler_double); func->max_length= func->float_length(func->decimals); return false; } bool Type_handler_decimal_result:: - Item_sum_hybrid_fix_length_and_dec(Item_sum_hybrid *func) const + Item_sum_min_max_fix_length_and_dec(Item_sum_min_max *func) const { - return Item_sum_hybrid_fix_length_and_dec_numeric(func, - &type_handler_newdecimal); + return Item_sum_min_max_fix_length_and_dec_numeric(func, + &type_handler_newdecimal); } @@ -3138,7 +3138,7 @@ bool Type_handler_decimal_result:: MAX(str_item) chooses the best suitable string type. */ bool Type_handler_string_result:: - Item_sum_hybrid_fix_length_and_dec(Item_sum_hybrid *func) const + Item_sum_min_max_fix_length_and_dec(Item_sum_min_max *func) const { Item *item= func->arguments()[0]; Item *item2= item->real_item(); @@ -3164,7 +3164,7 @@ bool Type_handler_string_result:: Traditional temporal types always preserve the type of the argument. */ bool Type_handler_temporal_result:: - Item_sum_hybrid_fix_length_and_dec(Item_sum_hybrid *func) const + Item_sum_min_max_fix_length_and_dec(Item_sum_min_max *func) const { Item *item= func->arguments()[0]; func->Type_std_attributes::set(item); diff --git a/sql/sql_type.h b/sql/sql_type.h index ef1a44a420c..3ef210efecf 100644 --- a/sql/sql_type.h +++ b/sql/sql_type.h @@ -33,7 +33,7 @@ class Item; class Item_param; class Item_cache; class Item_func_or_sum; -class Item_sum_hybrid; +class Item_sum_min_max; class Item_sum_sum; class Item_sum_avg; class Item_sum_variance; @@ -1314,7 +1314,7 @@ public: Item_func_min_max *func, Item **items, uint nitems) const; - virtual bool Item_sum_hybrid_fix_length_and_dec(Item_sum_hybrid *) const= 0; + virtual bool Item_sum_min_max_fix_length_and_dec(Item_sum_min_max *) const= 0; virtual bool Item_sum_sum_fix_length_and_dec(Item_sum_sum *) const= 0; virtual bool Item_sum_avg_fix_length_and_dec(Item_sum_avg *) const= 0; virtual @@ -1563,7 +1563,7 @@ public: DBUG_ASSERT(0); return true; } - bool Item_sum_hybrid_fix_length_and_dec(Item_sum_hybrid *func) const + bool Item_sum_min_max_fix_length_and_dec(Item_sum_min_max *func) const { DBUG_ASSERT(0); return true; @@ -1743,9 +1743,9 @@ public: class Type_handler_numeric: public Type_handler { protected: - bool Item_sum_hybrid_fix_length_and_dec_numeric(Item_sum_hybrid *func, - const Type_handler *handler) - const; + bool Item_sum_min_max_fix_length_and_dec_numeric(Item_sum_min_max *func, + const Type_handler *handler) + const; public: String *print_item_value(THD *thd, Item *item, String *str) const; double Item_func_min_max_val_real(Item_func_min_max *) const; @@ -1796,7 +1796,7 @@ public: Item **items, uint nitems) const; bool Item_func_min_max_fix_attributes(THD *thd, Item_func_min_max *func, Item **items, uint nitems) const; - bool Item_sum_hybrid_fix_length_and_dec(Item_sum_hybrid *func) const; + bool Item_sum_min_max_fix_length_and_dec(Item_sum_min_max *func) const; bool Item_sum_sum_fix_length_and_dec(Item_sum_sum *) const; bool Item_sum_avg_fix_length_and_dec(Item_sum_avg *) const; bool Item_sum_variance_fix_length_and_dec(Item_sum_variance *) const; @@ -1874,7 +1874,7 @@ public: Type_handler_hybrid_field_type *, Type_all_attributes *atrr, Item **items, uint nitems) const; - bool Item_sum_hybrid_fix_length_and_dec(Item_sum_hybrid *func) const; + bool Item_sum_min_max_fix_length_and_dec(Item_sum_min_max *func) const; bool Item_sum_sum_fix_length_and_dec(Item_sum_sum *) const; bool Item_sum_avg_fix_length_and_dec(Item_sum_avg *) const; bool Item_sum_variance_fix_length_and_dec(Item_sum_variance *) const; @@ -2068,7 +2068,7 @@ public: Type_handler_hybrid_field_type *, Type_all_attributes *atrr, Item **items, uint nitems) const; - bool Item_sum_hybrid_fix_length_and_dec(Item_sum_hybrid *func) const; + bool Item_sum_min_max_fix_length_and_dec(Item_sum_min_max *func) const; bool Item_sum_sum_fix_length_and_dec(Item_sum_sum *) const; bool Item_sum_avg_fix_length_and_dec(Item_sum_avg *) const; bool Item_sum_variance_fix_length_and_dec(Item_sum_variance *) const; @@ -2145,7 +2145,7 @@ public: const Item *outer) const; bool Item_func_min_max_fix_attributes(THD *thd, Item_func_min_max *func, Item **items, uint nitems) const; - bool Item_sum_hybrid_fix_length_and_dec(Item_sum_hybrid *func) const; + bool Item_sum_min_max_fix_length_and_dec(Item_sum_min_max *func) const; bool Item_sum_sum_fix_length_and_dec(Item_sum_sum *) const; bool Item_sum_avg_fix_length_and_dec(Item_sum_avg *) const; bool Item_sum_variance_fix_length_and_dec(Item_sum_variance *) const; @@ -2258,7 +2258,7 @@ public: Type_handler_hybrid_field_type *, Type_all_attributes *atrr, Item **items, uint nitems) const; - bool Item_sum_hybrid_fix_length_and_dec(Item_sum_hybrid *func) const; + bool Item_sum_min_max_fix_length_and_dec(Item_sum_min_max *func) const; bool Item_sum_sum_fix_length_and_dec(Item_sum_sum *) const; bool Item_sum_avg_fix_length_and_dec(Item_sum_avg *) const; bool Item_sum_variance_fix_length_and_dec(Item_sum_variance *) const; diff --git a/storage/spider/spd_db_conn.cc b/storage/spider/spd_db_conn.cc index 01b3a681130..cc4599ce0b3 100644 --- a/storage/spider/spd_db_conn.cc +++ b/storage/spider/spd_db_conn.cc @@ -2705,7 +2705,7 @@ int spider_db_fetch_for_item_sum_func( thd->free_list = free_list; } - Item_sum_hybrid *item_hybrid = (Item_sum_hybrid *) item_sum; + Item_sum_min_max *item_sum_min_max = (Item_sum_min_max *) item_sum; Item_string *item = (Item_string *) spider->direct_aggregate_item_current->item; if (row->is_null()) @@ -2732,7 +2732,7 @@ int spider_db_fetch_for_item_sum_func( #endif item->null_value = FALSE; } - item_hybrid->direct_add(item); + item_sum_min_max->direct_add(item); row->next(); } break; From d70dac207930ab74add149be692a775bc2952aaa Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Wed, 7 Aug 2019 21:01:22 +0400 Subject: [PATCH 09/14] MDEV-20278 PERCENTILE_DISC() returns a wrong data type --- mysql-test/main/win_percentile.result | 281 +++++++++++++++++--------- mysql-test/main/win_percentile.test | 63 ++++++ sql/item_windowfunc.cc | 12 +- sql/item_windowfunc.h | 11 - sql/sql_type.h | 4 - 5 files changed, 256 insertions(+), 115 deletions(-) diff --git a/mysql-test/main/win_percentile.result b/mysql-test/main/win_percentile.result index 4a918bad17f..19c400c3f2b 100644 --- a/mysql-test/main/win_percentile.result +++ b/mysql-test/main/win_percentile.result @@ -36,23 +36,23 @@ Tata 4.0000000000 Tatiana 4.0000000000 select name, percentile_disc(0.5) within group(order by score) over (partition by name) as c from t1; name c -Chun 3.0000000000 -Chun 3.0000000000 -Kaolin 4.0000000000 -Kaolin 4.0000000000 -Kaolin 4.0000000000 -Tata 4.0000000000 -Tatiana 4.0000000000 +Chun 3.0000 +Chun 3.0000 +Kaolin 4.0000 +Kaolin 4.0000 +Kaolin 4.0000 +Tata 4.0000 +Tatiana 4.0000 # no partition clause select name, percentile_disc(0.5) within group(order by score) over () from t1; name percentile_disc(0.5) within group(order by score) over () -Chun 4.0000000000 -Chun 4.0000000000 -Kaolin 4.0000000000 -Kaolin 4.0000000000 -Kaolin 4.0000000000 -Tata 4.0000000000 -Tatiana 4.0000000000 +Chun 4.0000 +Chun 4.0000 +Kaolin 4.0000 +Kaolin 4.0000 +Kaolin 4.0000 +Tata 4.0000 +Tatiana 4.0000 select name, percentile_cont(0.5) within group(order by score) over () from t1; name percentile_cont(0.5) within group(order by score) over () Chun 4.0000000000 @@ -79,13 +79,13 @@ Tata 4.0000000000 Tatiana 4.0000000000 select * from ( select name , percentile_disc(0.5) within group ( order by score) over (partition by name ) from t1 ) as t; name percentile_disc(0.5) within group ( order by score) over (partition by name ) -Chun 3.0000000000 -Chun 3.0000000000 -Kaolin 4.0000000000 -Kaolin 4.0000000000 -Kaolin 4.0000000000 -Tata 4.0000000000 -Tatiana 4.0000000000 +Chun 3.0000 +Chun 3.0000 +Kaolin 4.0000 +Kaolin 4.0000 +Kaolin 4.0000 +Tata 4.0000 +Tatiana 4.0000 select name from t1 a where (select percentile_disc(0.5) within group (order by score) over (partition by name) from t1 b limit 1) >= 0.5; name Chun @@ -118,13 +118,13 @@ ERROR HY000: percentile_disc function only accepts arguments that can be convert #complete query with partition column select name,cume_dist() over (partition by name order by score), percentile_disc(0.5) within group(order by score) over (partition by name) as c from t1; name cume_dist() over (partition by name order by score) c -Chun 0.5000000000 3.0000000000 -Chun 1.0000000000 3.0000000000 -Kaolin 0.3333333333 4.0000000000 -Kaolin 0.6666666667 4.0000000000 -Kaolin 1.0000000000 4.0000000000 -Tata 1.0000000000 4.0000000000 -Tatiana 1.0000000000 4.0000000000 +Chun 0.5000000000 3.0000 +Chun 1.0000000000 3.0000 +Kaolin 0.3333333333 4.0000 +Kaolin 0.6666666667 4.0000 +Kaolin 1.0000000000 4.0000 +Tata 1.0000000000 4.0000 +Tatiana 1.0000000000 4.0000 select name, percentile_cont(0.5) within group(order by score) over (partition by name) as c from t1; name c Chun 5.0000000000 @@ -136,94 +136,94 @@ Tata 4.0000000000 Tatiana 4.0000000000 select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.1) within group(order by score) over (partition by name) as c from t1; name b c -Chun 0.5000000000 3.0000000000 -Chun 1.0000000000 3.0000000000 -Kaolin 0.3333333333 3.0000000000 -Kaolin 0.6666666667 3.0000000000 -Kaolin 1.0000000000 3.0000000000 -Tata 1.0000000000 4.0000000000 -Tatiana 1.0000000000 4.0000000000 +Chun 0.5000000000 3.0000 +Chun 1.0000000000 3.0000 +Kaolin 0.3333333333 3.0000 +Kaolin 0.6666666667 3.0000 +Kaolin 1.0000000000 3.0000 +Tata 1.0000000000 4.0000 +Tatiana 1.0000000000 4.0000 select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.2) within group(order by score) over (partition by name) as c from t1; name b c -Chun 0.5000000000 3.0000000000 -Chun 1.0000000000 3.0000000000 -Kaolin 0.3333333333 3.0000000000 -Kaolin 0.6666666667 3.0000000000 -Kaolin 1.0000000000 3.0000000000 -Tata 1.0000000000 4.0000000000 -Tatiana 1.0000000000 4.0000000000 +Chun 0.5000000000 3.0000 +Chun 1.0000000000 3.0000 +Kaolin 0.3333333333 3.0000 +Kaolin 0.6666666667 3.0000 +Kaolin 1.0000000000 3.0000 +Tata 1.0000000000 4.0000 +Tatiana 1.0000000000 4.0000 select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.3) within group(order by score) over (partition by name) as c from t1; name b c -Chun 0.5000000000 3.0000000000 -Chun 1.0000000000 3.0000000000 -Kaolin 0.3333333333 3.0000000000 -Kaolin 0.6666666667 3.0000000000 -Kaolin 1.0000000000 3.0000000000 -Tata 1.0000000000 4.0000000000 -Tatiana 1.0000000000 4.0000000000 +Chun 0.5000000000 3.0000 +Chun 1.0000000000 3.0000 +Kaolin 0.3333333333 3.0000 +Kaolin 0.6666666667 3.0000 +Kaolin 1.0000000000 3.0000 +Tata 1.0000000000 4.0000 +Tatiana 1.0000000000 4.0000 select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.4) within group(order by score) over (partition by name) as c from t1; name b c -Chun 0.5000000000 3.0000000000 -Chun 1.0000000000 3.0000000000 -Kaolin 0.3333333333 4.0000000000 -Kaolin 0.6666666667 4.0000000000 -Kaolin 1.0000000000 4.0000000000 -Tata 1.0000000000 4.0000000000 -Tatiana 1.0000000000 4.0000000000 +Chun 0.5000000000 3.0000 +Chun 1.0000000000 3.0000 +Kaolin 0.3333333333 4.0000 +Kaolin 0.6666666667 4.0000 +Kaolin 1.0000000000 4.0000 +Tata 1.0000000000 4.0000 +Tatiana 1.0000000000 4.0000 select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.5) within group(order by score) over (partition by name) as c from t1; name b c -Chun 0.5000000000 3.0000000000 -Chun 1.0000000000 3.0000000000 -Kaolin 0.3333333333 4.0000000000 -Kaolin 0.6666666667 4.0000000000 -Kaolin 1.0000000000 4.0000000000 -Tata 1.0000000000 4.0000000000 -Tatiana 1.0000000000 4.0000000000 +Chun 0.5000000000 3.0000 +Chun 1.0000000000 3.0000 +Kaolin 0.3333333333 4.0000 +Kaolin 0.6666666667 4.0000 +Kaolin 1.0000000000 4.0000 +Tata 1.0000000000 4.0000 +Tatiana 1.0000000000 4.0000 select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.6) within group(order by score) over (partition by name) as c from t1; name b c -Chun 0.5000000000 7.0000000000 -Chun 1.0000000000 7.0000000000 -Kaolin 0.3333333333 4.0000000000 -Kaolin 0.6666666667 4.0000000000 -Kaolin 1.0000000000 4.0000000000 -Tata 1.0000000000 4.0000000000 -Tatiana 1.0000000000 4.0000000000 +Chun 0.5000000000 7.0000 +Chun 1.0000000000 7.0000 +Kaolin 0.3333333333 4.0000 +Kaolin 0.6666666667 4.0000 +Kaolin 1.0000000000 4.0000 +Tata 1.0000000000 4.0000 +Tatiana 1.0000000000 4.0000 select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.7) within group(order by score) over (partition by name) as c from t1; name b c -Chun 0.5000000000 7.0000000000 -Chun 1.0000000000 7.0000000000 -Kaolin 0.3333333333 7.0000000000 -Kaolin 0.6666666667 7.0000000000 -Kaolin 1.0000000000 7.0000000000 -Tata 1.0000000000 4.0000000000 -Tatiana 1.0000000000 4.0000000000 +Chun 0.5000000000 7.0000 +Chun 1.0000000000 7.0000 +Kaolin 0.3333333333 7.0000 +Kaolin 0.6666666667 7.0000 +Kaolin 1.0000000000 7.0000 +Tata 1.0000000000 4.0000 +Tatiana 1.0000000000 4.0000 select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.8) within group(order by score) over (partition by name) as c from t1; name b c -Chun 0.5000000000 7.0000000000 -Chun 1.0000000000 7.0000000000 -Kaolin 0.3333333333 7.0000000000 -Kaolin 0.6666666667 7.0000000000 -Kaolin 1.0000000000 7.0000000000 -Tata 1.0000000000 4.0000000000 -Tatiana 1.0000000000 4.0000000000 +Chun 0.5000000000 7.0000 +Chun 1.0000000000 7.0000 +Kaolin 0.3333333333 7.0000 +Kaolin 0.6666666667 7.0000 +Kaolin 1.0000000000 7.0000 +Tata 1.0000000000 4.0000 +Tatiana 1.0000000000 4.0000 select name,cume_dist() over (partition by name order by score) as b, percentile_disc(0.9) within group(order by score) over (partition by name) as c from t1; name b c -Chun 0.5000000000 7.0000000000 -Chun 1.0000000000 7.0000000000 -Kaolin 0.3333333333 7.0000000000 -Kaolin 0.6666666667 7.0000000000 -Kaolin 1.0000000000 7.0000000000 -Tata 1.0000000000 4.0000000000 -Tatiana 1.0000000000 4.0000000000 +Chun 0.5000000000 7.0000 +Chun 1.0000000000 7.0000 +Kaolin 0.3333333333 7.0000 +Kaolin 0.6666666667 7.0000 +Kaolin 1.0000000000 7.0000 +Tata 1.0000000000 4.0000 +Tatiana 1.0000000000 4.0000 select name,cume_dist() over (partition by name order by score) as b, percentile_disc(1) within group(order by score) over (partition by name) as c from t1; name b c -Chun 0.5000000000 7.0000000000 -Chun 1.0000000000 7.0000000000 -Kaolin 0.3333333333 7.0000000000 -Kaolin 0.6666666667 7.0000000000 -Kaolin 1.0000000000 7.0000000000 -Tata 1.0000000000 4.0000000000 -Tatiana 1.0000000000 4.0000000000 +Chun 0.5000000000 7.0000 +Chun 1.0000000000 7.0000 +Kaolin 0.3333333333 7.0000 +Kaolin 0.6666666667 7.0000 +Kaolin 1.0000000000 7.0000 +Tata 1.0000000000 4.0000 +Tatiana 1.0000000000 4.0000 select median(score) over (partition by name), percentile_cont(0) within group(order by score) over (partition by name) as c from t1; median(score) over (partition by name) c 5.0000000000 3.0000000000 @@ -366,3 +366,88 @@ median(val) OVER () 2.0000000000 drop table t1; drop view v1; +# +# MDEV-20278 PERCENTILE_DISC() returns a wrong data type +# +# INT variants +CREATE TABLE t1 (name CHAR(30), star_rating INT); +INSERT INTO t1 VALUES ('Lord of the Ladybirds', 5); +INSERT INTO t1 VALUES ('Lord of the Ladybirds', 3); +INSERT INTO t1 VALUES ('Lady of the Flies', 1); +INSERT INTO t1 VALUES ('Lady of the Flies', 2); +INSERT INTO t1 VALUES ('Lady of the Flies', 5); +CREATE OR REPLACE TABLE t2 AS SELECT name, PERCENTILE_DISC(0.5) +WITHIN GROUP (ORDER BY star_rating) +OVER (PARTITION BY name) AS pc FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `name` char(30) DEFAULT NULL, + `pc` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t2, t1; +# UNSIGNED INT variants +CREATE OR REPLACE TABLE t1 (name CHAR(30), star_rating BIGINT UNSIGNED); +INSERT INTO t1 VALUES ('Lord of the Ladybirds', 0x8000000000000005); +INSERT INTO t1 VALUES ('Lord of the Ladybirds', 0x8000000000000003); +INSERT INTO t1 VALUES ('Lady of the Flies', 0x8000000000000001); +INSERT INTO t1 VALUES ('Lady of the Flies', 0x8000000000000002); +INSERT INTO t1 VALUES ('Lady of the Flies', 0x8000000000000003); +CREATE OR REPLACE TABLE t2 AS SELECT name, PERCENTILE_DISC(0.5) +WITHIN GROUP (ORDER BY star_rating) +OVER (PARTITION BY name) AS pc FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `name` char(30) DEFAULT NULL, + `pc` bigint(20) unsigned DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT name, pc, HEX(pc) FROM t2 ORDER BY name, pc; +name pc HEX(pc) +Lady of the Flies 9223372036854775810 8000000000000002 +Lady of the Flies 9223372036854775810 8000000000000002 +Lady of the Flies 9223372036854775810 8000000000000002 +Lord of the Ladybirds 9223372036854775811 8000000000000003 +Lord of the Ladybirds 9223372036854775811 8000000000000003 +DROP TABLE t2, t1; +# FLOAT variants +CREATE TABLE t1 (name CHAR(30), star_rating FLOAT); +INSERT INTO t1 VALUES ('Lord of the Ladybirds', 5); +INSERT INTO t1 VALUES ('Lord of the Ladybirds', 3); +INSERT INTO t1 VALUES ('Lady of the Flies', 1); +INSERT INTO t1 VALUES ('Lady of the Flies', 2); +INSERT INTO t1 VALUES ('Lady of the Flies', 5); +CREATE TABLE t2 AS SELECT name, PERCENTILE_DISC(0.5) +WITHIN GROUP (ORDER BY star_rating) +OVER (PARTITION BY name) AS pc FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `name` char(30) DEFAULT NULL, + `pc` float DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t2, t1; +# DECIMAL variants +CREATE OR REPLACE TABLE t1 (name CHAR(30), star_rating DECIMAL(30,2)); +INSERT INTO t1 VALUES ('Lord of the Ladybirds', 50000000000); +INSERT INTO t1 VALUES ('Lord of the Ladybirds', 30000000000); +INSERT INTO t1 VALUES ('Lady of the Flies', 10000000000); +INSERT INTO t1 VALUES ('Lady of the Flies', 20000000000); +INSERT INTO t1 VALUES ('Lady of the Flies', 50000000000); +CREATE OR REPLACE TABLE t2 AS SELECT name, PERCENTILE_DISC(0.5) +WITHIN GROUP (ORDER BY star_rating) +OVER (PARTITION BY name) AS pc FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `name` char(30) DEFAULT NULL, + `pc` decimal(30,2) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT * FROM t2 ORDER BY name, pc; +name pc +Lady of the Flies 20000000000.00 +Lady of the Flies 20000000000.00 +Lady of the Flies 20000000000.00 +Lord of the Ladybirds 30000000000.00 +Lord of the Ladybirds 30000000000.00 +DROP TABLE t2, t1; diff --git a/mysql-test/main/win_percentile.test b/mysql-test/main/win_percentile.test index d36b365dd9b..2b3fffc4508 100644 --- a/mysql-test/main/win_percentile.test +++ b/mysql-test/main/win_percentile.test @@ -146,3 +146,66 @@ select * from v1; select median(val) OVER () FROM t1; drop table t1; drop view v1; + + +--echo # +--echo # MDEV-20278 PERCENTILE_DISC() returns a wrong data type +--echo # + +--echo # INT variants + +CREATE TABLE t1 (name CHAR(30), star_rating INT); +INSERT INTO t1 VALUES ('Lord of the Ladybirds', 5); +INSERT INTO t1 VALUES ('Lord of the Ladybirds', 3); +INSERT INTO t1 VALUES ('Lady of the Flies', 1); +INSERT INTO t1 VALUES ('Lady of the Flies', 2); +INSERT INTO t1 VALUES ('Lady of the Flies', 5); +CREATE OR REPLACE TABLE t2 AS SELECT name, PERCENTILE_DISC(0.5) + WITHIN GROUP (ORDER BY star_rating) + OVER (PARTITION BY name) AS pc FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t2, t1; + +--echo # UNSIGNED INT variants + +CREATE OR REPLACE TABLE t1 (name CHAR(30), star_rating BIGINT UNSIGNED); +INSERT INTO t1 VALUES ('Lord of the Ladybirds', 0x8000000000000005); +INSERT INTO t1 VALUES ('Lord of the Ladybirds', 0x8000000000000003); +INSERT INTO t1 VALUES ('Lady of the Flies', 0x8000000000000001); +INSERT INTO t1 VALUES ('Lady of the Flies', 0x8000000000000002); +INSERT INTO t1 VALUES ('Lady of the Flies', 0x8000000000000003); +CREATE OR REPLACE TABLE t2 AS SELECT name, PERCENTILE_DISC(0.5) + WITHIN GROUP (ORDER BY star_rating) + OVER (PARTITION BY name) AS pc FROM t1; +SHOW CREATE TABLE t2; +SELECT name, pc, HEX(pc) FROM t2 ORDER BY name, pc; +DROP TABLE t2, t1; + +--echo # FLOAT variants + +CREATE TABLE t1 (name CHAR(30), star_rating FLOAT); +INSERT INTO t1 VALUES ('Lord of the Ladybirds', 5); +INSERT INTO t1 VALUES ('Lord of the Ladybirds', 3); +INSERT INTO t1 VALUES ('Lady of the Flies', 1); +INSERT INTO t1 VALUES ('Lady of the Flies', 2); +INSERT INTO t1 VALUES ('Lady of the Flies', 5); +CREATE TABLE t2 AS SELECT name, PERCENTILE_DISC(0.5) + WITHIN GROUP (ORDER BY star_rating) + OVER (PARTITION BY name) AS pc FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t2, t1; + +--echo # DECIMAL variants + +CREATE OR REPLACE TABLE t1 (name CHAR(30), star_rating DECIMAL(30,2)); +INSERT INTO t1 VALUES ('Lord of the Ladybirds', 50000000000); +INSERT INTO t1 VALUES ('Lord of the Ladybirds', 30000000000); +INSERT INTO t1 VALUES ('Lady of the Flies', 10000000000); +INSERT INTO t1 VALUES ('Lady of the Flies', 20000000000); +INSERT INTO t1 VALUES ('Lady of the Flies', 50000000000); +CREATE OR REPLACE TABLE t2 AS SELECT name, PERCENTILE_DISC(0.5) + WITHIN GROUP (ORDER BY star_rating) + OVER (PARTITION BY name) AS pc FROM t1; +SHOW CREATE TABLE t2; +SELECT * FROM t2 ORDER BY name, pc; +DROP TABLE t2, t1; diff --git a/sql/item_windowfunc.cc b/sql/item_windowfunc.cc index 2db396d3065..85e5144779e 100644 --- a/sql/item_windowfunc.cc +++ b/sql/item_windowfunc.cc @@ -174,7 +174,8 @@ bool Item_window_func::check_result_type_of_order_item() { if (only_single_element_order_list()) { - Item_result rtype= window_spec->order_list->first->item[0]->cmp_type(); + Item *src_item= window_spec->order_list->first->item[0]; + Item_result rtype= src_item->cmp_type(); // TODO (varun) : support date type in percentile_cont function if (rtype != REAL_RESULT && rtype != INT_RESULT && rtype != DECIMAL_RESULT && rtype != TIME_RESULT) @@ -182,7 +183,14 @@ bool Item_window_func::check_result_type_of_order_item() my_error(ER_WRONG_TYPE_FOR_PERCENTILE_FUNC, MYF(0), window_func()->func_name()); return TRUE; } - setting_handler_for_percentile_functions(rtype); + if (window_func()->sum_func() == Item_sum::PERCENTILE_DISC_FUNC) + { + Item_sum_percentile_disc *func= + static_cast(window_func()); + func->set_handler(src_item->type_handler()); + func->Type_std_attributes::set(src_item); + Type_std_attributes::set(src_item); + } } return FALSE; } diff --git a/sql/item_windowfunc.h b/sql/item_windowfunc.h index 37376501d1f..1432643dfc8 100644 --- a/sql/item_windowfunc.h +++ b/sql/item_windowfunc.h @@ -1097,17 +1097,6 @@ public: } } - void setting_handler_for_percentile_functions(Item_result rtype) const - { - switch (window_func()->sum_func()){ - case Item_sum::PERCENTILE_DISC_FUNC: - ((Item_sum_percentile_disc* ) window_func())->set_handler_by_cmp_type(rtype); - break; - default: - return; - } - } - bool check_result_type_of_order_item(); diff --git a/sql/sql_type.h b/sql/sql_type.h index 3ef210efecf..a7915ddc463 100644 --- a/sql/sql_type.h +++ b/sql/sql_type.h @@ -3506,10 +3506,6 @@ public: { return (m_type_handler= Type_handler::get_handler_by_result_type(type)); } - const Type_handler *set_handler_by_cmp_type(Item_result type) - { - return (m_type_handler= Type_handler::get_handler_by_cmp_type(type)); - } const Type_handler *set_handler_by_result_type(Item_result type, uint max_octet_length, CHARSET_INFO *cs) From 7fc86a73d8fbfa6d527d9eb1160bedaf939eae7a Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Wed, 7 Aug 2019 22:44:54 +0400 Subject: [PATCH 10/14] MDEV-20272 PERCENTILE_DISC() crashes on a temporal type input --- mysql-test/main/win_percentile.result | 14 ++++++++++++ mysql-test/main/win_percentile.test | 17 ++++++++++++++ sql/item_windowfunc.cc | 33 +++++++++++++++++++-------- 3 files changed, 54 insertions(+), 10 deletions(-) diff --git a/mysql-test/main/win_percentile.result b/mysql-test/main/win_percentile.result index 19c400c3f2b..a2ca775fcfb 100644 --- a/mysql-test/main/win_percentile.result +++ b/mysql-test/main/win_percentile.result @@ -451,3 +451,17 @@ Lady of the Flies 20000000000.00 Lord of the Ladybirds 30000000000.00 Lord of the Ladybirds 30000000000.00 DROP TABLE t2, t1; +# +# MDEV-20272 PERCENTILE_DISC() crashes on a temporal type input +# +CREATE OR REPLACE TABLE t1 (name CHAR(30), star_rating TIME); +INSERT INTO t1 VALUES ('Lord of the Ladybirds', 5); +INSERT INTO t1 VALUES ('Lord of the Ladybirds', 3); +INSERT INTO t1 VALUES ('Lady of the Flies', 1); +INSERT INTO t1 VALUES ('Lady of the Flies', 2); +INSERT INTO t1 VALUES ('Lady of the Flies', 5); +SELECT name, PERCENTILE_DISC(0.5) +WITHIN GROUP (ORDER BY star_rating) +OVER (PARTITION BY name) AS pc FROM t1; +ERROR HY000: Numeric datatype is required for percentile_disc function +DROP TABLE t1; diff --git a/mysql-test/main/win_percentile.test b/mysql-test/main/win_percentile.test index 2b3fffc4508..8705be123ff 100644 --- a/mysql-test/main/win_percentile.test +++ b/mysql-test/main/win_percentile.test @@ -209,3 +209,20 @@ CREATE OR REPLACE TABLE t2 AS SELECT name, PERCENTILE_DISC(0.5) SHOW CREATE TABLE t2; SELECT * FROM t2 ORDER BY name, pc; DROP TABLE t2, t1; + + +--echo # +--echo # MDEV-20272 PERCENTILE_DISC() crashes on a temporal type input +--echo # + +CREATE OR REPLACE TABLE t1 (name CHAR(30), star_rating TIME); +INSERT INTO t1 VALUES ('Lord of the Ladybirds', 5); +INSERT INTO t1 VALUES ('Lord of the Ladybirds', 3); +INSERT INTO t1 VALUES ('Lady of the Flies', 1); +INSERT INTO t1 VALUES ('Lady of the Flies', 2); +INSERT INTO t1 VALUES ('Lady of the Flies', 5); +--error ER_WRONG_TYPE_FOR_PERCENTILE_FUNC +SELECT name, PERCENTILE_DISC(0.5) + WITHIN GROUP (ORDER BY star_rating) + OVER (PARTITION BY name) AS pc FROM t1; +DROP TABLE t1; diff --git a/sql/item_windowfunc.cc b/sql/item_windowfunc.cc index 85e5144779e..98474f62d4f 100644 --- a/sql/item_windowfunc.cc +++ b/sql/item_windowfunc.cc @@ -172,25 +172,38 @@ void Item_window_func::split_sum_func(THD *thd, Ref_ptr_array ref_pointer_array, bool Item_window_func::check_result_type_of_order_item() { - if (only_single_element_order_list()) + switch (window_func()->sum_func()) { + case Item_sum::PERCENTILE_CONT_FUNC: { - Item *src_item= window_spec->order_list->first->item[0]; - Item_result rtype= src_item->cmp_type(); + Item_result rtype= window_spec->order_list->first->item[0]->cmp_type(); // TODO (varun) : support date type in percentile_cont function if (rtype != REAL_RESULT && rtype != INT_RESULT && rtype != DECIMAL_RESULT && rtype != TIME_RESULT) { my_error(ER_WRONG_TYPE_FOR_PERCENTILE_FUNC, MYF(0), window_func()->func_name()); - return TRUE; + return true; } - if (window_func()->sum_func() == Item_sum::PERCENTILE_DISC_FUNC) + return false; + } + case Item_sum::PERCENTILE_DISC_FUNC: + { + Item *src_item= window_spec->order_list->first->item[0]; + Item_result rtype= src_item->cmp_type(); + // TODO-10.5: Fix MDEV-20280 PERCENTILE_DISC() rejects temporal and string input + if (rtype != REAL_RESULT && rtype != INT_RESULT && rtype != DECIMAL_RESULT) { - Item_sum_percentile_disc *func= - static_cast(window_func()); - func->set_handler(src_item->type_handler()); - func->Type_std_attributes::set(src_item); - Type_std_attributes::set(src_item); + my_error(ER_WRONG_TYPE_FOR_PERCENTILE_FUNC, MYF(0), window_func()->func_name()); + return true; } + Item_sum_percentile_disc *func= + static_cast(window_func()); + func->set_handler(src_item->type_handler()); + func->Type_std_attributes::set(src_item); + Type_std_attributes::set(src_item); + return false; + } + default: + break; } return FALSE; } From e555df648c5c81f51be2e574627f6327099516ba Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Thu, 8 Aug 2019 13:47:50 +0400 Subject: [PATCH 11/14] MDEV-20285 Wrong result on INSERT..SELECT when converting from SIGNED to UNSIGNED --- mysql-test/main/type_int.result | 13 +++++++++++++ mysql-test/main/type_int.test | 11 +++++++++++ mysql-test/main/warnings.result | 1 + sql/field.h | 23 ++++++++++++++--------- 4 files changed, 39 insertions(+), 9 deletions(-) diff --git a/mysql-test/main/type_int.result b/mysql-test/main/type_int.result index 607b333aae1..17488d1ef98 100644 --- a/mysql-test/main/type_int.result +++ b/mysql-test/main/type_int.result @@ -236,5 +236,18 @@ DROP FUNCTION sint32; DROP FUNCTION uint64; DROP FUNCTION sint64; # +# MDEV-20285 Wrong result on INSERT..SELECT when converting from SIGNED to UNSIGNED +# +CREATE TABLE t1 (a TINYINT UNSIGNED); +CREATE TABLE t2 (a TINYINT); +INSERT INTO t1 VALUES (255); +INSERT IGNORE INTO t2 SELECT a FROM t1; +Warnings: +Warning 1264 Out of range value for column 'a' at row 1 +SELECT * FROM t2; +a +127 +DROP TABLE t1, t2; +# # End of 10.3 tests # diff --git a/mysql-test/main/type_int.test b/mysql-test/main/type_int.test index 87f73fabbc8..11dad45162f 100644 --- a/mysql-test/main/type_int.test +++ b/mysql-test/main/type_int.test @@ -176,6 +176,17 @@ DROP FUNCTION sint32; DROP FUNCTION uint64; DROP FUNCTION sint64; +--echo # +--echo # MDEV-20285 Wrong result on INSERT..SELECT when converting from SIGNED to UNSIGNED +--echo # + +CREATE TABLE t1 (a TINYINT UNSIGNED); +CREATE TABLE t2 (a TINYINT); +INSERT INTO t1 VALUES (255); +INSERT IGNORE INTO t2 SELECT a FROM t1; +SELECT * FROM t2; +DROP TABLE t1, t2; + --echo # --echo # End of 10.3 tests --echo # diff --git a/mysql-test/main/warnings.result b/mysql-test/main/warnings.result index db3ef5f17d2..aa4cab37741 100644 --- a/mysql-test/main/warnings.result +++ b/mysql-test/main/warnings.result @@ -115,6 +115,7 @@ insert ignore into t2 select b,c from t1; Warnings: Warning 1265 Data truncated for column 'b' at row 1 Warning 1265 Data truncated for column 'b' at row 2 +Warning 1264 Out of range value for column 'a' at row 3 Warning 1265 Data truncated for column 'b' at row 3 Warning 1048 Column 'a' cannot be null Warning 1265 Data truncated for column 'b' at row 4 diff --git a/sql/field.h b/sql/field.h index 3e5b84f9249..330523f5864 100644 --- a/sql/field.h +++ b/sql/field.h @@ -1708,13 +1708,6 @@ public: { return to->store(val_int(), MY_TEST(flags & UNSIGNED_FLAG)); } - bool memcpy_field_possible(const Field *from) const - { - return real_type() == from->real_type() && - pack_length() == from->pack_length() && - !((flags & UNSIGNED_FLAG) && !(from->flags & UNSIGNED_FLAG)) && - decimals() == from->decimals(); - } uint is_equal(Create_field *new_field); uint row_pack_length() const { return pack_length(); } uint32 pack_length_from_metadata(uint field_metadata) { @@ -1892,7 +1885,10 @@ public: e.g. a DOUBLE(53,10) into a DOUBLE(10,10). But it should be OK the other way around. */ - return Field_num::memcpy_field_possible(from) && + return real_type() == from->real_type() && + pack_length() == from->pack_length() && + is_unsigned() <= from->is_unsigned() && + decimals() == from->decimals() && field_length >= from->field_length; } int store_decimal(const my_decimal *); @@ -1983,7 +1979,10 @@ public: } bool memcpy_field_possible(const Field *from) const { - return Field_num::memcpy_field_possible(from) && + return real_type() == from->real_type() && + pack_length() == from->pack_length() && + is_unsigned() <= from->is_unsigned() && + decimals() == from->decimals() && field_length == from->field_length; } int reset(void); @@ -2041,6 +2040,12 @@ public: :Field_num(ptr_arg, len_arg, null_ptr_arg, null_bit_arg, unireg_check_arg, field_name_arg, 0, zero_arg, unsigned_arg) {} + bool memcpy_field_possible(const Field *from) const + { + return real_type() == from->real_type() && + pack_length() == from->pack_length() && + is_unsigned() == from->is_unsigned(); + } int store_decimal(const my_decimal *); my_decimal *val_decimal(my_decimal *); bool val_bool() { return val_int() != 0; } From c3d67c17c150b06f79f2d4935933ebb6ecc4f644 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Thu, 8 Aug 2019 17:08:56 +0400 Subject: [PATCH 12/14] MDEV-20292 REPEAT(x,-1) returns a wrong data type --- mysql-test/main/func_str.result | 16 ++++++++++++++++ mysql-test/main/func_str.test | 13 +++++++++++++ sql/item_strfunc.cc | 26 +++++++++++++------------- 3 files changed, 42 insertions(+), 13 deletions(-) diff --git a/mysql-test/main/func_str.result b/mysql-test/main/func_str.result index 22cf0a5cc56..eb00837eaaf 100644 --- a/mysql-test/main/func_str.result +++ b/mysql-test/main/func_str.result @@ -5068,5 +5068,21 @@ NULL DROP TABLE t1; # +# MDEV-20292 REPEAT(x,-1) returns a wrong data type +# +CREATE OR REPLACE TABLE t1 (i BIGINT); +INSERT INTO t1 VALUES (42); +CREATE OR REPLACE TABLE t2 AS SELECT +REPEAT(i,0) AS c0, +REPEAT(i,-1) AS c1 +FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `c0` char(0) CHARACTER SET utf8 DEFAULT NULL, + `c1` char(0) CHARACTER SET utf8 DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1, t2; +# # End of 10.3 tests # diff --git a/mysql-test/main/func_str.test b/mysql-test/main/func_str.test index c122516d756..135d00bcd8c 100644 --- a/mysql-test/main/func_str.test +++ b/mysql-test/main/func_str.test @@ -2028,6 +2028,19 @@ SELECT LPAD( c, 0, '?' ) FROM t1; SELECT RPAD( c, 0, '?' ) FROM t1; DROP TABLE t1; +--echo # +--echo # MDEV-20292 REPEAT(x,-1) returns a wrong data type +--echo # + +CREATE OR REPLACE TABLE t1 (i BIGINT); +INSERT INTO t1 VALUES (42); +CREATE OR REPLACE TABLE t2 AS SELECT + REPEAT(i,0) AS c0, + REPEAT(i,-1) AS c1 +FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t1, t2; + --echo # --echo # End of 10.3 tests diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 3d2b3ef4814..65acc071237 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -2967,20 +2967,20 @@ bool Item_func_repeat::fix_length_and_dec() if (agg_arg_charsets_for_string_result(collation, args, 1)) return TRUE; DBUG_ASSERT(collation.collation != NULL); - if (args[1]->const_item()) + if (args[1]->const_item() && !args[1]->is_expensive()) { - /* must be longlong to avoid truncation */ - longlong count= args[1]->val_int(); - - /* Assumes that the maximum length of a String is < INT_MAX32. */ - /* Set here so that rest of code sees out-of-bound value as such. */ - if (args[1]->null_value) - count= 0; - else if (count > INT_MAX32) - count= INT_MAX32; - - ulonglong char_length= (ulonglong) args[0]->max_char_length() * count; - fix_char_length_ulonglong(char_length); + Longlong_hybrid nr= args[1]->to_longlong_hybrid(); + if (args[1]->null_value || nr.neg()) + fix_char_length(0); + else + { + /* Assumes that the maximum length of a String is < INT_MAX32. */ + longlong count= nr.value(); + if (count > INT_MAX32) + count= INT_MAX32; + ulonglong char_length= (ulonglong) args[0]->max_char_length() * count; + fix_char_length_ulonglong(char_length); + } } else { From 2dac1235150681433bdf6480e479e2f787b40f8b Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Fri, 9 Aug 2019 09:00:17 +0400 Subject: [PATCH 13/14] A cleanup for `MDEV-20273 Add class Item_sum_min_max` - removing duplicate code Reusing the MIN()/MAX() fix_length_and_dec() related code for window functions - FIRST_VALUE() - LAST_VALUE() - NTH_VALUE() - LEAD() - LAG --- sql/item_sum.cc | 64 ++++++++++++++++++++++++++++++++- sql/item_sum.h | 3 ++ sql/item_windowfunc.cc | 42 +++++++--------------- sql/item_windowfunc.h | 1 + sql/sql_type.cc | 80 ++++++------------------------------------ sql/sql_type.h | 20 +++++------ 6 files changed, 99 insertions(+), 111 deletions(-) diff --git a/sql/item_sum.cc b/sql/item_sum.cc index 081db08e943..08ee190e96c 100644 --- a/sql/item_sum.cc +++ b/sql/item_sum.cc @@ -1184,11 +1184,73 @@ Item_sum_min_max::fix_fields(THD *thd, Item **ref) } +bool Item_sum_hybrid::fix_length_and_dec_generic() +{ + Item *item= arguments()[0]; + Type_std_attributes::set(item); + set_handler(item->type_handler()); + return false; +} + + +/** + MAX/MIN for the traditional numeric types preserve the exact data type + from Fields, but do not preserve the exact type from Items: + MAX(float_field) -> FLOAT + MAX(smallint_field) -> LONGLONG + MAX(COALESCE(float_field)) -> DOUBLE + MAX(COALESCE(smallint_field)) -> LONGLONG + QQ: Items should probably be fixed to preserve the exact type. +*/ +bool Item_sum_hybrid::fix_length_and_dec_numeric(const Type_handler *handler) +{ + Item *item= arguments()[0]; + Item *item2= item->real_item(); + Type_std_attributes::set(item); + if (item2->type() == Item::FIELD_ITEM) + set_handler(item2->type_handler()); + else + set_handler(handler); + return false; +} + + +/** + MAX(str_field) converts ENUM/SET to CHAR, and preserve all other types + for Fields. + QQ: This works differently from UNION, which preserve the exact data + type for ENUM/SET if the joined ENUM/SET fields are equally defined. + Perhaps should be fixed. + MAX(str_item) chooses the best suitable string type. +*/ +bool Item_sum_hybrid::fix_length_and_dec_string() +{ + Item *item= arguments()[0]; + Item *item2= item->real_item(); + Type_std_attributes::set(item); + if (item2->type() == Item::FIELD_ITEM) + { + // Fields: convert ENUM/SET to CHAR, preserve the type otherwise. + set_handler(item->type_handler()); + } + else + { + // Items: choose VARCHAR/BLOB/MEDIUMBLOB/LONGBLOB, depending on length. + set_handler(type_handler_varchar. + type_handler_adjusted_to_max_octet_length(max_length, + collation.collation)); + } + return false; +} + + bool Item_sum_min_max::fix_length_and_dec() { DBUG_ASSERT(args[0]->field_type() == args[0]->real_item()->field_type()); DBUG_ASSERT(args[0]->result_type() == args[0]->real_item()->result_type()); - return args[0]->type_handler()->Item_sum_min_max_fix_length_and_dec(this); + /* MIN/MAX can return NULL for empty set indepedent of the used column */ + maybe_null= null_value= true; + return args[0]->type_handler()->Item_sum_hybrid_fix_length_and_dec(this); } diff --git a/sql/item_sum.h b/sql/item_sum.h index df37d0dbfa4..a3e10c25763 100644 --- a/sql/item_sum.h +++ b/sql/item_sum.h @@ -1044,6 +1044,9 @@ public: { } const Type_handler *type_handler() const { return Type_handler_hybrid_field_type::type_handler(); } + bool fix_length_and_dec_generic(); + bool fix_length_and_dec_numeric(const Type_handler *h); + bool fix_length_and_dec_string(); }; diff --git a/sql/item_windowfunc.cc b/sql/item_windowfunc.cc index 98474f62d4f..17c5740feda 100644 --- a/sql/item_windowfunc.cc +++ b/sql/item_windowfunc.cc @@ -353,39 +353,15 @@ bool Item_sum_hybrid_simple::fix_fields(THD *thd, Item **ref) if (args[i]->fix_fields_if_needed_for_scalar(thd, &args[i])) return TRUE; } - Type_std_attributes::set(args[0]); + for (uint i= 0; i < arg_count && !m_with_subquery; i++) m_with_subquery|= args[i]->with_subquery(); - Item *item2= args[0]->real_item(); - if (item2->type() == Item::FIELD_ITEM) - set_handler(item2->type_handler()); - else if (args[0]->cmp_type() == TIME_RESULT) - set_handler(item2->type_handler()); - else - set_handler_by_result_type(item2->result_type(), - max_length, collation.collation); - - switch (result_type()) { - case INT_RESULT: - case DECIMAL_RESULT: - case STRING_RESULT: - break; - case REAL_RESULT: - max_length= float_length(decimals); - break; - case ROW_RESULT: - case TIME_RESULT: - DBUG_ASSERT(0); // XXX(cvicentiu) Should this never happen? - return TRUE; - }; - setup_hybrid(thd, args[0]); - /* MIN/MAX can return NULL for empty set indepedent of the used column */ - maybe_null= 1; - result_field=0; - null_value=1; if (fix_length_and_dec()) - return TRUE; + return true; + + setup_hybrid(thd, args[0]); + result_field=0; if (check_sum_func(thd, ref)) return TRUE; @@ -397,6 +373,14 @@ bool Item_sum_hybrid_simple::fix_fields(THD *thd, Item **ref) return FALSE; } + +bool Item_sum_hybrid_simple::fix_length_and_dec() +{ + maybe_null= null_value= true; + return args[0]->type_handler()->Item_sum_hybrid_fix_length_and_dec(this); +} + + bool Item_sum_hybrid_simple::add() { value->store(args[0]); diff --git a/sql/item_windowfunc.h b/sql/item_windowfunc.h index 1432643dfc8..e6389c01832 100644 --- a/sql/item_windowfunc.h +++ b/sql/item_windowfunc.h @@ -307,6 +307,7 @@ class Item_sum_hybrid_simple : public Item_sum_hybrid bool add(); bool fix_fields(THD *, Item **); + bool fix_length_and_dec(); void setup_hybrid(THD *thd, Item *item); double val_real(); longlong val_int(); diff --git a/sql/sql_type.cc b/sql/sql_type.cc index 573d9721fc1..114e4cac367 100644 --- a/sql/sql_type.cc +++ b/sql/sql_type.cc @@ -365,7 +365,7 @@ Type_handler::blob_type_handler(const Item *item) /** This method is used by: - - Item_sum_min_max, e.g. MAX(item), MIN(item). + - Item_sum_hybrid, e.g. MAX(item), MIN(item). - Item_func_set_user_var */ const Type_handler * @@ -3076,87 +3076,33 @@ bool Type_handler_real_result:: /*************************************************************************/ -/** - MAX/MIN for the traditional numeric types preserve the exact data type - from Fields, but do not preserve the exact type from Items: - MAX(float_field) -> FLOAT - MAX(smallint_field) -> LONGLONG - MAX(COALESCE(float_field)) -> DOUBLE - MAX(COALESCE(smallint_field)) -> LONGLONG - QQ: Items should probably be fixed to preserve the exact type. -*/ -bool Type_handler_numeric:: - Item_sum_min_max_fix_length_and_dec_numeric(Item_sum_min_max *func, - const Type_handler *handler) - const -{ - Item *item= func->arguments()[0]; - Item *item2= item->real_item(); - func->Type_std_attributes::set(item); - /* MIN/MAX can return NULL for empty set indepedent of the used column */ - func->maybe_null= func->null_value= true; - if (item2->type() == Item::FIELD_ITEM) - func->set_handler(item2->type_handler()); - else - func->set_handler(handler); - return false; -} - - bool Type_handler_int_result:: - Item_sum_min_max_fix_length_and_dec(Item_sum_min_max *func) const + Item_sum_hybrid_fix_length_and_dec(Item_sum_hybrid *func) const { - return Item_sum_min_max_fix_length_and_dec_numeric(func, - &type_handler_longlong); + return func->fix_length_and_dec_numeric(&type_handler_longlong); } bool Type_handler_real_result:: - Item_sum_min_max_fix_length_and_dec(Item_sum_min_max *func) const + Item_sum_hybrid_fix_length_and_dec(Item_sum_hybrid *func) const { - (void) Item_sum_min_max_fix_length_and_dec_numeric(func, - &type_handler_double); + (void) func->fix_length_and_dec_numeric(&type_handler_double); func->max_length= func->float_length(func->decimals); return false; } bool Type_handler_decimal_result:: - Item_sum_min_max_fix_length_and_dec(Item_sum_min_max *func) const + Item_sum_hybrid_fix_length_and_dec(Item_sum_hybrid *func) const { - return Item_sum_min_max_fix_length_and_dec_numeric(func, - &type_handler_newdecimal); + return func->fix_length_and_dec_numeric(&type_handler_newdecimal); } -/** - MAX(str_field) converts ENUM/SET to CHAR, and preserve all other types - for Fields. - QQ: This works differently from UNION, which preserve the exact data - type for ENUM/SET if the joined ENUM/SET fields are equally defined. - Perhaps should be fixed. - MAX(str_item) chooses the best suitable string type. -*/ bool Type_handler_string_result:: - Item_sum_min_max_fix_length_and_dec(Item_sum_min_max *func) const + Item_sum_hybrid_fix_length_and_dec(Item_sum_hybrid *func) const { - Item *item= func->arguments()[0]; - Item *item2= item->real_item(); - func->Type_std_attributes::set(item); - func->maybe_null= func->null_value= true; - if (item2->type() == Item::FIELD_ITEM) - { - // Fields: convert ENUM/SET to CHAR, preserve the type otherwise. - func->set_handler(item->type_handler()); - } - else - { - // Items: choose VARCHAR/BLOB/MEDIUMBLOB/LONGBLOB, depending on length. - func->set_handler(type_handler_varchar. - type_handler_adjusted_to_max_octet_length(func->max_length, - func->collation.collation)); - } - return false; + return func->fix_length_and_dec_string(); } @@ -3164,13 +3110,9 @@ bool Type_handler_string_result:: Traditional temporal types always preserve the type of the argument. */ bool Type_handler_temporal_result:: - Item_sum_min_max_fix_length_and_dec(Item_sum_min_max *func) const + Item_sum_hybrid_fix_length_and_dec(Item_sum_hybrid *func) const { - Item *item= func->arguments()[0]; - func->Type_std_attributes::set(item); - func->maybe_null= func->null_value= true; - func->set_handler(item->type_handler()); - return false; + return func->fix_length_and_dec_generic(); } diff --git a/sql/sql_type.h b/sql/sql_type.h index a7915ddc463..df4b99569c1 100644 --- a/sql/sql_type.h +++ b/sql/sql_type.h @@ -33,7 +33,7 @@ class Item; class Item_param; class Item_cache; class Item_func_or_sum; -class Item_sum_min_max; +class Item_sum_hybrid; class Item_sum_sum; class Item_sum_avg; class Item_sum_variance; @@ -1314,7 +1314,7 @@ public: Item_func_min_max *func, Item **items, uint nitems) const; - virtual bool Item_sum_min_max_fix_length_and_dec(Item_sum_min_max *) const= 0; + virtual bool Item_sum_hybrid_fix_length_and_dec(Item_sum_hybrid *) const= 0; virtual bool Item_sum_sum_fix_length_and_dec(Item_sum_sum *) const= 0; virtual bool Item_sum_avg_fix_length_and_dec(Item_sum_avg *) const= 0; virtual @@ -1563,7 +1563,7 @@ public: DBUG_ASSERT(0); return true; } - bool Item_sum_min_max_fix_length_and_dec(Item_sum_min_max *func) const + bool Item_sum_hybrid_fix_length_and_dec(Item_sum_hybrid *func) const { DBUG_ASSERT(0); return true; @@ -1742,10 +1742,6 @@ public: */ class Type_handler_numeric: public Type_handler { -protected: - bool Item_sum_min_max_fix_length_and_dec_numeric(Item_sum_min_max *func, - const Type_handler *handler) - const; public: String *print_item_value(THD *thd, Item *item, String *str) const; double Item_func_min_max_val_real(Item_func_min_max *) const; @@ -1796,7 +1792,7 @@ public: Item **items, uint nitems) const; bool Item_func_min_max_fix_attributes(THD *thd, Item_func_min_max *func, Item **items, uint nitems) const; - bool Item_sum_min_max_fix_length_and_dec(Item_sum_min_max *func) const; + bool Item_sum_hybrid_fix_length_and_dec(Item_sum_hybrid *func) const; bool Item_sum_sum_fix_length_and_dec(Item_sum_sum *) const; bool Item_sum_avg_fix_length_and_dec(Item_sum_avg *) const; bool Item_sum_variance_fix_length_and_dec(Item_sum_variance *) const; @@ -1874,7 +1870,7 @@ public: Type_handler_hybrid_field_type *, Type_all_attributes *atrr, Item **items, uint nitems) const; - bool Item_sum_min_max_fix_length_and_dec(Item_sum_min_max *func) const; + bool Item_sum_hybrid_fix_length_and_dec(Item_sum_hybrid *func) const; bool Item_sum_sum_fix_length_and_dec(Item_sum_sum *) const; bool Item_sum_avg_fix_length_and_dec(Item_sum_avg *) const; bool Item_sum_variance_fix_length_and_dec(Item_sum_variance *) const; @@ -2068,7 +2064,7 @@ public: Type_handler_hybrid_field_type *, Type_all_attributes *atrr, Item **items, uint nitems) const; - bool Item_sum_min_max_fix_length_and_dec(Item_sum_min_max *func) const; + bool Item_sum_hybrid_fix_length_and_dec(Item_sum_hybrid *func) const; bool Item_sum_sum_fix_length_and_dec(Item_sum_sum *) const; bool Item_sum_avg_fix_length_and_dec(Item_sum_avg *) const; bool Item_sum_variance_fix_length_and_dec(Item_sum_variance *) const; @@ -2145,7 +2141,7 @@ public: const Item *outer) const; bool Item_func_min_max_fix_attributes(THD *thd, Item_func_min_max *func, Item **items, uint nitems) const; - bool Item_sum_min_max_fix_length_and_dec(Item_sum_min_max *func) const; + bool Item_sum_hybrid_fix_length_and_dec(Item_sum_hybrid *func) const; bool Item_sum_sum_fix_length_and_dec(Item_sum_sum *) const; bool Item_sum_avg_fix_length_and_dec(Item_sum_avg *) const; bool Item_sum_variance_fix_length_and_dec(Item_sum_variance *) const; @@ -2258,7 +2254,7 @@ public: Type_handler_hybrid_field_type *, Type_all_attributes *atrr, Item **items, uint nitems) const; - bool Item_sum_min_max_fix_length_and_dec(Item_sum_min_max *func) const; + bool Item_sum_hybrid_fix_length_and_dec(Item_sum_hybrid *func) const; bool Item_sum_sum_fix_length_and_dec(Item_sum_sum *) const; bool Item_sum_avg_fix_length_and_dec(Item_sum_avg *) const; bool Item_sum_variance_fix_length_and_dec(Item_sum_variance *) const; From 43882e764d6867c6855b1ff057758a3f08b25c55 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Fri, 9 Aug 2019 14:18:13 +0400 Subject: [PATCH 14/14] MDEV-20303 SPACE(-1) returns a wrong data type --- mysql-test/main/func_str.result | 68 ++++++++++++++++++++++ mysql-test/main/func_str.test | 47 +++++++++++++++ sql/item_strfunc.cc | 100 ++++++++++++++------------------ 3 files changed, 158 insertions(+), 57 deletions(-) diff --git a/mysql-test/main/func_str.result b/mysql-test/main/func_str.result index eb00837eaaf..2d86d384288 100644 --- a/mysql-test/main/func_str.result +++ b/mysql-test/main/func_str.result @@ -5073,16 +5073,84 @@ DROP TABLE t1; CREATE OR REPLACE TABLE t1 (i BIGINT); INSERT INTO t1 VALUES (42); CREATE OR REPLACE TABLE t2 AS SELECT +REPEAT(i,NULL) AS cn, REPEAT(i,0) AS c0, REPEAT(i,-1) AS c1 FROM t1; SHOW CREATE TABLE t2; Table Create Table t2 CREATE TABLE `t2` ( + `cn` char(0) CHARACTER SET utf8 DEFAULT NULL, `c0` char(0) CHARACTER SET utf8 DEFAULT NULL, `c1` char(0) CHARACTER SET utf8 DEFAULT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 DROP TABLE t1, t2; # +# MDEV-20303 SPACE(-1) returns a wrong data type +# +CREATE TABLE t1 (i BIGINT); +INSERT INTO t1 VALUES (42); +CREATE TABLE t2 AS SELECT +SPACE(NULL) AS cn, +SPACE(0) AS c0, +SPACE(-1) AS c1 +FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `cn` char(0) CHARACTER SET utf8 DEFAULT NULL, + `c0` char(0) CHARACTER SET utf8 DEFAULT NULL, + `c1` char(0) CHARACTER SET utf8 DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1, t2; +CREATE TABLE t1 (i BIGINT); +INSERT INTO t1 VALUES (42); +CREATE TABLE t2 AS SELECT +LPAD(i,NULL,'a') AS cn, +LPAD(i,0,'a') AS c0, +LPAD(i,-1,'a') AS c1 +FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `cn` char(0) CHARACTER SET utf8 DEFAULT NULL, + `c0` char(0) CHARACTER SET utf8 DEFAULT NULL, + `c1` char(0) CHARACTER SET utf8 DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1, t2; +CREATE TABLE t1 (i BIGINT); +INSERT INTO t1 VALUES (42); +CREATE TABLE t2 AS SELECT +RPAD(i,NULL,'a') AS cn, +RPAD(i,0,'a') AS c0, +RPAD(i,-1,'a') AS c1 +FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `cn` char(0) CHARACTER SET utf8 DEFAULT NULL, + `c0` char(0) CHARACTER SET utf8 DEFAULT NULL, + `c1` char(0) CHARACTER SET utf8 DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +DROP TABLE t1, t2; +CREATE TABLE t1 (i BIGINT); +INSERT INTO t1 VALUES (42); +CREATE TABLE t2 AS SELECT +LEFT(i,NULL) AS cn, +LEFT(i,0) AS c0, +LEFT(i,18446744073709551615) AS c1 +FROM t1; +SHOW CREATE TABLE t2; +Table Create Table +t2 CREATE TABLE `t2` ( + `cn` char(0) CHARACTER SET utf8 DEFAULT NULL, + `c0` char(0) CHARACTER SET utf8 DEFAULT NULL, + `c1` varchar(20) CHARACTER SET utf8 DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +SELECT c1 FROM t2; +c1 +42 +DROP TABLE t1, t2; +# # End of 10.3 tests # diff --git a/mysql-test/main/func_str.test b/mysql-test/main/func_str.test index 135d00bcd8c..60a142cda20 100644 --- a/mysql-test/main/func_str.test +++ b/mysql-test/main/func_str.test @@ -2035,6 +2035,7 @@ DROP TABLE t1; CREATE OR REPLACE TABLE t1 (i BIGINT); INSERT INTO t1 VALUES (42); CREATE OR REPLACE TABLE t2 AS SELECT + REPEAT(i,NULL) AS cn, REPEAT(i,0) AS c0, REPEAT(i,-1) AS c1 FROM t1; @@ -2042,6 +2043,52 @@ SHOW CREATE TABLE t2; DROP TABLE t1, t2; +--echo # +--echo # MDEV-20303 SPACE(-1) returns a wrong data type +--echo # + +CREATE TABLE t1 (i BIGINT); +INSERT INTO t1 VALUES (42); +CREATE TABLE t2 AS SELECT + SPACE(NULL) AS cn, + SPACE(0) AS c0, + SPACE(-1) AS c1 +FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t1, t2; + +CREATE TABLE t1 (i BIGINT); +INSERT INTO t1 VALUES (42); +CREATE TABLE t2 AS SELECT + LPAD(i,NULL,'a') AS cn, + LPAD(i,0,'a') AS c0, + LPAD(i,-1,'a') AS c1 +FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t1, t2; + +CREATE TABLE t1 (i BIGINT); +INSERT INTO t1 VALUES (42); +CREATE TABLE t2 AS SELECT + RPAD(i,NULL,'a') AS cn, + RPAD(i,0,'a') AS c0, + RPAD(i,-1,'a') AS c1 +FROM t1; +SHOW CREATE TABLE t2; +DROP TABLE t1, t2; + +CREATE TABLE t1 (i BIGINT); +INSERT INTO t1 VALUES (42); +CREATE TABLE t2 AS SELECT + LEFT(i,NULL) AS cn, + LEFT(i,0) AS c0, + LEFT(i,18446744073709551615) AS c1 +FROM t1; +SHOW CREATE TABLE t2; +SELECT c1 FROM t2; +DROP TABLE t1, t2; + + --echo # --echo # End of 10.3 tests --echo # diff --git a/sql/item_strfunc.cc b/sql/item_strfunc.cc index 65acc071237..b170634d864 100644 --- a/sql/item_strfunc.cc +++ b/sql/item_strfunc.cc @@ -58,6 +58,27 @@ C_MODE_END size_t username_char_length= 80; + +class Repeat_count +{ + ulonglong m_count; +public: + Repeat_count(Item *item) + :m_count(0) + { + Longlong_hybrid nr= item->to_longlong_hybrid(); + if (!item->null_value && !nr.neg()) + { + // Assume that the maximum length of a String is < INT_MAX32 + m_count= (ulonglong) nr.value(); + if (m_count > (ulonglong) INT_MAX32) + m_count= (ulonglong) INT_MAX32; + } + } + ulonglong count() const { return m_count; } +}; + + /* For the Items which have only val_str_ascii() method and don't have their own "native" val_str(), @@ -1635,13 +1656,10 @@ String *Item_func_left::val_str(String *str) void Item_str_func::left_right_max_length() { uint32 char_length= args[0]->max_char_length(); - if (args[1]->const_item()) + if (args[1]->const_item() && !args[1]->is_expensive()) { - int length= (int) args[1]->val_int(); - if (args[1]->null_value || length <= 0) - char_length=0; - else - set_if_smaller(char_length, (uint) length); + Repeat_count tmp(args[1]); + set_if_smaller(char_length, (uint) tmp.count()); } fix_char_length(char_length); } @@ -2969,25 +2987,14 @@ bool Item_func_repeat::fix_length_and_dec() DBUG_ASSERT(collation.collation != NULL); if (args[1]->const_item() && !args[1]->is_expensive()) { - Longlong_hybrid nr= args[1]->to_longlong_hybrid(); - if (args[1]->null_value || nr.neg()) - fix_char_length(0); - else - { - /* Assumes that the maximum length of a String is < INT_MAX32. */ - longlong count= nr.value(); - if (count > INT_MAX32) - count= INT_MAX32; - ulonglong char_length= (ulonglong) args[0]->max_char_length() * count; - fix_char_length_ulonglong(char_length); - } + Repeat_count tmp(args[1]); + ulonglong char_length= (ulonglong) args[0]->max_char_length() * tmp.count(); + fix_char_length_ulonglong(char_length); + return false; } - else - { - max_length= MAX_BLOB_WIDTH; - maybe_null= 1; - } - return FALSE; + max_length= MAX_BLOB_WIDTH; + maybe_null= true; + return false; } /** @@ -3052,26 +3059,14 @@ err: bool Item_func_space::fix_length_and_dec() { collation.set(default_charset(), DERIVATION_COERCIBLE, MY_REPERTOIRE_ASCII); - if (args[0]->const_item()) + if (args[0]->const_item() && !args[0]->is_expensive()) { - /* must be longlong to avoid truncation */ - longlong count= args[0]->val_int(); - if (args[0]->null_value) - goto end; - /* - Assumes that the maximum length of a String is < INT_MAX32. - Set here so that rest of code sees out-of-bound value as such. - */ - if (count > INT_MAX32) - count= INT_MAX32; - fix_char_length_ulonglong(count); - return FALSE; + fix_char_length_ulonglong(Repeat_count(args[0]).count()); + return false; } - -end: max_length= MAX_BLOB_WIDTH; - maybe_null= 1; - return FALSE; + maybe_null= true; + return false; } @@ -3182,24 +3177,15 @@ bool Item_func_pad::fix_length_and_dec() pad_str.append(" ", 1); } - if (args[1]->const_item()) + DBUG_ASSERT(collation.collation->mbmaxlen > 0); + if (args[1]->const_item() && !args[1]->is_expensive()) { - ulonglong char_length= (ulonglong) args[1]->val_int(); - DBUG_ASSERT(collation.collation->mbmaxlen > 0); - /* Assumes that the maximum length of a String is < INT_MAX32. */ - /* Set here so that rest of code sees out-of-bound value as such. */ - if (args[1]->null_value) - char_length= 0; - else if (char_length > INT_MAX32) - char_length= INT_MAX32; - fix_char_length_ulonglong(char_length); + fix_char_length(Repeat_count(args[1]).count()); + return false; } - else - { - max_length= MAX_BLOB_WIDTH; - maybe_null= 1; - } - return FALSE; + max_length= MAX_BLOB_WIDTH; + maybe_null= true; + return false; }