From 25570648732e202fd9b3291c379c9bfadfb5b15e Mon Sep 17 00:00:00 2001 From: Ian Gilfillan Date: Wed, 14 Apr 2021 02:17:48 +0200 Subject: [PATCH 01/14] MDEV-25354: Fix my_print_defaults wording --- extra/my_print_defaults.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extra/my_print_defaults.c b/extra/my_print_defaults.c index 5992af3bb78..d75c3f51319 100644 --- a/extra/my_print_defaults.c +++ b/extra/my_print_defaults.c @@ -116,7 +116,7 @@ static void usage() { version(); puts("This software comes with ABSOLUTELY NO WARRANTY. This is free software,\nand you are welcome to modify and redistribute it under the GPL license\n"); - puts("Prints all arguments that is give to some program using the default files"); + puts("Displays the options from option groups of option files, which is useful to see which options a particular tool will use"); printf("Usage: %s [OPTIONS] [groups]\n", my_progname); my_print_help(my_long_options); my_print_default_files(config_file); From 7b791b82b86ced825a2cca8da7db8a9a887fd545 Mon Sep 17 00:00:00 2001 From: Alice Sherepa Date: Tue, 13 Apr 2021 18:32:05 +0200 Subject: [PATCH 02/14] MDEV-25363 binlog_stm_datetime_ranges_mdev15289 failed in bb --- mysql-test/suite/binlog/r/binlog_statement_insert_delayed.result | 1 + mysql-test/suite/binlog/t/binlog_statement_insert_delayed.test | 1 + 2 files changed, 2 insertions(+) diff --git a/mysql-test/suite/binlog/r/binlog_statement_insert_delayed.result b/mysql-test/suite/binlog/r/binlog_statement_insert_delayed.result index d6875ab60e0..a4cd5b4080d 100644 --- a/mysql-test/suite/binlog/r/binlog_statement_insert_delayed.result +++ b/mysql-test/suite/binlog/r/binlog_statement_insert_delayed.result @@ -50,3 +50,4 @@ a 400 401 drop table t1; +reset master; diff --git a/mysql-test/suite/binlog/t/binlog_statement_insert_delayed.test b/mysql-test/suite/binlog/t/binlog_statement_insert_delayed.test index 570a7440592..736bcaf0cbe 100644 --- a/mysql-test/suite/binlog/t/binlog_statement_insert_delayed.test +++ b/mysql-test/suite/binlog/t/binlog_statement_insert_delayed.test @@ -10,3 +10,4 @@ disable_query_log; call mtr.add_suppression("Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT"); enable_query_log; -- source extra/binlog_tests/binlog_insert_delayed.test +reset master; From 022d3fa652d993ec198fb9f700ad4adb2fadcb41 Mon Sep 17 00:00:00 2001 From: Ian Gilfillan Date: Wed, 14 Apr 2021 14:46:47 +0200 Subject: [PATCH 03/14] Update mysqlbinlog man page with --table option --- man/mysqlbinlog.1 | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/man/mysqlbinlog.1 b/man/mysqlbinlog.1 index 10ae7302247..22e32bd1628 100644 --- a/man/mysqlbinlog.1 +++ b/man/mysqlbinlog.1 @@ -1,6 +1,6 @@ '\" t .\" -.TH "\FBMYSQLBINLOG\FR" "1" "3 April 2017" "MariaDB 10\&.2" "MariaDB Database System" +.TH "\FBMYSQLBINLOG\FR" "1" "14 April 2021" "MariaDB 10\&.2" "MariaDB Database System" .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- @@ -1091,6 +1091,23 @@ This option is useful for point\-in\-time recovery\&. .sp -1 .IP \(bu 2.3 .\} +.\" mysqlbinlog: table option +.\" table option: mysqlbinlog +\fB\-\-table\fR, +\fB\-T\fR +.sp +List entries for just this table (local log only)\&. +.RE +.sp +.RS 4 +.ie n \{\ +\h'-04'\(bu\h'+03'\c +.\} +.el \{\ +.sp -1 +.IP \(bu 2.3 +.\} + .\" mysqlbinlog: to-last-log option .\" to-last-log option: mysqlbinlog \fB\-\-to\-last\-log\fR, @@ -2107,7 +2124,7 @@ option can be used to prevent this header from being written\&. .SH "COPYRIGHT" .br .PP -Copyright 2007-2008 MySQL AB, 2008-2010 Sun Microsystems, Inc., 2010-2015 MariaDB Foundation +Copyright 2007-2008 MySQL AB, 2008-2010 Sun Microsystems, Inc., 2010-2021 MariaDB Foundation .PP This documentation is free software; you can redistribute it and/or modify it only under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. .PP From 3ebd6cd3ad7c4f7584837d37452f3a456dd48085 Mon Sep 17 00:00:00 2001 From: David Carlier Date: Tue, 30 Mar 2021 18:48:56 +0100 Subject: [PATCH 04/14] signal handler, display coredump file pattern similarly to MDEV-25294 but for FreeBSD, thankfully the sysctl OID is the same. --- sql/signal_handler.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/sql/signal_handler.cc b/sql/signal_handler.cc index 61c53e6b6e3..08ea696752a 100644 --- a/sql/signal_handler.cc +++ b/sql/signal_handler.cc @@ -31,7 +31,7 @@ #endif -#ifdef __APPLE__ +#if defined(__APPLE__) || defined(__FreeBSD__) #include #endif @@ -56,7 +56,7 @@ extern const char *optimizer_switch_names[]; static inline void output_core_info() { /* proc is optional on some BSDs so it can't hurt to look */ -#if defined(HAVE_READLINK) && !defined(__APPLE__) +#if defined(HAVE_READLINK) && !defined(__APPLE__) && !defined(__FreeBSD__) char buff[PATH_MAX]; ssize_t len; int fd; @@ -82,7 +82,7 @@ static inline void output_core_info() my_close(fd, MYF(0)); } #endif -#elif defined(__APPLE__) +#elif defined(__APPLE__) || defined(__FreeBSD__) char buff[PATH_MAX]; size_t len = sizeof(buff); if (sysctlbyname("kern.corefile", buff, &len, NULL, 0) == 0) From cc3105e100e9b07ce6ab24f58efd1bb9d42570aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Otto=20Kek=C3=A4l=C3=A4inen?= Date: Sun, 20 Dec 2020 20:52:51 +0200 Subject: [PATCH 05/14] Fix riscv64 build failure by linking correctly with pthread Link with -pthread instead of -lpthread, and do that for all architectures. Contributors: Aurelien Jarno Closes: #1717 --- configure.cmake | 1 + 1 file changed, 1 insertion(+) diff --git a/configure.cmake b/configure.cmake index ad2626e0357..1b85c31bdf4 100644 --- a/configure.cmake +++ b/configure.cmake @@ -134,6 +134,7 @@ IF(UNIX) IF(NOT LIBRT) MY_SEARCH_LIBS(clock_gettime rt LIBRT) ENDIF() + set(THREADS_PREFER_PTHREAD_FLAG ON) FIND_PACKAGE(Threads) SET(CMAKE_REQUIRED_LIBRARIES From 499e617182c3139b36978faafe186934bd218f54 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Tue, 13 Apr 2021 19:52:40 +0200 Subject: [PATCH 06/14] MDEV-25403 ALTER TABLE wrongly checks for field's default value if AFTER is used When a column is added to an non-empty table, existing rows will have a column's default value for existing rows. Or a "zero value" if the column has no default. But this check should be skipped when an existing column is altered. --- mysql-test/r/alter_table.result | 17 +++++++++++++++++ mysql-test/t/alter_table.test | 12 ++++++++++++ sql/sql_table.cc | 2 +- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/alter_table.result b/mysql-test/r/alter_table.result index 69322bb9028..1fcb8c6a33d 100644 --- a/mysql-test/r/alter_table.result +++ b/mysql-test/r/alter_table.result @@ -2517,5 +2517,22 @@ ALTER TABLE t1 ALTER COLUMN k1 SET DEFAULT (SELECT 1 FROM t2 limit 1); ERROR HY000: Function or expression 'select ...' cannot be used in the DEFAULT clause of `k1` DROP TABLE t1,t2; # +# MDEV-25403 ALTER TABLE wrongly checks for field's default value if AFTER is used +# +create table t1(t int, d date not null); +insert into t1 values (1,'2001-1-1'); +set sql_mode = "no_zero_date"; +alter table t1 change d d date not null after t, add i int; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `t` int(11) DEFAULT NULL, + `d` date NOT NULL, + `i` int(11) DEFAULT NULL +) ENGINE=MyISAM DEFAULT CHARSET=latin1 +alter table t1 add x date not null; +ERROR 22007: Incorrect date value: '0000-00-00' for column `test`.`t1`.`x` at row 1 +drop table t1; +# # End of 10.2 tests # diff --git a/mysql-test/t/alter_table.test b/mysql-test/t/alter_table.test index 2f1a40cbacd..7b03ead3739 100644 --- a/mysql-test/t/alter_table.test +++ b/mysql-test/t/alter_table.test @@ -2044,6 +2044,18 @@ CREATE TABLE t2 (i1 int); ALTER TABLE t1 ALTER COLUMN k1 SET DEFAULT (SELECT 1 FROM t2 limit 1); DROP TABLE t1,t2; +--echo # +--echo # MDEV-25403 ALTER TABLE wrongly checks for field's default value if AFTER is used +--echo # +create table t1(t int, d date not null); +insert into t1 values (1,'2001-1-1'); +set sql_mode = "no_zero_date"; +alter table t1 change d d date not null after t, add i int; +show create table t1; +--error ER_TRUNCATED_WRONG_VALUE +alter table t1 add x date not null; +drop table t1; + --echo # --echo # End of 10.2 tests --echo # diff --git a/sql/sql_table.cc b/sql/sql_table.cc index cb28c6adcec..d472e2332f2 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -7906,7 +7906,7 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, def->sql_type == MYSQL_TYPE_NEWDATE || def->sql_type == MYSQL_TYPE_DATETIME || def->sql_type == MYSQL_TYPE_DATETIME2) && - !alter_ctx->datetime_field && + !alter_ctx->datetime_field && !def->field && !(~def->flags & (NO_DEFAULT_VALUE_FLAG | NOT_NULL_FLAG)) && thd->variables.sql_mode & MODE_NO_ZERO_DATE) { From 343fe4e2327cc3190ca97b44997f391640746590 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Wed, 14 Apr 2021 20:01:51 +0200 Subject: [PATCH 07/14] update C/C --- libmariadb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libmariadb b/libmariadb index fc431a035a2..d19c7c69269 160000 --- a/libmariadb +++ b/libmariadb @@ -1 +1 @@ -Subproject commit fc431a035a21ac1d4ef25d9d3cd8c4d7e64a8ee7 +Subproject commit d19c7c69269fdf4e2af8943dd86c12e4e1664afd From 7fa12b1e34d3d561baed9e7f2aacb0d6a3eb7062 Mon Sep 17 00:00:00 2001 From: Thirunarayanan Balathandayuthapani Date: Mon, 12 Apr 2021 21:18:14 +0530 Subject: [PATCH 08/14] MDEV-23026 purge fails with assert !rw_lock_own_flagged(lock, RW_LOCK_FLAG_X | RW_LOCK_FLAG_S) InnoDB purge thread locks the root page of clustered index while accessing the undo log records and later same thread tries to open the table, initialize statistics and tries to lock the clustered index root page while doing virtual column computation. Solution: ========= InnoDB should prevent statistics initialization when the table is being opened by purge thread --- storage/innobase/handler/ha_innodb.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc index fc876e6f753..b837aec396b 100644 --- a/storage/innobase/handler/ha_innodb.cc +++ b/storage/innobase/handler/ha_innodb.cc @@ -6261,8 +6261,10 @@ no_such_table: innobase_copy_frm_flags_from_table_share(ib_table, table->s); - /* No point to init any statistics if tablespace is still encrypted. */ - if (ib_table->is_readable()) { + /* No point to init any statistics if tablespace is still encrypted + or if table is being opened by background thread */ + if (THDVAR(thd, background_thread)) { + } else if (ib_table->is_readable()) { dict_stats_init(ib_table); } else { ib_table->stat_initialized = 1; From a3871cd2832dec43ca4ad6592646f58a7acf6630 Mon Sep 17 00:00:00 2001 From: Eugene Kosov Date: Wed, 31 Mar 2021 16:36:36 +0300 Subject: [PATCH 09/14] MDEV-22255 SIGABRT: Assertion `id' failed in trx_write_trx_id on INSERT | Assertion `id > 0' failed in trx_write_trx_id | Assertion `val > 0' failed in row_upd_index_entry_sys_field | Assertion `thr_get_trx(thr)->id || index->table->no_rollback()' failed. --- .../suite/innodb/r/temporary_table.result | 91 ++++++++++++++++ .../suite/innodb/t/temporary_table.test | 102 ++++++++++++++++++ storage/innobase/btr/btr0cur.cc | 13 ++- storage/innobase/include/trx0sys.ic | 1 - storage/innobase/pars/pars0pars.cc | 1 + storage/innobase/row/row0ins.cc | 8 +- storage/innobase/row/row0uins.cc | 2 +- storage/innobase/row/row0umod.cc | 2 +- storage/innobase/row/row0undo.cc | 2 +- storage/innobase/row/row0upd.cc | 2 +- 10 files changed, 212 insertions(+), 12 deletions(-) diff --git a/mysql-test/suite/innodb/r/temporary_table.result b/mysql-test/suite/innodb/r/temporary_table.result index 628bb648ead..490179fe6cb 100644 --- a/mysql-test/suite/innodb/r/temporary_table.result +++ b/mysql-test/suite/innodb/r/temporary_table.result @@ -663,3 +663,94 @@ DROP TABLE t1; END// call t1_proc; drop procedure t1_proc; +CREATE TABLE t (c INT) ENGINE=InnoDB; +INSERT INTO t VALUES(0); +CREATE TEMPORARY TABLE t2 (c INT) ENGINE=InnoDB; +START TRANSACTION READ ONLY; +INSERT INTO t2 SELECT * FROM t; +COMMIT; +DROP TABLE t, t2; +CREATE TEMPORARY TABLE t (c INT,c2 INT) ENGINE=InnoDB; +START TRANSACTION READ ONLY; +INSERT INTO t VALUES(0); +ERROR 21S01: Column count doesn't match value count at row 1 +SAVEPOINT s; +INSERT INTO t VALUES(0,0); +COMMIT; +DROP TABLE t; +CREATE TEMPORARY TABLE t (c INT,c2 INT) ENGINE=InnoDB; +START TRANSACTION READ ONLY; +INSERT INTO t VALUES(0); +ERROR 21S01: Column count doesn't match value count at row 1 +SAVEPOINT s; +INSERT INTO t VALUES(0,0); +ROLLBACK; +DROP TABLE t; +CREATE TEMPORARY TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1); +START TRANSACTION READ ONLY; +UPDATE t1 SET a= 2; +COMMIT; +DROP TABLE t1; +CREATE TEMPORARY TABLE t(c INT) ENGINE=InnoDB; +SET SESSION tx_read_only=TRUE; +LOCK TABLE test.t READ; +SELECT * FROM t; +c +INSERT INTO t VALUES(0xADC3); +SET SESSION tx_read_only=FALSE; +DROP TABLE t; +CREATE TEMPORARY TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1); +START TRANSACTION READ ONLY; +UPDATE t1 SET a= 2; +COMMIT; +DROP TABLE t1; +CREATE TEMPORARY TABLE t1 (a INT PRIMARY KEY, b int) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1, 1); +START TRANSACTION READ ONLY; +UPDATE t1 SET b= 2; +COMMIT; +DROP TABLE t1; +CREATE TEMPORARY TABLE t1 (a INT PRIMARY KEY, b int, c varchar(255)) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1, 1, repeat('a', 200)); +START TRANSACTION READ ONLY; +UPDATE t1 SET b= 2, c=repeat('a', 250); +COMMIT; +DROP TABLE t1; +CREATE TEMPORARY TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1); +START TRANSACTION READ ONLY; +UPDATE t1 SET a= 2; +ROLLBACK; +DROP TABLE t1; +CREATE TEMPORARY TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1); +START TRANSACTION READ ONLY; +DELETE FROM t1 WHERE a= 2; +COMMIT; +DROP TABLE t1; +CREATE TEMPORARY TABLE tmp (a INT) ENGINE=InnoDB; +INSERT INTO tmp () VALUES (),(); +SET TX_READ_ONLY= 1; +INSERT INTO tmp SELECT * FROM tmp; +SET TX_READ_ONLY= 0; +DROP TABLE tmp; +SET sql_mode=''; +SET GLOBAL tx_read_only=TRUE; +CREATE TEMPORARY TABLE t (c INT); +SET SESSION tx_read_only=DEFAULT; +INSERT INTO t VALUES(1); +INSERT INTO t SELECT * FROM t; +SET SESSION tx_read_only=FALSE; +SET GLOBAL tx_read_only=OFF; +DROP TABLE t; +CREATE TEMPORARY TABLE t(a INT); +SET SESSION tx_read_only=ON; +LOCK TABLE t READ; +SELECT COUNT(*)FROM t; +COUNT(*) +0 +INSERT INTO t VALUES (0); +SET SESSION tx_read_only=OFF; +DROP TABLE t; diff --git a/mysql-test/suite/innodb/t/temporary_table.test b/mysql-test/suite/innodb/t/temporary_table.test index 6856ca86323..42bd403d0be 100644 --- a/mysql-test/suite/innodb/t/temporary_table.test +++ b/mysql-test/suite/innodb/t/temporary_table.test @@ -493,3 +493,105 @@ delimiter ;// call t1_proc; drop procedure t1_proc; + + +CREATE TABLE t (c INT) ENGINE=InnoDB; +INSERT INTO t VALUES(0); +CREATE TEMPORARY TABLE t2 (c INT) ENGINE=InnoDB; +START TRANSACTION READ ONLY; +INSERT INTO t2 SELECT * FROM t; +COMMIT; +DROP TABLE t, t2; + +CREATE TEMPORARY TABLE t (c INT,c2 INT) ENGINE=InnoDB; +START TRANSACTION READ ONLY; +--error ER_WRONG_VALUE_COUNT_ON_ROW +INSERT INTO t VALUES(0); +SAVEPOINT s; +INSERT INTO t VALUES(0,0); +COMMIT; +DROP TABLE t; + +CREATE TEMPORARY TABLE t (c INT,c2 INT) ENGINE=InnoDB; +START TRANSACTION READ ONLY; +--error ER_WRONG_VALUE_COUNT_ON_ROW +INSERT INTO t VALUES(0); +SAVEPOINT s; +INSERT INTO t VALUES(0,0); +ROLLBACK; +DROP TABLE t; + +CREATE TEMPORARY TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1); +START TRANSACTION READ ONLY; +UPDATE t1 SET a= 2; +COMMIT; +DROP TABLE t1; + +CREATE TEMPORARY TABLE t(c INT) ENGINE=InnoDB; +SET SESSION tx_read_only=TRUE; +LOCK TABLE test.t READ; +SELECT * FROM t; +INSERT INTO t VALUES(0xADC3); +SET SESSION tx_read_only=FALSE; +DROP TABLE t; + +CREATE TEMPORARY TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1); +START TRANSACTION READ ONLY; +UPDATE t1 SET a= 2; +COMMIT; +DROP TABLE t1; + +CREATE TEMPORARY TABLE t1 (a INT PRIMARY KEY, b int) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1, 1); +START TRANSACTION READ ONLY; +UPDATE t1 SET b= 2; +COMMIT; +DROP TABLE t1; + +CREATE TEMPORARY TABLE t1 (a INT PRIMARY KEY, b int, c varchar(255)) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1, 1, repeat('a', 200)); +START TRANSACTION READ ONLY; +UPDATE t1 SET b= 2, c=repeat('a', 250); +COMMIT; +DROP TABLE t1; + +CREATE TEMPORARY TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1); +START TRANSACTION READ ONLY; +UPDATE t1 SET a= 2; +ROLLBACK; +DROP TABLE t1; + +CREATE TEMPORARY TABLE t1 (a INT PRIMARY KEY) ENGINE=InnoDB; +INSERT INTO t1 VALUES (1); +START TRANSACTION READ ONLY; +DELETE FROM t1 WHERE a= 2; +COMMIT; +DROP TABLE t1; + +CREATE TEMPORARY TABLE tmp (a INT) ENGINE=InnoDB; +INSERT INTO tmp () VALUES (),(); +SET TX_READ_ONLY= 1; +INSERT INTO tmp SELECT * FROM tmp; +SET TX_READ_ONLY= 0; +DROP TABLE tmp; + +SET sql_mode=''; +SET GLOBAL tx_read_only=TRUE; +CREATE TEMPORARY TABLE t (c INT); +SET SESSION tx_read_only=DEFAULT; +INSERT INTO t VALUES(1); +INSERT INTO t SELECT * FROM t; +SET SESSION tx_read_only=FALSE; +SET GLOBAL tx_read_only=OFF; +DROP TABLE t; + +CREATE TEMPORARY TABLE t(a INT); +SET SESSION tx_read_only=ON; +LOCK TABLE t READ; +SELECT COUNT(*)FROM t; +INSERT INTO t VALUES (0); +SET SESSION tx_read_only=OFF; +DROP TABLE t; diff --git a/storage/innobase/btr/btr0cur.cc b/storage/innobase/btr/btr0cur.cc index 8f2acdb35bd..3bbddb79a0c 100644 --- a/storage/innobase/btr/btr0cur.cc +++ b/storage/innobase/btr/btr0cur.cc @@ -3242,7 +3242,8 @@ fail_err: ut_ad(thr->graph->trx->id == trx_read_trx_id( static_cast( - trx_id->data))); + trx_id->data)) + || index->table->is_temporary()); } } #endif @@ -3844,7 +3845,8 @@ btr_cur_update_in_place( index = cursor->index; ut_ad(rec_offs_validate(rec, index, offsets)); ut_ad(!!page_rec_is_comp(rec) == dict_table_is_comp(index->table)); - ut_ad(trx_id > 0 || (flags & BTR_KEEP_SYS_FLAG)); + ut_ad(trx_id > 0 || (flags & BTR_KEEP_SYS_FLAG) + || index->table->is_temporary()); /* The insert buffer tree should never be updated in place. */ ut_ad(!dict_index_is_ibuf(index)); ut_ad(dict_index_is_online_ddl(index) == !!(flags & BTR_CREATE_FLAG) @@ -4017,7 +4019,8 @@ btr_cur_optimistic_update( page = buf_block_get_frame(block); rec = btr_cur_get_rec(cursor); index = cursor->index; - ut_ad(trx_id > 0 || (flags & BTR_KEEP_SYS_FLAG)); + ut_ad(trx_id > 0 || (flags & BTR_KEEP_SYS_FLAG) + || index->table->is_temporary()); ut_ad(!!page_rec_is_comp(rec) == dict_table_is_comp(index->table)); ut_ad(mtr_is_block_fix(mtr, block, MTR_MEMO_PAGE_X_FIX, index->table)); /* This is intended only for leaf page updates */ @@ -4354,8 +4357,8 @@ btr_cur_pessimistic_update( ut_ad(!page_zip || !dict_table_is_temporary(index->table)); /* The insert buffer tree should never be updated in place. */ ut_ad(!dict_index_is_ibuf(index)); - ut_ad(trx_id > 0 - || (flags & BTR_KEEP_SYS_FLAG)); + ut_ad(trx_id > 0 || (flags & BTR_KEEP_SYS_FLAG) + || index->table->is_temporary()); ut_ad(dict_index_is_online_ddl(index) == !!(flags & BTR_CREATE_FLAG) || dict_index_is_clust(index)); ut_ad(thr_get_trx(thr)->id == trx_id diff --git a/storage/innobase/include/trx0sys.ic b/storage/innobase/include/trx0sys.ic index 0a4d583671f..c85695630f0 100644 --- a/storage/innobase/include/trx0sys.ic +++ b/storage/innobase/include/trx0sys.ic @@ -185,7 +185,6 @@ trx_write_trx_id( #if DATA_TRX_ID_LEN != 6 # error "DATA_TRX_ID_LEN != 6" #endif - ut_ad(id > 0); mach_write_to_6(ptr, id); } diff --git a/storage/innobase/pars/pars0pars.cc b/storage/innobase/pars/pars0pars.cc index 280c4ee1815..991762673aa 100644 --- a/storage/innobase/pars/pars0pars.cc +++ b/storage/innobase/pars/pars0pars.cc @@ -1219,6 +1219,7 @@ pars_update_statement( sel_node->row_lock_mode = LOCK_X; } else { node->has_clust_rec_x_lock = sel_node->set_x_locks; + ut_ad(node->has_clust_rec_x_lock); } ut_a(sel_node->n_tables == 1); diff --git a/storage/innobase/row/row0ins.cc b/storage/innobase/row/row0ins.cc index 635e7f659eb..4dc9c66a536 100644 --- a/storage/innobase/row/row0ins.cc +++ b/storage/innobase/row/row0ins.cc @@ -3250,7 +3250,7 @@ row_ins_index_entry( dtuple_t* entry, /*!< in/out: index entry to insert */ que_thr_t* thr) /*!< in: query thread */ { - ut_ad(thr_get_trx(thr)->id != 0); + ut_ad(thr_get_trx(thr)->id != 0 || index->table->is_temporary()); DBUG_EXECUTE_IF("row_ins_index_entry_timeout", { DBUG_SET("-d,row_ins_index_entry_timeout"); @@ -3613,12 +3613,16 @@ row_ins_step( table during the search operation, and there is no need to set it again here. But we must write trx->id to node->sys_buf. */ - trx_write_trx_id(&node->sys_buf[DATA_ROW_ID_LEN], trx->id); + trx_write_trx_id(&node->sys_buf[DATA_TRX_ID_LEN], trx->id); if (node->state == INS_NODE_SET_IX_LOCK) { node->state = INS_NODE_ALLOC_ROW_ID; + if (node->table->is_temporary()) { + node->trx_id = trx->id; + } + /* It may be that the current session has not yet started its transaction, or it has been committed: */ diff --git a/storage/innobase/row/row0uins.cc b/storage/innobase/row/row0uins.cc index 915d4b99d16..8c944189de6 100644 --- a/storage/innobase/row/row0uins.cc +++ b/storage/innobase/row/row0uins.cc @@ -106,7 +106,7 @@ row_undo_ins_remove_clust_rec( btr_cur = btr_pcur_get_btr_cur(&node->pcur); ut_ad(rec_get_trx_id(btr_cur_get_rec(btr_cur), btr_cur->index) - == node->trx->id); + == node->trx->id || node->table->is_temporary()); ut_ad(!rec_get_deleted_flag( btr_cur_get_rec(btr_cur), dict_table_is_comp(btr_cur->index->table))); diff --git a/storage/innobase/row/row0umod.cc b/storage/innobase/row/row0umod.cc index 80d90f40379..d207aa5b9bc 100644 --- a/storage/innobase/row/row0umod.cc +++ b/storage/innobase/row/row0umod.cc @@ -109,7 +109,7 @@ row_undo_mod_clust_low( ut_ad(success); ut_ad(rec_get_trx_id(btr_cur_get_rec(btr_cur), btr_cur_get_index(btr_cur)) - == thr_get_trx(thr)->id); + == thr_get_trx(thr)->id || node->index->table->is_temporary()); if (mode != BTR_MODIFY_LEAF && dict_index_is_online_ddl(btr_cur_get_index(btr_cur))) { diff --git a/storage/innobase/row/row0undo.cc b/storage/innobase/row/row0undo.cc index b65b173fedb..e1978cfb297 100644 --- a/storage/innobase/row/row0undo.cc +++ b/storage/innobase/row/row0undo.cc @@ -194,7 +194,7 @@ row_undo_search_clust_to_pcur( if (found) { ut_ad(row_get_rec_trx_id(rec, clust_index, offsets) - == node->trx->id); + == node->trx->id || node->table->is_temporary()); if (dict_table_get_format(node->table) >= UNIV_FORMAT_B) { /* In DYNAMIC or COMPRESSED format, there is diff --git a/storage/innobase/row/row0upd.cc b/storage/innobase/row/row0upd.cc index 4b81d1478b0..429282906df 100644 --- a/storage/innobase/row/row0upd.cc +++ b/storage/innobase/row/row0upd.cc @@ -549,7 +549,7 @@ row_upd_index_entry_sys_field( field = static_cast(dfield_get_data(dfield)); if (type == DATA_TRX_ID) { - ut_ad(val > 0); + ut_ad(val > 0 || index->table->is_temporary()); trx_write_trx_id(field, val); } else { ut_ad(type == DATA_ROLL_PTR); From ab5dc625458c2fd63489292117d4420610a79a9d Mon Sep 17 00:00:00 2001 From: Sergei Petrunia Date: Tue, 13 Apr 2021 20:32:16 +0300 Subject: [PATCH 10/14] MDEV-25407: EXISTS subquery with correlation in ON expression crashes Make Item_subselect::walk() walk the ON expressions, too. --- mysql-test/r/subselect_exists2in.result | 18 +++++++++++++++ mysql-test/t/subselect_exists2in.test | 23 +++++++++++++++++++ sql/item_subselect.cc | 30 ++++++++++++++++++++++++- 3 files changed, 70 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/subselect_exists2in.result b/mysql-test/r/subselect_exists2in.result index de4e428e462..ff5605575ba 100644 --- a/mysql-test/r/subselect_exists2in.result +++ b/mysql-test/r/subselect_exists2in.result @@ -1099,4 +1099,22 @@ U5.`storage_target_id` = V0.`id` ); id drop table t1,t2,t3; +# +# MDEV-25407: EXISTS subquery with correlation in ON expression crashes +# +create table t10(a int primary key); +insert into t10 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); +create table t11(a int primary key); +insert into t11 select a.a + b.a* 10 + c.a * 100 from t10 a, t10 b, t10 c; +create table t1 (a int, b int); +insert into t1 select a,a from t10; +create table t2 (a int, b int); +insert into t2 select a,a from t11; +create table t3 as select * from t2; +explain select * from t1 where exists (select t2.a from t2 left join t3 on (t3.b=t1.b) where t2.a=t1.a); +id select_type table type possible_keys key key_len ref rows Extra +1 PRIMARY t1 ALL NULL NULL NULL NULL 10 +1 PRIMARY t2 ALL NULL NULL NULL NULL 1000 Using where; Start temporary; Using join buffer (flat, BNL join) +1 PRIMARY t3 ALL NULL NULL NULL NULL 1000 Using where; End temporary; Using join buffer (incremental, BNL join) +drop table t1, t2, t3, t10, t11; set optimizer_switch=default; diff --git a/mysql-test/t/subselect_exists2in.test b/mysql-test/t/subselect_exists2in.test index e27ce57038b..e70d643138b 100644 --- a/mysql-test/t/subselect_exists2in.test +++ b/mysql-test/t/subselect_exists2in.test @@ -941,5 +941,28 @@ WHERE ( drop table t1,t2,t3; +--echo # +--echo # MDEV-25407: EXISTS subquery with correlation in ON expression crashes +--echo # +create table t10(a int primary key); +insert into t10 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); + +create table t11(a int primary key); +insert into t11 select a.a + b.a* 10 + c.a * 100 from t10 a, t10 b, t10 c; + +create table t1 (a int, b int); +insert into t1 select a,a from t10; + +create table t2 (a int, b int); +insert into t2 select a,a from t11; + +create table t3 as select * from t2; + + +explain select * from t1 where exists (select t2.a from t2 left join t3 on (t3.b=t1.b) where t2.a=t1.a); + +drop table t1, t2, t3, t10, t11; + + #restore defaults set optimizer_switch=default; diff --git a/sql/item_subselect.cc b/sql/item_subselect.cc index 4b8f118ca43..ed8e5e900a2 100644 --- a/sql/item_subselect.cc +++ b/sql/item_subselect.cc @@ -664,6 +664,31 @@ bool Item_subselect::is_expensive() } +static +int walk_items_for_table_list(Item_processor processor, + bool walk_subquery, void *argument, + List& join_list) +{ + List_iterator li(join_list); + int res; + while (TABLE_LIST *table= li++) + { + if (table->on_expr) + { + if ((res= table->on_expr->walk(processor, walk_subquery, argument))) + return res; + } + if (table->nested_join) + { + if ((res= walk_items_for_table_list(processor, walk_subquery, argument, + table->nested_join->join_list))) + return res; + } + } + return 0; +} + + bool Item_subselect::walk(Item_processor processor, bool walk_subquery, void *argument) { @@ -695,7 +720,10 @@ bool Item_subselect::walk(Item_processor processor, bool walk_subquery, if (lex->having && (lex->having)->walk(processor, walk_subquery, argument)) return 1; - /* TODO: why does this walk WHERE/HAVING but not ON expressions of outer joins? */ + + if (walk_items_for_table_list(processor, walk_subquery, argument, + *lex->join_list)) + return 1; while ((item=li++)) { From 73bf62469e0124a088bfddd838a68714ce7d79ea Mon Sep 17 00:00:00 2001 From: Rainer Orth Date: Fri, 20 Nov 2020 16:55:03 +1100 Subject: [PATCH 11/14] MDEV-15064: IO_CACHE mysys read_pos, not libmaria rc_pos It seems some overly tolerant compilers (gcc) allow the structure of IO_CACHE that is defined differently in libmaria to have members equalivance to the iocache in mysys. More strict Solaris compilers recognise that rc_pos really isn't a structure member and won't compile. --- mysys/mf_iocache.c | 2 +- sql/mf_iocache.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mysys/mf_iocache.c b/mysys/mf_iocache.c index e09c7f930c8..8ade76e922e 100644 --- a/mysys/mf_iocache.c +++ b/mysys/mf_iocache.c @@ -1603,7 +1603,7 @@ int _my_b_async_read(IO_CACHE *info, uchar *Buffer, size_t Count) Buffer+=length; Count-=length; left_length+=length; - info->read_end=info->rc_pos+read_length; + info->read_end=info->read_pos+read_length; info->read_pos+=length; } else diff --git a/sql/mf_iocache.cc b/sql/mf_iocache.cc index 8533c9037aa..e4dc3d44a38 100644 --- a/sql/mf_iocache.cc +++ b/sql/mf_iocache.cc @@ -26,7 +26,7 @@ Used instead of FILE when reading or writing whole files. This will make mf_rec_cache obsolete. One can change info->pos_in_file to a higher value to skip bytes in file if - also info->rc_pos is set to info->rc_end. + also info->read_pos is set to info->read_end. If called through open_cached_file(), then the temporary file will only be created if a write exeeds the file buffer or if one calls flush_io_cache(). From 635b5ce355473167af64e116e403a51bfaed184b Mon Sep 17 00:00:00 2001 From: Igor Babaev Date: Fri, 16 Apr 2021 09:53:16 -0700 Subject: [PATCH 12/14] MDEV-25362 Incorrect name resolution for subqueries in ON expressions This patch sets the proper name resolution context for outer references used in a subquery from an ON clause. Usually this context is more narrow than the name resolution context of the parent select that were used before this fix. This fix revealed another problem that concerned ON expressions used in from clauses of specifications of derived tables / views / CTEs. The name resolution outer context for such ON expression must be set to NULL to prevent name resolution beyond the derived table where it is used. The solution to resolve this problem applied in sql_derived.cc was provided by Sergei Petrunia . The change in sql_parse.cc is not good for 10.4+. A corresponding diff for 10.4+ will be provided in JIRA entry for this bug. Approved by Oleksandr Byelkin --- mysql-test/r/join_outer.result | 40 +++++++++++++++++++++++ mysql-test/r/join_outer_jcl6.result | 40 +++++++++++++++++++++++ mysql-test/t/join_outer.test | 50 +++++++++++++++++++++++++++++ sql/sql_derived.cc | 31 ++++++++++++++++++ sql/sql_parse.cc | 4 ++- 5 files changed, 164 insertions(+), 1 deletion(-) diff --git a/mysql-test/r/join_outer.result b/mysql-test/r/join_outer.result index fdc36b74f63..1995640638a 100644 --- a/mysql-test/r/join_outer.result +++ b/mysql-test/r/join_outer.result @@ -2682,4 +2682,44 @@ id timestamp modifiedBy id REV REVTYPE profile_id id REV person_id id REV 12 1294650860266 u62C^Kzx3wH8 8 12 2 2 2 117548 300006 300006 97697 DROP TABLE t1,t2,t3,t4; # end of 10.1 tests +# +# MDEV-25362: name resolution for subqueries in ON expressions +# +create table t1 (a int, b int); +create table t2 (c int, d int); +create table t3 (e int, f int); +create table t4 (g int, h int); +explain +select * +from +t1 left join +(t2 +join +t3 on +(t3.f=t1.a) +) on (t2.c=t1.a ); +ERROR 42S22: Unknown column 't1.a' in 'on clause' +explain +select * +from +t1 left join +(t2 +join +t3 on +(t3.f=(select max(g) from t4 where t4.h=t1.a)) +) on (t2.c=t1.a ); +ERROR 42S22: Unknown column 't1.a' in 'where clause' +drop table t1,t2,t3,t4; +create table t1 (a int); +insert into t1 values (1),(2); +create table t2 (b int); +insert into t2 values (1),(2); +create table t3 (c int); +insert into t3 values (1),(2); +select * from ( select * from t1 left join t2 +on b in (select x from t3 as sq1) +) as sq2; +ERROR 42S22: Unknown column 'x' in 'field list' +drop table t1,t2,t3; +# end of 10.2 tests SET optimizer_switch=@org_optimizer_switch; diff --git a/mysql-test/r/join_outer_jcl6.result b/mysql-test/r/join_outer_jcl6.result index 6a6b1007866..58df4203c17 100644 --- a/mysql-test/r/join_outer_jcl6.result +++ b/mysql-test/r/join_outer_jcl6.result @@ -2690,6 +2690,46 @@ id timestamp modifiedBy id REV REVTYPE profile_id id REV person_id id REV 12 1294650860266 u62C^Kzx3wH8 8 12 2 2 2 117548 300006 300006 97697 DROP TABLE t1,t2,t3,t4; # end of 10.1 tests +# +# MDEV-25362: name resolution for subqueries in ON expressions +# +create table t1 (a int, b int); +create table t2 (c int, d int); +create table t3 (e int, f int); +create table t4 (g int, h int); +explain +select * +from +t1 left join +(t2 +join +t3 on +(t3.f=t1.a) +) on (t2.c=t1.a ); +ERROR 42S22: Unknown column 't1.a' in 'on clause' +explain +select * +from +t1 left join +(t2 +join +t3 on +(t3.f=(select max(g) from t4 where t4.h=t1.a)) +) on (t2.c=t1.a ); +ERROR 42S22: Unknown column 't1.a' in 'where clause' +drop table t1,t2,t3,t4; +create table t1 (a int); +insert into t1 values (1),(2); +create table t2 (b int); +insert into t2 values (1),(2); +create table t3 (c int); +insert into t3 values (1),(2); +select * from ( select * from t1 left join t2 +on b in (select x from t3 as sq1) +) as sq2; +ERROR 42S22: Unknown column 'x' in 'field list' +drop table t1,t2,t3; +# end of 10.2 tests SET optimizer_switch=@org_optimizer_switch; set join_cache_level=default; set @@optimizer_switch=@save_optimizer_switch_jcl6; diff --git a/mysql-test/t/join_outer.test b/mysql-test/t/join_outer.test index c5b2c985ff7..9ad2c48bfca 100644 --- a/mysql-test/t/join_outer.test +++ b/mysql-test/t/join_outer.test @@ -2190,4 +2190,54 @@ DROP TABLE t1,t2,t3,t4; --echo # end of 10.1 tests +--echo # +--echo # MDEV-25362: name resolution for subqueries in ON expressions +--echo # + +create table t1 (a int, b int); +create table t2 (c int, d int); +create table t3 (e int, f int); +create table t4 (g int, h int); + +--error ER_BAD_FIELD_ERROR +explain +select * +from + t1 left join + (t2 + join + t3 on + (t3.f=t1.a) + ) on (t2.c=t1.a ); + +# This must produce an error: +--error ER_BAD_FIELD_ERROR +explain +select * +from + t1 left join + (t2 + join + t3 on + (t3.f=(select max(g) from t4 where t4.h=t1.a)) + ) on (t2.c=t1.a ); + +drop table t1,t2,t3,t4; + +create table t1 (a int); +insert into t1 values (1),(2); +create table t2 (b int); +insert into t2 values (1),(2); +create table t3 (c int); +insert into t3 values (1),(2); + +--error ER_BAD_FIELD_ERROR +select * from ( select * from t1 left join t2 + on b in (select x from t3 as sq1) + ) as sq2; + +drop table t1,t2,t3; + +--echo # end of 10.2 tests + SET optimizer_switch=@org_optimizer_switch; diff --git a/sql/sql_derived.cc b/sql/sql_derived.cc index be5905da683..5a85b7ea7e3 100644 --- a/sql/sql_derived.cc +++ b/sql/sql_derived.cc @@ -562,6 +562,32 @@ bool mysql_derived_init(THD *thd, LEX *lex, TABLE_LIST *derived) } +/* + @brief + Prevent name resolution out of context of ON expressions in derived tables + + @param + join_list list of tables used in from list of a derived + + @details + The function sets the Name_resolution_context::outer_context to NULL + for all ON expressions contexts in the given join list. It does this + recursively for all nested joins the list contains. +*/ + +static void nullify_outer_context_for_on_clauses(List& join_list) +{ + List_iterator li(join_list); + while (TABLE_LIST *table= li++) + { + if (table->on_context) + table->on_context->outer_context= NULL; + if (table->nested_join) + nullify_outer_context_for_on_clauses(table->nested_join->join_list); + } +} + + /* Create temporary table structure (but do not fill it) @@ -695,7 +721,12 @@ bool mysql_derived_prepare(THD *thd, LEX *lex, TABLE_LIST *derived) /* prevent name resolving out of derived table */ for (SELECT_LEX *sl= first_select; sl; sl= sl->next_select()) { + // Prevent it for the WHERE clause sl->context.outer_context= 0; + + // And for ON clauses, if there are any + nullify_outer_context_for_on_clauses(*sl->join_list); + if (!derived->is_with_table_recursive_reference() || (!derived->with->with_anchor && !derived->with->is_with_prepared_anchor())) diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index 573df24cb33..9436e111043 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -7418,6 +7418,7 @@ mysql_new_select(LEX *lex, bool move_down) DBUG_RETURN(1); select_lex->select_number= ++thd->lex->stmt_lex->current_select_number; select_lex->parent_lex= lex; /* Used in init_query. */ + Name_resolution_context *curr_context= lex->context_stack.head(); select_lex->init_query(); select_lex->init_select(); lex->nest_level++; @@ -7448,7 +7449,8 @@ mysql_new_select(LEX *lex, bool move_down) By default we assume that it is usual subselect and we have outer name resolution context, if no we will assign it to 0 later */ - select_lex->context.outer_context= &select_lex->outer_select()->context; + + select_lex->context.outer_context= curr_context; } else { From 562bbf5212412437273a469fc59138a939f123cd Mon Sep 17 00:00:00 2001 From: Aleksey Midenkov Date: Tue, 13 Apr 2021 23:56:49 +0300 Subject: [PATCH 13/14] MDEV-25327 Unexpected ER_DUP_ENTRY upon dropping PK column from system-versioned table When dropped all user key-parts we also drop key-parts of implicit system fields. --- mysql-test/suite/versioning/r/alter.result | 17 +++++++++++++++++ mysql-test/suite/versioning/t/alter.test | 22 ++++++++++++++++++++++ sql/sql_table.cc | 12 ++++++++++-- 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/mysql-test/suite/versioning/r/alter.result b/mysql-test/suite/versioning/r/alter.result index 3666a5ddcb1..5092adc2b11 100644 --- a/mysql-test/suite/versioning/r/alter.result +++ b/mysql-test/suite/versioning/r/alter.result @@ -742,3 +742,20 @@ create or replace table t1 (x int); alter table t1 add column y timestamp(6) as row start; ERROR HY000: Table `t1` is not system-versioned drop table t1; +# +# MDEV-25327 Unexpected ER_DUP_ENTRY upon dropping PK column from system-versioned table +# +create table t1 (pk int, a int, primary key (pk), key (a)) +with system versioning; +insert into t1 values (1, 1), (2, 2); +delete from t1; +set system_versioning_alter_history= keep; +alter table t1 drop pk; +drop table t1; +create table t1 (pk int, a int, primary key (pk), key (a)) +with system versioning; +insert into t1 values (1, 2), (2, 8), (3, 4), (4, 4), (5, 0); +delete from t1; +set system_versioning_alter_history= keep; +alter ignore table t1 drop pk; +drop table t1; diff --git a/mysql-test/suite/versioning/t/alter.test b/mysql-test/suite/versioning/t/alter.test index 91bddb5aaeb..3ce87817e06 100644 --- a/mysql-test/suite/versioning/t/alter.test +++ b/mysql-test/suite/versioning/t/alter.test @@ -630,3 +630,25 @@ create or replace table t1 (x int); alter table t1 add column y timestamp(6) as row start; # cleanup drop table t1; + + +--echo # +--echo # MDEV-25327 Unexpected ER_DUP_ENTRY upon dropping PK column from system-versioned table +--echo # +create table t1 (pk int, a int, primary key (pk), key (a)) +with system versioning; +insert into t1 values (1, 1), (2, 2); +delete from t1; +set system_versioning_alter_history= keep; +alter table t1 drop pk; +# cleanup +drop table t1; + +create table t1 (pk int, a int, primary key (pk), key (a)) +with system versioning; +insert into t1 values (1, 2), (2, 8), (3, 4), (4, 4), (5, 0); +delete from t1; +set system_versioning_alter_history= keep; +alter ignore table t1 drop pk; +# cleanup +drop table t1; diff --git a/sql/sql_table.cc b/sql/sql_table.cc index 01812e039be..64336ed02af 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -8451,7 +8451,7 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, key_parts.push_back(new (thd->mem_root) Key_part_spec(&cfield->field_name, key_part_length, true), thd->mem_root); - if (cfield->invisible < INVISIBLE_SYSTEM) + if (!(cfield->invisible == INVISIBLE_SYSTEM && cfield->vers_sys_field())) user_keyparts= true; } if (table->s->tmp_table == NO_TMP_TABLE) @@ -8463,6 +8463,14 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, (void) delete_statistics_for_index(thd, table, key_info, TRUE); } + if (!user_keyparts && key_parts.elements) + { + /* + If we dropped all user key-parts we also drop implicit system fields. + */ + key_parts.empty(); + } + if (key_parts.elements) { KEY_CREATE_INFO key_create_info; @@ -8496,7 +8504,7 @@ mysql_prepare_alter_table(THD *thd, TABLE *table, key_type= Key::PRIMARY; else key_type= Key::UNIQUE; - if (dropped_key_part && user_keyparts) + if (dropped_key_part) { my_error(ER_KEY_COLUMN_DOES_NOT_EXITS, MYF(0), dropped_key_part); goto err; From 72432ec7b3e6c4d87d86fcd00acdff1c03f402d2 Mon Sep 17 00:00:00 2001 From: Aditya A Date: Wed, 24 Feb 2021 07:49:37 +0530 Subject: [PATCH 14/14] Bug #32032897 DEADLOCKING WAIT GRAPH ON BUSY SERVER PROBLEM ------- 1. The customer had presented a stack which had many threads waiting on multiple mutexes like LOCK_Status, srv_innodb_monitor_mutex, ibuf_mutex etc. 2. The root cause was that the AHI latch was held in S (shared) mode by the a thread which was doing a truncate of a large table . 3. There was another thread which was trying to acquire the AHI latch in X (exclusive) mode 4. With our lock implementation any thread requesting a X lock ,blocks rest of the threads requesting S(shared) locks,this caused many threads to wait for this shared lock. 5. The main reason why we hold the latches in truncate is to avoid disabling of AHI during truncate FIX --- storage/innobase/fil/fil0fil.cc | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/storage/innobase/fil/fil0fil.cc b/storage/innobase/fil/fil0fil.cc index 659cfa26033..39e7507373f 100644 --- a/storage/innobase/fil/fil0fil.cc +++ b/storage/innobase/fil/fil0fil.cc @@ -1,6 +1,6 @@ /***************************************************************************** -Copyright (c) 1995, 2017, Oracle and/or its affiliates. All Rights Reserved. +Copyright (c) 1995, 2021, Oracle and/or its affiliates. All Rights Reserved. Copyright (c) 2014, 2020, MariaDB Corporation. This program is free software; you can redistribute it and/or modify it under @@ -3137,11 +3137,7 @@ fil_reinit_space_header_for_table( row_mysql_unlock_data_dictionary(trx); DEBUG_SYNC_C("buffer_pool_scan"); - /* Lock the search latch in shared mode to prevent user - from disabling AHI during the scan */ - btr_search_s_lock_all(); buf_LRU_flush_or_remove_pages(id, NULL); - btr_search_s_unlock_all(); row_mysql_lock_data_dictionary(trx);