From c88ca2c22739dc2327c7b1082df79a93370662ba Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Fri, 6 Nov 2015 17:56:56 +0100 Subject: [PATCH 1/6] MDEV-8701 Crash on derived query MDEV-8938 Server Crash on Update with joins Make unique table check after setup_fields of update because unique table can materialize table and we do not need field resolving after materialization. --- mysql-test/r/update.result | 59 ++++++++++++++++++++++++++++++ mysql-test/t/update.test | 73 ++++++++++++++++++++++++++++++++++++++ sql/sql_prepare.cc | 3 +- sql/sql_update.cc | 32 ++++++++++++----- sql/sql_update.h | 1 + 5 files changed, 158 insertions(+), 10 deletions(-) diff --git a/mysql-test/r/update.result b/mysql-test/r/update.result index 3ea58553653..0b036ca0a2e 100644 --- a/mysql-test/r/update.result +++ b/mysql-test/r/update.result @@ -618,3 +618,62 @@ Variable_name Value Handler_update 5 ROLLBACK; DROP TABLE t1, t2; +# +# MDEV-8938: Server Crash on Update with joins +# +CREATE TABLE `t1` ( +`name` varchar(255) NOT NULL, +`value` varchar(4095) DEFAULT NULL, +PRIMARY KEY (`name`) +); +UPDATE `t1` SET value = CONCAT("*.",(SELECT `temptable`.`value` FROM (SELECT * FROM `t1` WHERE `name`="consoleproxy.url.domain") AS `temptable` WHERE `temptable`.`name`="consoleproxy.url.domain")) WHERE `name`="consoleproxy.url.domain"; +drop table t1; +CREATE TABLE `t1` ( +`name` varchar(255) NOT NULL, +`value` varchar(4095) DEFAULT NULL, +PRIMARY KEY (`name`) +); +create table t2 ( +`name` varchar(255) NOT NULL, +`value` varchar(4095) DEFAULT NULL, +PRIMARY KEY (`name`) +); +UPDATE t1 +SET value = (SELECT value FROM t2 WHERE `name`= t1.name) +WHERE value is null ; +drop table t1,t2; +# +#MDEV-8701: Crash on derived query +# +CREATE TABLE t1 ( +data_exit_entry_id int(11) NOT NULL, +data_entry_id int(11) NOT NULL, +data_entry_exit_id int(11) NOT NULL, +data_exit_entry_quantity double NOT NULL +) DEFAULT CHARSET=utf8; +CREATE TABLE t2 ( +data_entry_id int(11) NOT NULL, +data_entry_cost double NOT NULL, +data_entry_quantity double NOT NULL +) DEFAULT CHARSET=utf8; +create algorithm=temptable view v1 as SELECT data_entry_exit_id, data_exit_entry_quantity, data_entry_cost +FROM t1 INNER JOIN t2 as dt ON dt.data_entry_id = t1.data_entry_id; +UPDATE t2 +SET data_entry_cost += ( ( SELECT SUM(data_exit_entry_quantity * data_entry_cost) +FROM +v1 AS query +WHERE data_entry_exit_id = t2.data_entry_id +) +); +UPDATE t2 +SET data_entry_cost += ( ( SELECT SUM(data_exit_entry_quantity * data_entry_cost) +FROM +( SELECT data_entry_exit_id, data_exit_entry_quantity, data_entry_cost +FROM t1 INNER JOIN t2 as dt ON dt.data_entry_id = t1.data_entry_id) AS query +WHERE data_entry_exit_id = t2.data_entry_id +) +); +drop view v1; +drop table t1, t2; diff --git a/mysql-test/t/update.test b/mysql-test/t/update.test index be97dd02dc7..e9d7ff243dd 100644 --- a/mysql-test/t/update.test +++ b/mysql-test/t/update.test @@ -559,3 +559,76 @@ SHOW STATUS LIKE 'HANDLER_UPDATE'; ROLLBACK; DROP TABLE t1, t2; +--echo # +--echo # MDEV-8938: Server Crash on Update with joins +--echo # + +CREATE TABLE `t1` ( + `name` varchar(255) NOT NULL, + `value` varchar(4095) DEFAULT NULL, + PRIMARY KEY (`name`) +); + +UPDATE `t1` SET value = CONCAT("*.",(SELECT `temptable`.`value` FROM (SELECT * FROM `t1` WHERE `name`="consoleproxy.url.domain") AS `temptable` WHERE `temptable`.`name`="consoleproxy.url.domain")) WHERE `name`="consoleproxy.url.domain"; + +drop table t1; + +CREATE TABLE `t1` ( + `name` varchar(255) NOT NULL, + `value` varchar(4095) DEFAULT NULL, + PRIMARY KEY (`name`) +); + +create table t2 ( + `name` varchar(255) NOT NULL, + `value` varchar(4095) DEFAULT NULL, + PRIMARY KEY (`name`) +); + +UPDATE t1 +SET value = (SELECT value FROM t2 WHERE `name`= t1.name) +WHERE value is null ; + +drop table t1,t2; + +--echo # +--echo #MDEV-8701: Crash on derived query +--echo # + +CREATE TABLE t1 ( + data_exit_entry_id int(11) NOT NULL, + data_entry_id int(11) NOT NULL, + data_entry_exit_id int(11) NOT NULL, + data_exit_entry_quantity double NOT NULL +) DEFAULT CHARSET=utf8; + +CREATE TABLE t2 ( + data_entry_id int(11) NOT NULL, + data_entry_cost double NOT NULL, + data_entry_quantity double NOT NULL +) DEFAULT CHARSET=utf8; + +create algorithm=temptable view v1 as SELECT data_entry_exit_id, data_exit_entry_quantity, data_entry_cost + FROM t1 INNER JOIN t2 as dt ON dt.data_entry_id = t1.data_entry_id; + +UPDATE t2 +SET data_entry_cost + = ( ( SELECT SUM(data_exit_entry_quantity * data_entry_cost) + FROM + v1 AS query + WHERE data_entry_exit_id = t2.data_entry_id + ) + ); + +UPDATE t2 +SET data_entry_cost + = ( ( SELECT SUM(data_exit_entry_quantity * data_entry_cost) + FROM + ( SELECT data_entry_exit_id, data_exit_entry_quantity, data_entry_cost + FROM t1 INNER JOIN t2 as dt ON dt.data_entry_id = t1.data_entry_id) AS query + WHERE data_entry_exit_id = t2.data_entry_id + ) + ); + +drop view v1; +drop table t1, t2; diff --git a/sql/sql_prepare.cc b/sql/sql_prepare.cc index 4fcc007d104..c61c9101a36 100644 --- a/sql/sql_prepare.cc +++ b/sql/sql_prepare.cc @@ -1408,7 +1408,8 @@ static int mysql_test_update(Prepared_statement *stmt, (SELECT_ACL & ~table_list->table->grant.privilege); table_list->register_want_access(SELECT_ACL); #endif - if (setup_fields(thd, 0, stmt->lex->value_list, MARK_COLUMNS_NONE, 0, 0)) + if (setup_fields(thd, 0, stmt->lex->value_list, MARK_COLUMNS_NONE, 0, 0) || + check_unique_table(thd, table_list)) goto error; /* TODO: here we should send types of placeholders to the client. */ DBUG_RETURN(0); diff --git a/sql/sql_update.cc b/sql/sql_update.cc index 23e17b0a3bb..c8a7990c23e 100644 --- a/sql/sql_update.cc +++ b/sql/sql_update.cc @@ -367,6 +367,9 @@ int mysql_update(THD *thd, DBUG_RETURN(1); /* purecov: inspected */ } + if (check_unique_table(thd, table_list)) + DBUG_RETURN(TRUE); + /* Apply the IN=>EXISTS transformation to all subqueries and optimize them. */ if (select_lex->optimize_unflattened_subqueries(false)) DBUG_RETURN(TRUE); @@ -1036,19 +1039,30 @@ bool mysql_prepare_update(THD *thd, TABLE_LIST *table_list, setup_ftfuncs(select_lex)) DBUG_RETURN(TRUE); - /* Check that we are not using table that we are updating in a sub select */ - { - TABLE_LIST *duplicate; - if ((duplicate= unique_table(thd, table_list, table_list->next_global, 0))) - { - update_non_unique_table_error(table_list, "UPDATE", duplicate); - DBUG_RETURN(TRUE); - } - } select_lex->fix_prepare_information(thd, conds, &fake_conds); DBUG_RETURN(FALSE); } +/** + Check that we are not using table that we are updating in a sub select + + @param thd Thread handle + @param table_list List of table with first to check + + @retval TRUE Error + @retval FALSE OK +*/ +bool check_unique_table(THD *thd, TABLE_LIST *table_list) +{ + TABLE_LIST *duplicate; + DBUG_ENTER("check_unique_table"); + if ((duplicate= unique_table(thd, table_list, table_list->next_global, 0))) + { + update_non_unique_table_error(table_list, "UPDATE", duplicate); + DBUG_RETURN(TRUE); + } + DBUG_RETURN(FALSE); +} /*************************************************************************** Update multiple tables from join diff --git a/sql/sql_update.h b/sql/sql_update.h index 64029c5d634..4c6f89d8468 100644 --- a/sql/sql_update.h +++ b/sql/sql_update.h @@ -27,6 +27,7 @@ typedef class st_select_lex_unit SELECT_LEX_UNIT; bool mysql_prepare_update(THD *thd, TABLE_LIST *table_list, Item **conds, uint order_num, ORDER *order); +bool check_unique_table(THD *thd, TABLE_LIST *table_list); int mysql_update(THD *thd,TABLE_LIST *tables,List &fields, List &values,COND *conds, uint order_num, ORDER *order, ha_rows limit, From 5d754fce95fa378027d1b575d049ab6b78823bb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20Lindstr=C3=B6m?= Date: Mon, 9 Nov 2015 09:23:32 +0200 Subject: [PATCH 2/6] MDEV-8854: New warning messages are unreadable Improved warning messages by quote marks. --- .../suite/innodb/r/innodb-fk-warnings.result | 24 ++-- mysql-test/suite/innodb/r/innodb-fk.result | 6 +- storage/innobase/dict/dict0dict.c | 122 +++++++++--------- storage/xtradb/dict/dict0dict.c | 122 +++++++++--------- 4 files changed, 136 insertions(+), 138 deletions(-) diff --git a/mysql-test/suite/innodb/r/innodb-fk-warnings.result b/mysql-test/suite/innodb/r/innodb-fk-warnings.result index 542fc972880..b3360d038df 100644 --- a/mysql-test/suite/innodb/r/innodb-fk-warnings.result +++ b/mysql-test/suite/innodb/r/innodb-fk-warnings.result @@ -24,7 +24,7 @@ create table t2(a int, constraint a foreign key a (a) references t1(a)) engine=i ERROR HY000: Can't create table 'test.t2' (errno: 150) show warnings; Level Code Message -Warning 150 Create table '`test`.`t2`' with foreign key constraint failed. There is no index in the referenced table where the referenced columns appear as the first columns. Error close to foreign key a (a) references t1(a)) engine=innodb. +Warning 150 Create table '`test`.`t2`' with foreign key constraint failed. There is no index in the referenced table where the referenced columns appear as the first columns near ' foreign key a (a) references t1(a)) engine=innodb'. Error 1005 Can't create table 'test.t2' (errno: 150) drop table t1; create table t1(a int not null primary key, b int) engine=innodb; @@ -33,14 +33,14 @@ constraint a foreign key a (a) references t1(b)) engine=innodb; ERROR HY000: Can't create table 'test.t2' (errno: 150) show warnings; Level Code Message -Warning 150 Create table '`test`.`t2`' with foreign key constraint failed. There is no index in the referenced table where the referenced columns appear as the first columns. Error close to foreign key a (a) references t1(b)) engine=innodb. +Warning 150 Create table '`test`.`t2`' with foreign key constraint failed. There is no index in the referenced table where the referenced columns appear as the first columns near ' foreign key a (a) references t1(b)) engine=innodb'. Error 1005 Can't create table 'test.t2' (errno: 150) create table t2(a int, b int, constraint a foreign key a (a) references t1(a)) engine=innodb; alter table t2 add constraint b foreign key (b) references t2(b); ERROR HY000: Can't create table '#sql-temporary' (errno: 150) show warnings; Level Code Message -Warning 150 Alter table '`test`.`t2`' with foreign key constraint failed. There is no index in the referenced table where the referenced columns appear as the first columns. Error close to foreign key (b) references t2(b). +Warning 150 Alter table '`test`.`t2`' with foreign key constraint failed. There is no index in the referenced table where the referenced columns appear as the first columns near ' foreign key (b) references t2(b)'. Error 1005 Can't create table '#sql-temporary' (errno: 150) drop table t2, t1; create table t1 (f1 integer primary key) engine=innodb; @@ -48,7 +48,7 @@ alter table t1 add constraint c1 foreign key (f1) references t11(f1); ERROR HY000: Can't create table '#sql-temporary' (errno: 150) show warnings; Level Code Message -Warning 150 Alter table `test`.`t1` with foreign key constraint failed. Referenced table `test`.`t11` not found in the data dictionary close to foreign key (f1) references t11(f1). +Warning 150 Alter table `test`.`t1` with foreign key constraint failed. Referenced table `test`.`t11` not found in the data dictionary near ' foreign key (f1) references t11(f1)'. Error 1005 Can't create table '#sql-temporary' (errno: 150) drop table t1; create temporary table t1(a int not null primary key, b int, key(b)) engine=innodb; @@ -56,13 +56,13 @@ create temporary table t2(a int, foreign key(a) references t1(a)) engine=innodb; ERROR HY000: Can't create table 'test.t2' (errno: 150) show warnings; Level Code Message -Warning 150 Create table `mysqld.1`.`t2` with foreign key constraint failed. Referenced table `mysqld.1`.`t1` not found in the data dictionary close to foreign key(a) references t1(a)) engine=innodb. +Warning 150 Create table `mysqld.1`.`t2` with foreign key constraint failed. Referenced table `mysqld.1`.`t1` not found in the data dictionary near 'foreign key(a) references t1(a)) engine=innodb'. Error 1005 Can't create table 'test.t2' (errno: 150) alter table t1 add foreign key(b) references t1(a); ERROR HY000: Can't create table '#sql-temporary' (errno: 150) show warnings; Level Code Message -Warning 150 Alter table `mysqld.1`.`t1` with foreign key constraint failed. Referenced table `mysqld.1`.`t1` not found in the data dictionary close to foreign key(b) references t1(a). +Warning 150 Alter table `mysqld.1`.`t1` with foreign key constraint failed. Referenced table `mysqld.1`.`t1` not found in the data dictionary near 'foreign key(b) references t1(a)'. Error 1005 Can't create table '#sql-temporary' (errno: 150) drop table t1; create table t1(a int not null primary key, b int, key(b)) engine=innodb; @@ -70,7 +70,8 @@ alter table t1 add foreign key(a,b) references t1(a); ERROR HY000: Can't create table '#sql-temporary' (errno: 150) show warnings; Level Code Message -Warning 150 Alter table `test`.`t1` with foreign key constraint failed. Foreign key constraint parse error in foreign key(a,b) references t1(a) close to ). Too few referenced columns, you have 1 when you should have 2. +Warning 150 Alter table `test`.`t1` with foreign key constraint failed. Parse error in 'foreign key(a,b) references t1(a)' near ')'. Referencing column count 1 does not match referenced column count 2. + Error 1005 Can't create table '#sql-temporary' (errno: 150) drop table t1; create table t1(a int not null primary key, b int, key(b)) engine=innodb; @@ -78,7 +79,8 @@ alter table t1 add foreign key(a) references t1(a,b); ERROR HY000: Can't create table '#sql-temporary' (errno: 150) show warnings; Level Code Message -Warning 150 Alter table `test`.`t1` with foreign key constraint failed. Foreign key constraint parse error in foreign key(a) references t1(a,b) close to ). Too few referenced columns, you have 2 when you should have 1. +Warning 150 Alter table `test`.`t1` with foreign key constraint failed. Parse error in 'foreign key(a) references t1(a,b)' near ')'. Referencing column count 2 does not match referenced column count 1. + Error 1005 Can't create table '#sql-temporary' (errno: 150) drop table t1; create table t1 (f1 integer not null primary key) engine=innodb; @@ -86,13 +88,13 @@ alter table t1 add constraint c1 foreign key (f1) references t1(f1) on update se ERROR HY000: Can't create table '#sql-temporary' (errno: 150) show warnings; Level Code Message -Warning 150 Alter table `test`.`t1` with foreign key constraint failed. You have defined a SET NULL condition but column f1 is defined as NOT NULL in foreign key (f1) references t1(f1) on update set null close to on update set null. +Warning 150 Alter table `test`.`t1` with foreign key constraint failed. You have defined a SET NULL condition but column 'f1' is defined as NOT NULL in ' foreign key (f1) references t1(f1) on update set null' near ' on update set null'. Error 1005 Can't create table '#sql-temporary' (errno: 150) create table t2(a int not null, foreign key(a) references t1(f1) on delete set null) engine=innodb; ERROR HY000: Can't create table 'test.t2' (errno: 150) show warnings; Level Code Message -Warning 150 Create table `test`.`t2` with foreign key constraint failed. You have defined a SET NULL condition but column a is defined as NOT NULL in foreign key(a) references t1(f1) on delete set null) engine=innodb close to on delete set null) engine=innodb. +Warning 150 Create table `test`.`t2` with foreign key constraint failed. You have defined a SET NULL condition but column 'a' is defined as NOT NULL in 'foreign key(a) references t1(f1) on delete set null) engine=innodb' near ' on delete set null) engine=innodb'. Error 1005 Can't create table 'test.t2' (errno: 150) drop table t1; create table t1 (id int not null primary key, f1 int, f2 int, key(f1)) engine=innodb; @@ -100,6 +102,6 @@ create table t2(a char(20), key(a), foreign key(a) references t1(f1)) engine=inn ERROR HY000: Can't create table 'test.t2' (errno: 150) show warnings; Level Code Message -Warning 150 Create table `test`.`t2` with foreign key constraint failed. Field type or character set for column a does not mach referenced column f1 close to foreign key(a) references t1(f1)) engine=innodb +Warning 150 Create table `test`.`t2` with foreign key constraint failed. Field type or character set for column 'a' does not mach referenced column 'f1' near 'foreign key(a) references t1(f1)) engine=innodb'. Error 1005 Can't create table 'test.t2' (errno: 150) drop table t1; diff --git a/mysql-test/suite/innodb/r/innodb-fk.result b/mysql-test/suite/innodb/r/innodb-fk.result index 2b53bc21b31..6c3306f5c15 100644 --- a/mysql-test/suite/innodb/r/innodb-fk.result +++ b/mysql-test/suite/innodb/r/innodb-fk.result @@ -50,8 +50,8 @@ CONSTRAINT fk3 FOREIGN KEY (f3) REFERENCES t3 (id) ON DELETE CASCADE ERROR HY000: Can't create table 'test.t2' (errno: 150) show warnings; Level Code Message -Warning 150 Create table `test`.`t2` with foreign key constraint failed. Referenced table `test`.`t3` not found in the data dictionary close to FOREIGN KEY (f3) REFERENCES t3 (id) ON DELETE CASCADE -) ENGINE=InnoDB. +Warning 150 Create table `test`.`t2` with foreign key constraint failed. Referenced table `test`.`t3` not found in the data dictionary near ' FOREIGN KEY (f3) REFERENCES t3 (id) ON DELETE CASCADE +) ENGINE=InnoDB'. Error 1005 Can't create table 'test.t2' (errno: 150) CREATE TABLE t2 ( id int(11) NOT NULL AUTO_INCREMENT, @@ -64,7 +64,7 @@ ALTER TABLE t2 ADD CONSTRAINT fk3 FOREIGN KEY (f3) REFERENCES t3 (id) ON DELETE ERROR HY000: Can't create table '#sql-temporary' (errno: 150) show warnings; Level Code Message -Warning 150 Alter table `test`.`t2` with foreign key constraint failed. Referenced table `test`.`t3` not found in the data dictionary close to FOREIGN KEY (f3) REFERENCES t3 (id) ON DELETE CASCADE. +Warning 150 Alter table `test`.`t2` with foreign key constraint failed. Referenced table `test`.`t3` not found in the data dictionary near ' FOREIGN KEY (f3) REFERENCES t3 (id) ON DELETE CASCADE'. Error 1005 Can't create table '#sql-temporary' (errno: 150) drop table t2; drop table t1; diff --git a/storage/innobase/dict/dict0dict.c b/storage/innobase/dict/dict0dict.c index ad900385325..17e9eb122df 100644 --- a/storage/innobase/dict/dict0dict.c +++ b/storage/innobase/dict/dict0dict.c @@ -3628,13 +3628,13 @@ dict_foreign_push_index_error( "%s table '%s' with foreign key constraint" " failed. There is no index in the referenced" " table where the referenced columns appear" - " as the first columns. Error close to %s.\n", + " as the first columns near '%s'.\n", operation, create_name, latest_foreign); ib_push_warning(trx, DB_CANNOT_ADD_CONSTRAINT, "%s table '%s' with foreign key constraint" " failed. There is no index in the referenced" " table where the referenced columns appear" - " as the first columns. Error close to %s.", + " as the first columns near '%s'.", operation, create_name, latest_foreign); break; } @@ -3643,13 +3643,13 @@ dict_foreign_push_index_error( "%s table '%s' with foreign key constraint" " failed. There is only prefix index in the referenced" " table where the referenced columns appear" - " as the first columns. Error close to %s.\n", + " as the first columns near '%s'.\n", operation, create_name, latest_foreign); ib_push_warning(trx, DB_CANNOT_ADD_CONSTRAINT, "%s table '%s' with foreign key constraint" " failed. There is only prefix index in the referenced" " table where the referenced columns appear" - " as the first columns. Error close to %s.", + " as the first columns near '%s'.", operation, create_name, latest_foreign); break; } @@ -3657,12 +3657,12 @@ dict_foreign_push_index_error( fprintf(ef, "%s table %s with foreign key constraint" " failed. You have defined a SET NULL condition but " - "field %s on index is defined as NOT NULL close to %s\n", + "column '%s' on index is defined as NOT NULL near '%s'.\n", operation, create_name, columns[err_col], latest_foreign); ib_push_warning(trx, DB_CANNOT_ADD_CONSTRAINT, "%s table %s with foreign key constraint" " failed. You have defined a SET NULL condition but " - "field %s on index is defined as NOT NULL close to %s", + "column '%s' on index is defined as NOT NULL near '%s'.", operation, create_name, columns[err_col], latest_foreign); break; } @@ -3675,13 +3675,13 @@ dict_foreign_push_index_error( table, dict_col_get_no(field->col)); fprintf(ef, "%s table %s with foreign key constraint" - " failed. Field type or character set for column %s " - "does not mach referenced column %s close to %s\n", + " failed. Field type or character set for column '%s' " + "does not mach referenced column '%s' near '%s'.\n", operation, create_name, columns[err_col], col_name, latest_foreign); ib_push_warning(trx, DB_CANNOT_ADD_CONSTRAINT, "%s table %s with foreign key constraint" - " failed. Field type or character set for column %s " - "does not mach referenced column %s close to %s", + " failed. Field type or character set for column '%s' " + "does not mach referenced column '%s' near '%s'.", operation, create_name, columns[err_col], col_name, latest_foreign); break; } @@ -3973,14 +3973,14 @@ loop: if (!success) { dict_foreign_report_syntax_err( "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.\n", + " failed. Parse error in '%s'" + " near '%s'.\n", operation, create_name, start_of_latest_foreign, orig); ib_push_warning(trx, DB_CANNOT_ADD_CONSTRAINT, "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.", + " failed. Parse error in '%s'" + " near '%s'.", operation, create_name, start_of_latest_foreign, orig); return(DB_CANNOT_ADD_CONSTRAINT); @@ -4009,16 +4009,16 @@ col_loop1: dict_foreign_error_report_low(ef, create_name); fprintf(ef, "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.\n", + " failed. Parse error in '%s'" + " near '%s'.\n", operation, create_name, start_of_latest_foreign, orig); mutex_exit(&dict_foreign_err_mutex); ib_push_warning(trx, DB_CANNOT_ADD_CONSTRAINT, "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.", + " failed. Parse error in '%s'" + " near '%s'.", operation, create_name, start_of_latest_foreign, orig); return(DB_CANNOT_ADD_CONSTRAINT); @@ -4038,14 +4038,14 @@ col_loop1: if (!success) { dict_foreign_report_syntax_err( "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.\n", + " failed. Parse error in '%s'" + " near '%s'.\n", operation, create_name, start_of_latest_foreign, orig); ib_push_warning(trx, DB_CANNOT_ADD_CONSTRAINT, "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.", + " failed. Parse error in '%s'" + " near '%s'.", operation, create_name, start_of_latest_foreign, orig); return(DB_CANNOT_ADD_CONSTRAINT); @@ -4081,14 +4081,14 @@ col_loop1: if (!success || !my_isspace(cs, *ptr)) { dict_foreign_report_syntax_err( "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.\n", + " failed. Parse error in '%s'" + " near '%s'.\n", operation, create_name, start_of_latest_foreign, orig); ib_push_warning(trx, DB_CANNOT_ADD_CONSTRAINT, "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.", + " failed. Parse error in '%s'" + " near '%s'.", operation, create_name, start_of_latest_foreign, orig); return(DB_CANNOT_ADD_CONSTRAINT); } @@ -4148,7 +4148,7 @@ col_loop1: ib_push_warning(trx, DB_CANNOT_ADD_CONSTRAINT, "%s table %s with foreign key constraint failed. Referenced table %s not found in the data dictionary " - "close to %s.", + "near '%s'.", operation, create_name, buf, start_of_latest_foreign); dict_foreign_free(foreign); @@ -4157,7 +4157,7 @@ col_loop1: dict_foreign_error_report_low(ef, create_name); fprintf(ef, "%s table %s with foreign key constraint failed. Referenced table %s not found in the data dictionary " - "close to %s.\n", + "near '%s'.\n", operation, create_name, buf, start_of_latest_foreign); mutex_exit(&dict_foreign_err_mutex); @@ -4172,14 +4172,14 @@ col_loop1: dict_foreign_free(foreign); dict_foreign_report_syntax_err( "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.\n", + " failed. Parse error in '%s'" + " near '%s'.\n", operation, create_name, start_of_latest_foreign, orig); ib_push_warning(trx, DB_CANNOT_ADD_CONSTRAINT, "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.", + " failed. Parse error in '%s'" + " near '%s'.", operation, create_name, start_of_latest_foreign, orig); return(DB_CANNOT_ADD_CONSTRAINT); @@ -4201,16 +4201,16 @@ col_loop2: dict_foreign_error_report_low(ef, create_name); fprintf(ef, "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.\n", + " failed. Parse error in '%s'" + " near '%s'.\n", operation, create_name, start_of_latest_foreign, orig); mutex_exit(&dict_foreign_err_mutex); ib_push_warning(trx, DB_CANNOT_ADD_CONSTRAINT, "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.", + " failed. Parse error in '%s'" + " near '%s'.", operation, create_name, start_of_latest_foreign, orig); return(DB_CANNOT_ADD_CONSTRAINT); } @@ -4228,14 +4228,12 @@ col_loop2: dict_foreign_report_syntax_err( "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s. Too few referenced columns.\n", + " failed. Parse error in '%s' near '%s'. Referencing column count does not match referenced column count.\n", operation, create_name, start_of_latest_foreign, orig); ib_push_warning(trx, DB_CANNOT_ADD_CONSTRAINT, "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s. Too few referenced columns, you have %d when you should have %d.", + " failed. Parse error in '%s' near '%s'. Referencing column count %d does not match referenced column count %d.\n", operation, create_name, start_of_latest_foreign, orig, i, foreign->n_fields); dict_foreign_free(foreign); @@ -4268,14 +4266,14 @@ scan_on_conditions: dict_foreign_report_syntax_err( "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.\n", + " failed. Parse error in '%s'" + " near '%s'.\n", operation, create_name, start_of_latest_foreign, start_of_latest_set); ib_push_warning(trx, DB_CANNOT_ADD_CONSTRAINT, "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.", + " failed. Parse error in '%s'" + " near '%s'.", operation, create_name, start_of_latest_foreign, start_of_latest_set); return(DB_CANNOT_ADD_CONSTRAINT); @@ -4316,14 +4314,14 @@ scan_on_conditions: dict_foreign_free(foreign); dict_foreign_report_syntax_err( "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.\n", + " failed. Parse error in '%s'" + " near '%s'.\n", operation, create_name, start_of_latest_foreign, start_of_latest_set); ib_push_warning(trx, DB_CANNOT_ADD_CONSTRAINT, "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.", + " failed. Parse error in '%s'" + " near '%s'.", operation, create_name, start_of_latest_foreign, start_of_latest_set); return(DB_CANNOT_ADD_CONSTRAINT); @@ -4345,14 +4343,14 @@ scan_on_conditions: dict_foreign_free(foreign); dict_foreign_report_syntax_err( "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.\n", + " failed. Parse error in '%s'" + " near '%s'.\n", operation, create_name, start_of_latest_foreign, start_of_latest_set); ib_push_warning(trx, DB_CANNOT_ADD_CONSTRAINT, "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.", + " failed. Parse error in '%s'" + " near '%s'.", operation, create_name, start_of_latest_foreign, start_of_latest_set); return(DB_CANNOT_ADD_CONSTRAINT); @@ -4365,14 +4363,14 @@ scan_on_conditions: dict_foreign_free(foreign); dict_foreign_report_syntax_err( "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.\n", + " failed. Parse error in '%s'" + " near '%s'.\n", operation, create_name, start_of_latest_foreign, start_of_latest_set); ib_push_warning(trx, DB_CANNOT_ADD_CONSTRAINT, "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.", + " failed. Parse error in '%s'" + " near '%s'.", operation, create_name, start_of_latest_foreign, start_of_latest_set); return(DB_CANNOT_ADD_CONSTRAINT); } @@ -4392,16 +4390,16 @@ scan_on_conditions: dict_foreign_error_report_low(ef, create_name); fprintf(ef, "%s table %s with foreign key constraint" - " failed. You have defined a SET NULL condition but column %s is defined as NOT NULL" - " in %s close to %s.\n", + " failed. You have defined a SET NULL condition but column '%s' is defined as NOT NULL" + " in '%s' near '%s'.\n", operation, create_name, col_name, start_of_latest_foreign, start_of_latest_set); mutex_exit(&dict_foreign_err_mutex); ib_push_warning(trx, DB_CANNOT_ADD_CONSTRAINT, "%s table %s with foreign key constraint" - " failed. You have defined a SET NULL condition but column %s is defined as NOT NULL" - " in %s close to %s.", + " failed. You have defined a SET NULL condition but column '%s' is defined as NOT NULL" + " in '%s' near '%s'.", operation, create_name, col_name, start_of_latest_foreign, start_of_latest_set); dict_foreign_free(foreign); @@ -4427,14 +4425,14 @@ try_find_index: fprintf(ef, "%s table %s with foreign key constraint" " failed. You have more than one on delete or on update clause" - " in %s close to %s.\n", + " in '%s' near '%s'.\n", operation, create_name, start_of_latest_foreign, start_of_latest_set); mutex_exit(&dict_foreign_err_mutex); ib_push_warning(trx, DB_CANNOT_ADD_CONSTRAINT, "%s table %s with foreign key constraint" " failed. You have more than one on delete or on update clause" - " in %s close to %s.", + " in '%s' near '%s'.", operation, create_name, start_of_latest_foreign, start_of_latest_set); dict_foreign_free(foreign); return(DB_CANNOT_ADD_CONSTRAINT); diff --git a/storage/xtradb/dict/dict0dict.c b/storage/xtradb/dict/dict0dict.c index cd8e4159033..7351de5de2b 100644 --- a/storage/xtradb/dict/dict0dict.c +++ b/storage/xtradb/dict/dict0dict.c @@ -3762,13 +3762,13 @@ dict_foreign_push_index_error( "%s table '%s' with foreign key constraint" " failed. There is no index in the referenced" " table where the referenced columns appear" - " as the first columns. Error close to %s.\n", + " as the first columns near '%s'.\n", operation, create_name, latest_foreign); ib_push_warning(trx, DB_CANNOT_ADD_CONSTRAINT, "%s table '%s' with foreign key constraint" " failed. There is no index in the referenced" " table where the referenced columns appear" - " as the first columns. Error close to %s.", + " as the first columns near '%s'.", operation, create_name, latest_foreign); break; } @@ -3777,13 +3777,13 @@ dict_foreign_push_index_error( "%s table '%s' with foreign key constraint" " failed. There is only prefix index in the referenced" " table where the referenced columns appear" - " as the first columns. Error close to %s.\n", + " as the first columns near '%s'.\n", operation, create_name, latest_foreign); ib_push_warning(trx, DB_CANNOT_ADD_CONSTRAINT, "%s table '%s' with foreign key constraint" " failed. There is only prefix index in the referenced" " table where the referenced columns appear" - " as the first columns. Error close to %s.", + " as the first columns near '%s'.", operation, create_name, latest_foreign); break; } @@ -3791,12 +3791,12 @@ dict_foreign_push_index_error( fprintf(ef, "%s table %s with foreign key constraint" " failed. You have defined a SET NULL condition but " - "field %s on index is defined as NOT NULL close to %s\n", + "column '%s' on index is defined as NOT NULL near '%s'.\n", operation, create_name, columns[err_col], latest_foreign); ib_push_warning(trx, DB_CANNOT_ADD_CONSTRAINT, "%s table %s with foreign key constraint" " failed. You have defined a SET NULL condition but " - "field %s on index is defined as NOT NULL close to %s", + "column '%s' on index is defined as NOT NULL near '%s'.", operation, create_name, columns[err_col], latest_foreign); break; } @@ -3809,13 +3809,13 @@ dict_foreign_push_index_error( table, dict_col_get_no(field->col)); fprintf(ef, "%s table %s with foreign key constraint" - " failed. Field type or character set for column %s " - "does not mach referenced column %s close to %s\n", + " failed. Field type or character set for column '%s' " + "does not mach referenced column '%s' near '%s'.\n", operation, create_name, columns[err_col], col_name, latest_foreign); ib_push_warning(trx, DB_CANNOT_ADD_CONSTRAINT, "%s table %s with foreign key constraint" - " failed. Field type or character set for column %s " - "does not mach referenced column %s close to %s", + " failed. Field type or character set for column '%s' " + "does not mach referenced column '%s' near '%s'.", operation, create_name, columns[err_col], col_name, latest_foreign); break; } @@ -4107,14 +4107,14 @@ loop: if (!success) { dict_foreign_report_syntax_err( "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.\n", + " failed. Parse error in '%s'" + " near '%s'.\n", operation, create_name, start_of_latest_foreign, orig); ib_push_warning(trx, DB_CANNOT_ADD_CONSTRAINT, "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.", + " failed. Parse error in '%s'" + " near '%s'.", operation, create_name, start_of_latest_foreign, orig); return(DB_CANNOT_ADD_CONSTRAINT); @@ -4143,16 +4143,16 @@ col_loop1: dict_foreign_error_report_low(ef, create_name); fprintf(ef, "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.\n", + " failed. Parse error in '%s'" + " near '%s'.\n", operation, create_name, start_of_latest_foreign, orig); mutex_exit(&dict_foreign_err_mutex); ib_push_warning(trx, DB_CANNOT_ADD_CONSTRAINT, "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.", + " failed. Parse error in '%s'" + " near '%s'.", operation, create_name, start_of_latest_foreign, orig); return(DB_CANNOT_ADD_CONSTRAINT); @@ -4172,14 +4172,14 @@ col_loop1: if (!success) { dict_foreign_report_syntax_err( "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.\n", + " failed. Parse error in '%s'" + " near '%s'.\n", operation, create_name, start_of_latest_foreign, orig); ib_push_warning(trx, DB_CANNOT_ADD_CONSTRAINT, "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.", + " failed. Parse error in '%s'" + " near '%s'.", operation, create_name, start_of_latest_foreign, orig); return(DB_CANNOT_ADD_CONSTRAINT); @@ -4215,14 +4215,14 @@ col_loop1: if (!success || !my_isspace(cs, *ptr)) { dict_foreign_report_syntax_err( "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.\n", + " failed. Parse error in '%s'" + " near '%s'.\n", operation, create_name, start_of_latest_foreign, orig); ib_push_warning(trx, DB_CANNOT_ADD_CONSTRAINT, "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.", + " failed. Parse error in '%s'" + " near '%s'.", operation, create_name, start_of_latest_foreign, orig); return(DB_CANNOT_ADD_CONSTRAINT); } @@ -4282,7 +4282,7 @@ col_loop1: ib_push_warning(trx, DB_CANNOT_ADD_CONSTRAINT, "%s table %s with foreign key constraint failed. Referenced table %s not found in the data dictionary " - "close to %s.", + "near '%s'.", operation, create_name, buf, start_of_latest_foreign); dict_foreign_free(foreign); @@ -4291,7 +4291,7 @@ col_loop1: dict_foreign_error_report_low(ef, create_name); fprintf(ef, "%s table %s with foreign key constraint failed. Referenced table %s not found in the data dictionary " - "close to %s.\n", + "near '%s'.\n", operation, create_name, buf, start_of_latest_foreign); mutex_exit(&dict_foreign_err_mutex); @@ -4306,14 +4306,14 @@ col_loop1: dict_foreign_free(foreign); dict_foreign_report_syntax_err( "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.\n", + " failed. Parse error in '%s'" + " near '%s'.\n", operation, create_name, start_of_latest_foreign, orig); ib_push_warning(trx, DB_CANNOT_ADD_CONSTRAINT, "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.", + " failed. Parse error in '%s'" + " near '%s'.", operation, create_name, start_of_latest_foreign, orig); return(DB_CANNOT_ADD_CONSTRAINT); @@ -4335,16 +4335,16 @@ col_loop2: dict_foreign_error_report_low(ef, create_name); fprintf(ef, "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.\n", + " failed. Parse error in '%s'" + " near '%s'.\n", operation, create_name, start_of_latest_foreign, orig); mutex_exit(&dict_foreign_err_mutex); ib_push_warning(trx, DB_CANNOT_ADD_CONSTRAINT, "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.", + " failed. Parse error in '%s'" + " near '%s'.", operation, create_name, start_of_latest_foreign, orig); return(DB_CANNOT_ADD_CONSTRAINT); } @@ -4362,14 +4362,12 @@ col_loop2: dict_foreign_report_syntax_err( "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s. Too few referenced columns\n", + " failed. Parse error in '%s' near '%s'. Referencing column count does not match referenced column count.\n", operation, create_name, start_of_latest_foreign, orig); ib_push_warning(trx, DB_CANNOT_ADD_CONSTRAINT, "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s. Too few referenced columns, you have %d when you should have %d.", + " failed. Parse error in '%s' near '%s'. Referencing column count %d does not match referenced column count %d.\n", operation, create_name, start_of_latest_foreign, orig, i, foreign->n_fields); dict_foreign_free(foreign); @@ -4402,14 +4400,14 @@ scan_on_conditions: dict_foreign_report_syntax_err( "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.\n", + " failed. Parse error in '%s'" + " near '%s'.\n", operation, create_name, start_of_latest_foreign, start_of_latest_set); ib_push_warning(trx, DB_CANNOT_ADD_CONSTRAINT, "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.", + " failed. Parse error in '%s'" + " near '%s'.", operation, create_name, start_of_latest_foreign, start_of_latest_set); return(DB_CANNOT_ADD_CONSTRAINT); @@ -4450,14 +4448,14 @@ scan_on_conditions: dict_foreign_free(foreign); dict_foreign_report_syntax_err( "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.\n", + " failed. Parse error in '%s'" + " near '%s'.\n", operation, create_name, start_of_latest_foreign, start_of_latest_set); ib_push_warning(trx, DB_CANNOT_ADD_CONSTRAINT, "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.", + " failed. Parse error in '%s'" + " near '%s'.", operation, create_name, start_of_latest_foreign, start_of_latest_set); return(DB_CANNOT_ADD_CONSTRAINT); @@ -4479,14 +4477,14 @@ scan_on_conditions: dict_foreign_free(foreign); dict_foreign_report_syntax_err( "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.\n", + " failed. Parse error in '%s'" + " near '%s'.\n", operation, create_name, start_of_latest_foreign, start_of_latest_set); ib_push_warning(trx, DB_CANNOT_ADD_CONSTRAINT, "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.", + " failed. Parse error in '%s'" + " near '%s'.", operation, create_name, start_of_latest_foreign, start_of_latest_set); return(DB_CANNOT_ADD_CONSTRAINT); @@ -4499,14 +4497,14 @@ scan_on_conditions: dict_foreign_free(foreign); dict_foreign_report_syntax_err( "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.\n", + " failed. Parse error in '%s'" + " near '%s'.\n", operation, create_name, start_of_latest_foreign, start_of_latest_set); ib_push_warning(trx, DB_CANNOT_ADD_CONSTRAINT, "%s table %s with foreign key constraint" - " failed. Foreign key constraint parse error in %s" - " close to %s.", + " failed. Parse error in '%s'" + " near '%s'.", operation, create_name, start_of_latest_foreign, start_of_latest_set); return(DB_CANNOT_ADD_CONSTRAINT); } @@ -4526,16 +4524,16 @@ scan_on_conditions: dict_foreign_error_report_low(ef, create_name); fprintf(ef, "%s table %s with foreign key constraint" - " failed. You have defined a SET NULL condition but column %s is defined as NOT NULL" - " in %s close to %s.\n", + " failed. You have defined a SET NULL condition but column '%s' is defined as NOT NULL" + " in '%s' near '%s'.\n", operation, create_name, col_name, start_of_latest_foreign, start_of_latest_set); mutex_exit(&dict_foreign_err_mutex); ib_push_warning(trx, DB_CANNOT_ADD_CONSTRAINT, "%s table %s with foreign key constraint" - " failed. You have defined a SET NULL condition but column %s is defined as NOT NULL" - " in %s close to %s.", + " failed. You have defined a SET NULL condition but column '%s' is defined as NOT NULL" + " in '%s' near '%s'.", operation, create_name, col_name, start_of_latest_foreign, start_of_latest_set); dict_foreign_free(foreign); @@ -4561,14 +4559,14 @@ try_find_index: fprintf(ef, "%s table %s with foreign key constraint" " failed. You have more than one on delete or on update clause" - " in %s close to %s.\n", + " in '%s' near '%s'.\n", operation, create_name, start_of_latest_foreign, start_of_latest_set); mutex_exit(&dict_foreign_err_mutex); ib_push_warning(trx, DB_CANNOT_ADD_CONSTRAINT, "%s table %s with foreign key constraint" " failed. You have more than one on delete or on update clause" - " in %s close to %s.", + " in '%s' near '%s'.", operation, create_name, start_of_latest_foreign, start_of_latest_set); dict_foreign_free(foreign); return(DB_CANNOT_ADD_CONSTRAINT); From 7e4da9b370d032db9015adb47ad2ff585aeaea5d Mon Sep 17 00:00:00 2001 From: Oleksandr Byelkin Date: Fri, 6 Nov 2015 16:36:41 +0100 Subject: [PATCH 3/6] DEV-8632 Segmentation fault on INSERT View/derived fields should be taken into account when we build ref_pointer_array constructed. DBUG_ASSERTs added to avoid memory overrun. --- mysql-test/r/view.result | 33 +++++++++++++++++++++++++++++++++ mysql-test/t/view.test | 35 +++++++++++++++++++++++++++++++++++ sql/item.cc | 3 +++ sql/sql_select.cc | 6 ++++++ sql/sql_view.cc | 5 +++++ sql/sql_yacc.yy | 9 +++++++++ 6 files changed, 91 insertions(+) diff --git a/mysql-test/r/view.result b/mysql-test/r/view.result index 57065d74274..b008e623b5d 100644 --- a/mysql-test/r/view.result +++ b/mysql-test/r/view.result @@ -5479,6 +5479,39 @@ UPDATE t1, t2 SET a = 1 WHERE a IN ( SELECT 0 FROM v3 ); EXECUTE stmt; DROP TABLE t1, t2, t3; DROP VIEW v3; +# +# MDEV-8632: Segmentation fault on INSERT +# +CREATE TABLE `t1` ( +`id` int(10) unsigned NOT NULL, +`r` float NOT NULL, +PRIMARY KEY (`id`) +) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +create view v1 as select id, if(r=r,1,2) as d from t1; +create view v2 as +select id, +d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d as p +from v1; +insert into t1 (id, r) +select id,p from +( +select id, +d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d as p +from ( +select id, if(r=r,1,2) as d +from t1 +) a +) b +on duplicate key update r=p; +insert into t1 (id, r) +select id,p from v2 +on duplicate key update r=p; +prepare stmt from "insert into t1 (id, r) select id,p from v2 on duplicate key update r=p"; +execute stmt; +execute stmt; +deallocate prepare stmt; +drop view v1,v2; +drop table `t1`; # ----------------------------------------------------------------- # -- End of 5.5 tests. # ----------------------------------------------------------------- diff --git a/mysql-test/t/view.test b/mysql-test/t/view.test index fe04cdfecec..815be87b04e 100644 --- a/mysql-test/t/view.test +++ b/mysql-test/t/view.test @@ -5445,6 +5445,41 @@ EXECUTE stmt; DROP TABLE t1, t2, t3; DROP VIEW v3; +--echo # +--echo # MDEV-8632: Segmentation fault on INSERT +--echo # +CREATE TABLE `t1` ( + `id` int(10) unsigned NOT NULL, + `r` float NOT NULL, + PRIMARY KEY (`id`) +) DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; +create view v1 as select id, if(r=r,1,2) as d from t1; +create view v2 as + select id, + d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d as p + from v1; +insert into t1 (id, r) +select id,p from +( + select id, + d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d+d as p + from ( + select id, if(r=r,1,2) as d + from t1 + ) a +) b +on duplicate key update r=p; +insert into t1 (id, r) +select id,p from v2 +on duplicate key update r=p; + +prepare stmt from "insert into t1 (id, r) select id,p from v2 on duplicate key update r=p"; +execute stmt; +execute stmt; +deallocate prepare stmt; + +drop view v1,v2; +drop table `t1`; --echo # ----------------------------------------------------------------- --echo # -- End of 5.5 tests. --echo # ----------------------------------------------------------------- diff --git a/sql/item.cc b/sql/item.cc index 878c9604ca2..840272c57a4 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -1891,6 +1891,8 @@ void Item::split_sum_func2(THD *thd, Item **ref_pointer_array, */ Item_aggregate_ref *item_ref; uint el= fields.elements; + DBUG_ASSERT(fields.elements <= + thd->lex->current_select->ref_pointer_array_size); /* If this is an item_ref, get the original item This is a safety measure if this is called for things that is @@ -6719,6 +6721,7 @@ Item *Item_field::update_value_transformer(uchar *select_arg) { List *all_fields= &select->join->all_fields; Item **ref_pointer_array= select->ref_pointer_array; + DBUG_ASSERT(all_fields->elements <= select->ref_pointer_array_size); int el= all_fields->elements; Item_ref *ref; diff --git a/sql/sql_select.cc b/sql/sql_select.cc index e960a3d7c45..ef1b5b0014e 100644 --- a/sql/sql_select.cc +++ b/sql/sql_select.cc @@ -427,6 +427,7 @@ fix_inner_refs(THD *thd, List &all_fields, SELECT_LEX *select, if (ref_pointer_array && !ref->found_in_select_list) { int el= all_fields.elements; + DBUG_ASSERT(all_fields.elements <= select->ref_pointer_array_size); ref_pointer_array[el]= item; /* Add the field item to the select list of the current select. */ all_fields.push_front(item); @@ -832,6 +833,7 @@ JOIN::prepare(Item ***rref_pointer_array, { Item_field *field= new Item_field(thd, *(Item_field**)ord->item); int el= all_fields.elements; + DBUG_ASSERT(all_fields.elements <= select_lex->ref_pointer_array_size); ref_pointer_array[el]= field; all_fields.push_front(field); ord->item= ref_pointer_array + el; @@ -20596,6 +20598,8 @@ find_order_in_list(THD *thd, Item **ref_pointer_array, TABLE_LIST *tables, return TRUE; /* Wrong field. */ uint el= all_fields.elements; + DBUG_ASSERT(all_fields.elements <= + thd->lex->current_select->ref_pointer_array_size); all_fields.push_front(order_item); /* Add new field to field list. */ ref_pointer_array[el]= order_item; /* @@ -20855,6 +20859,8 @@ create_distinct_group(THD *thd, Item **ref_pointer_array, */ Item_field *new_item= new Item_field(thd, (Item_field*)item); int el= all_fields.elements; + DBUG_ASSERT(all_fields.elements <= + thd->lex->current_select->ref_pointer_array_size); orig_ref_pointer_array[el]= new_item; all_fields.push_front(new_item); ord->item= orig_ref_pointer_array + el; diff --git a/sql/sql_view.cc b/sql/sql_view.cc index 255f876e02a..e6c5ffddfcf 100644 --- a/sql/sql_view.cc +++ b/sql/sql_view.cc @@ -1520,6 +1520,11 @@ bool mysql_make_view(THD *thd, File_parser *parser, TABLE_LIST *table, */ lex->sql_command= old_lex->sql_command; lex->duplicates= old_lex->duplicates; + + /* Fields in this view can be used in upper select in case of merge. */ + if (table->select_lex) + table->select_lex->select_n_where_fields+= + lex->select_lex.select_n_where_fields; } /* This method has a dependency on the proper lock type being set, diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index a49dea6380e..11d7efdbadf 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -9872,6 +9872,15 @@ table_factor: sel->add_joined_table($$); lex->pop_context(); lex->nest_level--; + /* + Fields in derived table can be used in upper select in + case of merge. We do not add HAVING fields because we do + not merge such derived. We do not add union because + also do not merge them + */ + if (!sel->next_select()) + $2->select_n_where_fields+= + sel->select_n_where_fields; } /*else if (($3->select_lex && $3->select_lex->master_unit()->is_union() && From e669a5fd87b28158cbb4454b4bcce7fe4a4ef8b8 Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Tue, 17 Nov 2015 18:33:08 +0100 Subject: [PATCH 4/6] MDEV-7588 Add thd_wait_begin/end to notify threadpool of binlog waits --- sql/log.cc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sql/log.cc b/sql/log.cc index 0940cb9b56c..a87ec7225d1 100644 --- a/sql/log.cc +++ b/sql/log.cc @@ -6296,11 +6296,13 @@ int MYSQL_BIN_LOG::wait_for_update_bin_log(THD* thd, int ret= 0; DBUG_ENTER("wait_for_update_bin_log"); + thd_wait_begin(thd, THD_WAIT_BINLOG); if (!timeout) mysql_cond_wait(&update_cond, &LOCK_log); else ret= mysql_cond_timedwait(&update_cond, &LOCK_log, const_cast(timeout)); + thd_wait_end(thd); DBUG_RETURN(ret); } From 726162989bdffca6af4a83c018a7d8eafeb82e6f Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 18 Nov 2015 10:58:51 +0100 Subject: [PATCH 5/6] feedback plugin debug make it possible to change feedback plugin wait intervals * only in debug builds * and force the feedback report to be ignored update the test to use this feature --- mysql-test/include/default_mysqld.cnf | 3 ++ .../plugins/r/feedback_plugin_install.result | 3 +- .../plugins/r/feedback_plugin_load.result | 3 +- .../plugins/r/feedback_plugin_send.result | 9 +++-- .../plugins/t/feedback_plugin_install.test | 4 ++- .../suite/plugins/t/feedback_plugin_load.test | 3 +- .../suite/plugins/t/feedback_plugin_send.test | 15 +++------ plugin/feedback/feedback.cc | 33 +++++++++++++++++++ plugin/feedback/feedback.h | 4 +++ plugin/feedback/sender_thread.cc | 6 ++-- 10 files changed, 61 insertions(+), 22 deletions(-) diff --git a/mysql-test/include/default_mysqld.cnf b/mysql-test/include/default_mysqld.cnf index 96848c39f11..40d699ce759 100644 --- a/mysql-test/include/default_mysqld.cnf +++ b/mysql-test/include/default_mysqld.cnf @@ -38,6 +38,9 @@ max_heap_table_size= 1M loose-aria-pagecache-buffer-size=8M loose-feedback-user-info= mysql-test +loose-feedback-debug-startup-interval=20 +loose-feedback-debug-first-interval=60 +loose-feedback-debug-interval=60 loose-innodb_data_file_path= ibdata1:10M:autoextend loose-innodb_buffer_pool_size= 8M diff --git a/mysql-test/suite/plugins/r/feedback_plugin_install.result b/mysql-test/suite/plugins/r/feedback_plugin_install.result index 37d26b48501..c52fdb8f85b 100644 --- a/mysql-test/suite/plugins/r/feedback_plugin_install.result +++ b/mysql-test/suite/plugins/r/feedback_plugin_install.result @@ -3,7 +3,8 @@ select plugin_status from information_schema.plugins where plugin_name='feedback plugin_status ACTIVE select * from information_schema.feedback where variable_name like 'feed%' - and variable_name not like '%_uid'; + and variable_name not like '%_uid' + and variable_name not like '%debug%'; VARIABLE_NAME VARIABLE_VALUE FEEDBACK used 1 FEEDBACK version 1.1 diff --git a/mysql-test/suite/plugins/r/feedback_plugin_load.result b/mysql-test/suite/plugins/r/feedback_plugin_load.result index ea6eae98601..e2cf3247022 100644 --- a/mysql-test/suite/plugins/r/feedback_plugin_load.result +++ b/mysql-test/suite/plugins/r/feedback_plugin_load.result @@ -6,7 +6,8 @@ SELECT variable_value = @feedback_used + 1 FROM information_schema.feedback wher variable_value = @feedback_used + 1 1 select * from information_schema.feedback where variable_name like 'feed%' - and variable_name not like '%_uid' and variable_name not like 'FEEDBACK used'; + and variable_name not like '%_uid' and variable_name not like 'FEEDBACK used' + and variable_name not like '%debug%'; VARIABLE_NAME VARIABLE_VALUE FEEDBACK version 1.1 FEEDBACK_SEND_RETRY_WAIT 60 diff --git a/mysql-test/suite/plugins/r/feedback_plugin_send.result b/mysql-test/suite/plugins/r/feedback_plugin_send.result index 90a37f7ffbc..56a4e37981c 100644 --- a/mysql-test/suite/plugins/r/feedback_plugin_send.result +++ b/mysql-test/suite/plugins/r/feedback_plugin_send.result @@ -6,14 +6,13 @@ SELECT variable_value = @feedback_used + 1 FROM information_schema.feedback wher variable_value = @feedback_used + 1 1 select * from information_schema.feedback where variable_name like 'feed%' - and variable_name not like '%_uid' and variable_name not like 'FEEDBACK used'; + and variable_name not like '%_uid' and variable_name not like 'FEEDBACK used' + and variable_name not like '%debug%'; VARIABLE_NAME VARIABLE_VALUE FEEDBACK version 1.1 FEEDBACK_SEND_RETRY_WAIT 60 FEEDBACK_SEND_TIMEOUT 60 FEEDBACK_URL http://mariadb.org/feedback_plugin/post FEEDBACK_USER_INFO mysql-test -feedback plugin: report to 'http://mariadb.org/feedback_plugin/post' was sent -feedback plugin: server replied 'ok' -feedback plugin: report to 'http://mariadb.org/feedback_plugin/post' was sent -feedback plugin: server replied 'ok' +6: feedback plugin: report to 'http://mariadb.org/feedback_plugin/post' was sent +6: feedback plugin: server replied 'ok' diff --git a/mysql-test/suite/plugins/t/feedback_plugin_install.test b/mysql-test/suite/plugins/t/feedback_plugin_install.test index 81343c436c3..559dcebfc05 100644 --- a/mysql-test/suite/plugins/t/feedback_plugin_install.test +++ b/mysql-test/suite/plugins/t/feedback_plugin_install.test @@ -10,6 +10,8 @@ select plugin_status from information_schema.plugins where plugin_name='feedback --replace_result https http --sorted_result select * from information_schema.feedback where variable_name like 'feed%' - and variable_name not like '%_uid'; + and variable_name not like '%_uid' + and variable_name not like '%debug%'; + uninstall plugin feedback; diff --git a/mysql-test/suite/plugins/t/feedback_plugin_load.test b/mysql-test/suite/plugins/t/feedback_plugin_load.test index f7c62b96b49..f626f1b0125 100644 --- a/mysql-test/suite/plugins/t/feedback_plugin_load.test +++ b/mysql-test/suite/plugins/t/feedback_plugin_load.test @@ -24,4 +24,5 @@ SELECT variable_value = @feedback_used + 1 FROM information_schema.feedback wher --replace_result https http --sorted_result select * from information_schema.feedback where variable_name like 'feed%' - and variable_name not like '%_uid' and variable_name not like 'FEEDBACK used'; + and variable_name not like '%_uid' and variable_name not like 'FEEDBACK used' + and variable_name not like '%debug%'; diff --git a/mysql-test/suite/plugins/t/feedback_plugin_send.test b/mysql-test/suite/plugins/t/feedback_plugin_send.test index 31542c33482..31ab213831e 100644 --- a/mysql-test/suite/plugins/t/feedback_plugin_send.test +++ b/mysql-test/suite/plugins/t/feedback_plugin_send.test @@ -25,20 +25,15 @@ sleep 310; --let $shutdown_timeout= 60 source include/restart_mysqld.inc; -replace_result https http; +replace_result https http 2 6; perl; $log_error= $ENV{'MYSQLTEST_VARDIR'} . '/log/mysqld.1.err'; open(LOG, '<', $log_error) or die "open(< $log_error): $!"; - # Get the first few rows (as there may be different number rows in the log) - $i= 0; - while ($_=) - { - if (/feedback plugin:.*/) - { - print "$&\n"; - break if ($i++ >= 3); - } + %logg=(); + while ($_=) { + $logg{$&}++ if /feedback plugin:.*/; } + print "$logg{$_}: $_\n" for sort keys %logg; close LOG; EOF diff --git a/plugin/feedback/feedback.cc b/plugin/feedback/feedback.cc index 9bf2fcb99bc..f87caa54cbc 100644 --- a/plugin/feedback/feedback.cc +++ b/plugin/feedback/feedback.cc @@ -22,6 +22,10 @@ extern ST_SCHEMA_TABLE schema_tables[]; namespace feedback { +#ifndef DBUG_OFF +ulong debug_startup_interval, debug_first_interval, debug_interval; +#endif + char server_uid_buf[SERVER_UID_SIZE+1]; ///< server uid will be written here /* backing store for system variables */ @@ -249,6 +253,18 @@ static int init(void *p) prepare_linux_info(); +#ifndef DBUG_OFF + if (startup_interval != debug_startup_interval || + first_interval != debug_first_interval || + interval != debug_interval) + { + startup_interval= debug_startup_interval; + first_interval= debug_first_interval; + interval= debug_interval; + user_info= "mysql-test"; + } +#endif + url_count= 0; if (*url) { @@ -347,12 +363,29 @@ static MYSQL_SYSVAR_ULONG(send_retry_wait, send_retry_wait, PLUGIN_VAR_RQCMDARG, "Wait this many seconds before retrying a failed send.", NULL, NULL, 60, 1, 60*60*24, 1); +#ifndef DBUG_OFF +static MYSQL_SYSVAR_ULONG(debug_startup_interval, debug_startup_interval, + PLUGIN_VAR_RQCMDARG, "for debugging only", + NULL, NULL, startup_interval, 1, INT_MAX32, 1); +static MYSQL_SYSVAR_ULONG(debug_first_interval, debug_first_interval, + PLUGIN_VAR_RQCMDARG, "for debugging only", + NULL, NULL, first_interval, 1, INT_MAX32, 1); +static MYSQL_SYSVAR_ULONG(debug_interval, debug_interval, + PLUGIN_VAR_RQCMDARG, "for debugging only", + NULL, NULL, interval, 1, INT_MAX32, 1); +#endif + static struct st_mysql_sys_var* settings[] = { MYSQL_SYSVAR(server_uid), MYSQL_SYSVAR(user_info), MYSQL_SYSVAR(url), MYSQL_SYSVAR(send_timeout), MYSQL_SYSVAR(send_retry_wait), +#ifndef DBUG_OFF + MYSQL_SYSVAR(debug_startup_interval), + MYSQL_SYSVAR(debug_first_interval), + MYSQL_SYSVAR(debug_interval), +#endif NULL }; diff --git a/plugin/feedback/feedback.h b/plugin/feedback/feedback.h index c5acbb5ef72..63aa4f8db8a 100644 --- a/plugin/feedback/feedback.h +++ b/plugin/feedback/feedback.h @@ -58,6 +58,10 @@ class Url { extern Url **urls; extern uint url_count; +extern time_t startup_interval; +extern time_t first_interval; +extern time_t interval; + /* these are used to communicate with the background thread */ extern mysql_mutex_t sleep_mutex; extern mysql_cond_t sleep_condition; diff --git a/plugin/feedback/sender_thread.cc b/plugin/feedback/sender_thread.cc index 4ab45998484..abc3d0a18e6 100644 --- a/plugin/feedback/sender_thread.cc +++ b/plugin/feedback/sender_thread.cc @@ -25,9 +25,9 @@ static my_thread_id thd_thread_id; ///< its thread_id static size_t needed_size= 20480; -static const time_t startup_interval= 60*5; ///< in seconds (5 minutes) -static const time_t first_interval= 60*60*24; ///< in seconds (one day) -static const time_t interval= 60*60*24*7; ///< in seconds (one week) +time_t startup_interval= 60*5; ///< in seconds (5 minutes) +time_t first_interval= 60*60*24; ///< in seconds (one day) +time_t interval= 60*60*24*7; ///< in seconds (one week) /** reads the rows from a table and puts them, concatenated, in a String From 43a5090980ac0ab9695587979b9068b6bf849d64 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 18 Nov 2015 11:20:59 +0100 Subject: [PATCH 6/6] MDEV-9051 mysqld got signal 11, after upgrade to 10.1.8 feedback plugin needs to set tables->select_lex properly --- mysql-test/suite/plugins/r/feedback_plugin_send.result | 1 + mysql-test/suite/plugins/t/feedback_plugin_send.test | 6 +++++- plugin/feedback/sender_thread.cc | 1 + 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/mysql-test/suite/plugins/r/feedback_plugin_send.result b/mysql-test/suite/plugins/r/feedback_plugin_send.result index 56a4e37981c..10378673829 100644 --- a/mysql-test/suite/plugins/r/feedback_plugin_send.result +++ b/mysql-test/suite/plugins/r/feedback_plugin_send.result @@ -14,5 +14,6 @@ FEEDBACK_SEND_RETRY_WAIT 60 FEEDBACK_SEND_TIMEOUT 60 FEEDBACK_URL http://mariadb.org/feedback_plugin/post FEEDBACK_USER_INFO mysql-test +set global sql_mode=ONLY_FULL_GROUP_BY; 6: feedback plugin: report to 'http://mariadb.org/feedback_plugin/post' was sent 6: feedback plugin: server replied 'ok' diff --git a/mysql-test/suite/plugins/t/feedback_plugin_send.test b/mysql-test/suite/plugins/t/feedback_plugin_send.test index 31ab213831e..b28f9d4cb38 100644 --- a/mysql-test/suite/plugins/t/feedback_plugin_send.test +++ b/mysql-test/suite/plugins/t/feedback_plugin_send.test @@ -13,7 +13,11 @@ if (!$MTR_FEEDBACK_PLUGIN) { # Let's wait, and hope that mtr is started with --parallel and # is doing some work in other workers. # -sleep 310; + +sleep 100; +set global sql_mode=ONLY_FULL_GROUP_BY; +sleep 210; + # The test expects that the plugin will send a report at least 2 times, # now (5 min after loading) and on server shutdown which happens below. diff --git a/plugin/feedback/sender_thread.cc b/plugin/feedback/sender_thread.cc index abc3d0a18e6..f32bf36a634 100644 --- a/plugin/feedback/sender_thread.cc +++ b/plugin/feedback/sender_thread.cc @@ -124,6 +124,7 @@ static int prepare_for_fill(TABLE_LIST *tables) if (!tables->table) return 1; + tables->select_lex= thd->lex->current_select; tables->table->pos_in_table_list= tables; return 0;