[MDEV-22118] handler::update_auto_increment(): Assertion `nr != 0' failed. | SIGABRT in handler::update_auto_increment Created: 2020-04-02  Updated: 2021-10-24  Resolved: 2021-10-24

Status: Closed
Project: MariaDB Server
Component/s: Data Manipulation - Insert
Affects Version/s: 10.2.0, 10.2.1, 10.2.2, 10.2, 10.3, 10.4, 10.5, 10.6
Fix Version/s: N/A

Type: Bug Priority: Critical
Reporter: Roel Van de Paar Assignee: Alexey Botchkov
Resolution: Duplicate Votes: 0
Labels: affects-tests, not-10.1

Issue Links:
Duplicate
is duplicated by MDEV-22711 Assertion `nr != 0' failed in handler... Closed

 Description   

# mysqld options required for replay:  --sql_mode= 
CREATE TABLE t (c INT AUTO_INCREMENT KEY);
SET @@SESSION.insert_id=-0;  # Or -1, -2 etc.
INSERT INTO t VALUES(0);

Leads to:

mysqld: /data/git/10.5_dbg/sql/handler.cc:3541: int handler::update_auto_increment(): Assertion `nr != 0' failed.

Core was generated by `/data/MD180320-mariadb-10.5.2-linux-x86_64-dbg/bin/mysqld --no-defaults --core-'.
Program terminated with signal SIGABRT, Aborted.
#0  __pthread_kill (threadid=<optimized out>, signo=signo@entry=6)
    at ../sysdeps/unix/sysv/linux/pthread_kill.c:57
[Current thread is 1 (Thread 0x7fdd5b114700 (LWP 4790))]
(gdb) bt
#0  __pthread_kill (threadid=<optimized out>, signo=signo@entry=6) at ../sysdeps/unix/sysv/linux/pthread_kill.c:57
#1  0x00005621b7f597d4 in my_write_core (sig=sig@entry=6) at /data/git/10.5_dbg/mysys/stacktrace.c:518
#2  0x00005621b7702b5f in handle_fatal_signal (sig=6) at /data/git/10.5_dbg/sql/signal_handler.cc:325
#3  <signal handler called>
#4  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#5  0x00007fdd59858801 in __GI_abort () at abort.c:79
#6  0x00007fdd5984839a in __assert_fail_base (fmt=0x7fdd599cf7d8 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=assertion@entry=0x5621b826048b "nr != 0", file=file@entry=0x5621b82609e0 "/data/git/10.5_dbg/sql/handler.cc", line=line@entry=3541, function=function@entry=0x5621b8263fc0 <handler::update_auto_increment()::__PRETTY_FUNCTION__> "int handler::update_auto_increment()") at assert.c:92
#7  0x00007fdd59848412 in __GI___assert_fail (assertion=assertion@entry=0x5621b826048b "nr != 0", file=file@entry=0x5621b82609e0 "/data/git/10.5_dbg/sql/handler.cc", line=line@entry=3541, function=function@entry=0x5621b8263fc0 <handler::update_auto_increment()::__PRETTY_FUNCTION__> "int handler::update_auto_increment()") at assert.c:101
#8  0x00005621b770f10a in handler::update_auto_increment (this=this@entry=0x7fdd3182eca0) at /data/git/10.5_dbg/sql/handler.cc:3541
#9  0x00005621b7ad1c32 in ha_innobase::write_row (this=0x7fdd3182eca0, record=0x7fdd318491a8 "\377") at /data/git/10.5_dbg/storage/innobase/handler/ha_innodb.cc:7710
#10 0x00005621b77160b4 in handler::ha_write_row (this=0x7fdd3182eca0, buf=0x7fdd318491a8 "\377") at /data/git/10.5_dbg/sql/handler.cc:6798
#11 0x00005621b741a9cd in write_record (thd=thd@entry=0x7fdd31815088, table=table@entry=0x7fdd318ee088, info=info@entry=0x7fdd5b112a80, sink=sink@entry=0x0) at /data/git/10.5_dbg/sql/sql_insert.cc:2055
#12 0x00005621b74258bf in mysql_insert (thd=thd@entry=0x7fdd31815088, table_list=0x7fdd31874178, fields=..., values_list=..., update_fields=..., update_values=..., duplic=DUP_ERROR, ignore=false, result=0x0) at /data/git/10.5_dbg/sql/sql_insert.cc:1080
#13 0x00005621b745cc50 in mysql_execute_command (thd=thd@entry=0x7fdd31815088) at /data/git/10.5_dbg/sql/sql_parse.cc:4507
#14 0x00005621b74687a5 in mysql_parse (thd=thd@entry=0x7fdd31815088, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x7fdd5b113450, is_com_multi=is_com_multi@entry=false, is_next_command=is_next_command@entry=false) at /data/git/10.5_dbg/sql/sql_parse.cc:7926
#15 0x00005621b7454664 in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x7fdd31815088, packet=packet@entry=0x7fdd31867089 "INSERT INTO t VALUES(0)", packet_length=packet_length@entry=23, is_com_multi=is_com_multi@entry=false, is_next_command=is_next_command@entry=false) at /data/git/10.5_dbg/sql/sql_parse.cc:1839
#16 0x00005621b7452eaf in do_command (thd=0x7fdd31815088) at /data/git/10.5_dbg/sql/sql_parse.cc:1358
#17 0x00005621b75aca09 in do_handle_one_connection (connect=<optimized out>, connect@entry=0x7fdd3762b3a8, put_in_cache=put_in_cache@entry=true) at /data/git/10.5_dbg/sql/sql_connect.cc:1422
#18 0x00005621b75acd38 in handle_one_connection (arg=arg@entry=0x7fdd3762b3a8) at /data/git/10.5_dbg/sql/sql_connect.cc:1319
#19 0x00005621b7a09cfc in pfs_spawn_thread (arg=0x7fdd58c45888) at /data/git/10.5_dbg/storage/perfschema/pfs.cc:2201
#20 0x00007fdd5a53b6db in start_thread (arg=0x7fdd5b114700) at pthread_create.c:463
#21 0x00007fdd5993988f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Bug confirmed present in:
MariaDB: 10.2.32 (dbg), 10.3.23 (dbg), 10.4.13 (dbg), 10.5.2 (dbg)

Bug confirmed not present in:
MariaDB: 10.1.45 (dbg), 10.1.45 (opt), 10.2.32 (opt), 10.3.23 (opt), 10.4.13 (opt), 10.5.2 (opt)
MySQL: 5.5.62 (dbg), 5.5.62 (opt), 5.6.47 (dbg), 5.6.47 (opt), 5.7.29 (dbg), 5.7.29 (opt), 8.0.19 (dbg), 8.0.19 (opt)



 Comments   
Comment by Marko Mäkelä [ 2020-04-02 ]

I suspect that this could have something to do with MDEV-6076. But, I was unable to compile that old 10.2 due to errors in mysys_ssl/my_md5.cc, presumably due to too new OpenSSL or YaSSL library being available.

git checkout 8777458a6eb73ac1d7d864ebac390ea7039e21c1~

I would have tested the parent of the MDEV-6076 commit, and then the MDEV-6076 commit itself.

Comment by Marko Mäkelä [ 2020-04-02 ]

I tried a ‘transplant build’ with the parent InnoDB of MDEV-6076 into the latest 10.2, and I can repeat the crash with that. So, I do not think that MDEV-6076 is to blame.

git checkout 05e4a87c8b074910f4bbf2b6a666a670764c4f89
git checkout 8777458a6eb73ac1d7d864ebac390ea7039e21c1~ storage/innobase/
git checkout HEAD storage/innobase/innodb.cmake storage/innobase/CMakeLists.txt

I had to patch the code to compile:

diff --git a/storage/innobase/CMakeLists.txt b/storage/innobase/CMakeLists.txt
index 1b5345cbddc..6e59f736345 100644
--- a/storage/innobase/CMakeLists.txt
+++ b/storage/innobase/CMakeLists.txt
@@ -21,6 +21,8 @@
 INCLUDE(innodb.cmake)
 
 SET(INNOBASE_SOURCES
+        api/api0api.cc
+	api/api0misc.cc
 	btr/btr0btr.cc
 	btr/btr0bulk.cc
 	btr/btr0cur.cc
@@ -56,6 +58,7 @@ SET(INNOBASE_SOURCES
 	fsp/fsp0file.cc
 	fsp/fsp0space.cc
 	fsp/fsp0sysspace.cc
+	fut/fut0fut.cc
 	fut/fut0lst.cc
 	ha/ha0ha.cc
 	ha/ha0storage.cc
@@ -137,6 +140,7 @@ SET(INNOBASE_SOURCES
 	trx/trx0sys.cc
 	trx/trx0trx.cc
 	trx/trx0undo.cc
+	usr/usr0sess.cc
 	ut/ut0crc32.cc
 	ut/ut0dbg.cc
 	ut/ut0list.cc
@@ -144,6 +148,7 @@ SET(INNOBASE_SOURCES
 	ut/ut0new.cc
 	ut/ut0rbt.cc
 	ut/ut0rnd.cc
+	ut/ut0timer.cc
 	ut/ut0ut.cc
 	ut/ut0vec.cc
 	ut/ut0wqueue.cc)
diff --git a/storage/innobase/btr/btr0cur.cc b/storage/innobase/btr/btr0cur.cc
index 0d72b9d2b92..c74d036c563 100644
--- a/storage/innobase/btr/btr0cur.cc
+++ b/storage/innobase/btr/btr0cur.cc
@@ -3626,7 +3626,7 @@ btr_cur_update_in_place(
 #ifdef UNIV_DEBUG
 	{
 		rec_printer p(rec, offsets);
-		DBUG_PRINT("ib_cur", ("update-in-place %s (" IB_ID_FMT ") by "IB_ID_FMT ": %s",
+		DBUG_PRINT("ib_cur", ("update-in-place %s (" IB_ID_FMT ") by " IB_ID_FMT ": %s",
 				index->name(), index->id, trx_id,
 				p.str().c_str()));
 	}
diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc
index 83dd0c17eaa..1ae2d1e979c 100644
--- a/storage/innobase/handler/ha_innodb.cc
+++ b/storage/innobase/handler/ha_innodb.cc
@@ -61,7 +61,7 @@ this program; if not, write to the Free Software Foundation, Inc.,
 // MYSQL_PLUGIN_IMPORT extern my_bool lower_case_file_system;
 // MYSQL_PLUGIN_IMPORT extern char mysql_unpacked_real_data_home[];
 
-#include <my_systemd.h>
+#include <my_service_manager.h>
 #include <key.h>
 
 /* Include necessary InnoDB headers */
@@ -4114,9 +4114,6 @@ innobase_init(
 	innobase_hton->flags =
 		HTON_SUPPORTS_EXTENDED_KEYS | HTON_SUPPORTS_FOREIGN_KEYS;
 
-	innobase_hton->release_temporary_latches =
-		innobase_release_temporary_latches;
-
 #ifdef MYSQL_REPLACE_TRX_IN_THD
         innobase_hton->replace_native_transaction_in_thd =
                 innodb_replace_trx_in_thd;
diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc
index 51aef715ee2..1a7b0a1dc8b 100644
--- a/storage/innobase/handler/handler0alter.cc
+++ b/storage/innobase/handler/handler0alter.cc
@@ -71,8 +71,7 @@ static const char *MSG_UNSUPPORTED_ALTER_ONLINE_ON_VIRTUAL_COLUMN=
 /** Operations for creating secondary indexes (no rebuild needed) */
 static const Alter_inplace_info::HA_ALTER_FLAGS INNOBASE_ONLINE_CREATE
 	= Alter_inplace_info::ADD_INDEX
-	| Alter_inplace_info::ADD_UNIQUE_INDEX
-	| Alter_inplace_info::ADD_SPATIAL_INDEX;
+	| Alter_inplace_info::ADD_UNIQUE_INDEX;
 
 /** Operations for rebuilding a table in place */
 static const Alter_inplace_info::HA_ALTER_FLAGS INNOBASE_ALTER_REBUILD
@@ -1915,11 +1914,6 @@ innobase_row_to_mysql(
 				dfield_get_len(df), field);
 		}
 	}
-	if (table->vfield) {
-		my_bitmap_map*	old_vcol_set = tmp_use_all_columns(table, table->vcol_set);
-		table->update_virtual_fields(VCOL_UPDATE_FOR_READ_WRITE);
-		tmp_restore_column_map(table->vcol_set, old_vcol_set);
-	}
 }
 
 /*************************************************************//**
@@ -4476,8 +4470,6 @@ prepare_inplace_alter_table_dict(
 		/* This should have been blocked in
 		check_if_supported_inplace_alter(). */
 		ut_ad(0);
-		my_error(ER_NOT_SUPPORTED_YET, MYF(0),
-			 thd_query(ctx->prebuilt->trx->mysql_thd));
 		goto error_handled;
 	}
 
diff --git a/storage/innobase/include/data0type.ic b/storage/innobase/include/data0type.ic
index 57770ec0e17..edc8481e6b6 100644
--- a/storage/innobase/include/data0type.ic
+++ b/storage/innobase/include/data0type.ic
@@ -388,6 +388,7 @@ dtype_sql_name(
 	unsigned	name_sz)/*!< in: size of the name buffer */
 {
 
+#define ut_snprintf snprintf
 #define APPEND_UNSIGNED()					\
 	do {							\
 		if (prtype & DATA_UNSIGNED) {			\
diff --git a/storage/innobase/log/log0recv.cc b/storage/innobase/log/log0recv.cc
index a7c3f337287..d174bef55b2 100644
--- a/storage/innobase/log/log0recv.cc
+++ b/storage/innobase/log/log0recv.cc
@@ -30,7 +30,7 @@ Created 9/20/1997 Heikki Tuuri
 #include <vector>
 #include <map>
 #include <string>
-#include <my_systemd.h>
+#include <my_service_manager.h>
 
 #include "log0recv.h"
 

Compilation:

cmake -DCMAKE_{C_COMPILER=clang,CXX_COMPILER=clang++}-10 -DCMAKE_C{,XX}_FLAGS='-O2 -march=native -mtune=native -Wno-unused-command-line-argument -fdebug-macro' -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCONC_WITH_{UNITTEST,SSL}=OFF -DWITH_EMBEDDED_SERVER=OFF -DWITH_UNIT_TESTS=OFF -DCMAKE_BUILD_TYPE=Debug -DPLUGIN_{ARCHIVE,TOKUDB,MROONGA,OQGRAPH,ROCKSDB,CONNECT,SPIDER}=NO -DWITH_SAFEMALLOC=OFF -DWITH_{ZLIB,SSL}=system -G Ninja -DWITH_SYSTEMD=no -DWITH_MARIABACKUP=OFF -DWITH_INNODB_{AHI,ROOT_GUESS,LZ4,LZMA,LZO,BZIP,SNAPPY}=OFF -DMYSQL_MAINTAINER_MODE=OFF /mariadb/10.2
ninja -k 60

There is no option to disable the compilation of innochecksum. It will fail, but we only need sql/mysqld for this:

--source include/have_innodb.inc
 
SET sql_mode='';
CREATE TABLE t (c INT AUTO_INCREMENT KEY) ENGINE=InnoDB;
SET @@SESSION.insert_id=-0;  # Or -1, -2 etc.
INSERT INTO t VALUES(0);

SET sql_mode='';
CREATE TABLE t (c INT AUTO_INCREMENT KEY) ENGINE=InnoDB;
SET @@SESSION.insert_id=-0;
INSERT INTO t VALUES(0);
innodb.ai 'innodb'                       [ fail ]
        Test ended at 2020-04-02 11:14:06
 
CURRENT_TEST: innodb.ai
mysqltest: At line 6: query 'INSERT INTO t VALUES(0)' failed: 2013: Lost connection to MySQL server during query
Version: '10.2.32-MariaDB-debug-log'  socket: '/dev/shm/10.2o/mysql-test/var/tmp/mysqld.1.sock'  port: 16020  Source distribution
mysqld: /mariadb/10.2/sql/handler.cc:3220: int handler::update_auto_increment(): Assertion `nr != 0' failed.

The next interesting exercise would be to transplant 2e814d4702d71a04388386a9f591d14a35980bfe~ (or to build that one directly if you manage to do it).

Comment by Elena Stepanova [ 2020-04-02 ]

Please note that it fails with MyISAM as well, so I doubt any InnoDB changes would be to blame.

Comment by Marko Mäkelä [ 2020-04-02 ]

Transplanting the MySQL 5.6 based InnoDB to the newest 10.2 was an even bigger exercise. I can reproduce the bug even with that:

10.2 05e4a87c8b074910f4bbf2b6a666a670764c4f89 with InnoDB 5.6

SET sql_mode='';
CREATE TABLE t (c INT AUTO_INCREMENT KEY) ENGINE=InnoDB;
SET @@SESSION.insert_id=-0;
INSERT INTO t VALUES(0);
innodb.ai 'innodb'                       [ fail ]
        Test ended at 2020-04-02 12:12:42
 
CURRENT_TEST: innodb.ai
mysqltest: At line 6: query 'INSERT INTO t VALUES(0)' failed: 2013: Lost connection to MySQL server during query
2020-04-02 12:12:42 140491119908672 [Note] InnoDB: 5.6.31 started; log sequence number 1618552
Version: '10.2.32-MariaDB-debug-log'  socket: '/dev/shm/10.2o/mysql-test/var/tmp/mysqld.1.sock'  port: 16000  Source distribution
mysqld: /mariadb/10.2o/sql/handler.cc:3220: int handler::update_auto_increment(): Assertion `nr != 0' failed.

Here is how I transplanted the old InnoDB to the new server:

git worktree add ../10.2-transplant 05e4a87c8b074910f4bbf2b6a666a670764c4f89
cd ../10.2-transplant
git rm -fr storage/innobase
git checkout 2e814d4702d71a04388386a9f591d14a35980bfe~ storage/innobase extra/innochecksum.cc
git checkout HEAD storage/innobase/innodb.cmake
patch -p1<transplant.patch
mkdir build
cd build
cmake -DCMAKE_{C_COMPILER=clang,CXX_COMPILER=clang++}-10 -DCMAKE_C{,XX}_FLAGS='-O2 -march=native -mtune=native -Wno-unused-command-line-argument -fdebug-macro' -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCONC_WITH_{UNITTEST,SSL}=OFF -DWITH_EMBEDDED_SERVER=OFF -DWITH_UNIT_TESTS=OFF -DCMAKE_BUILD_TYPE=Debug -DPLUGIN_{ARCHIVE,TOKUDB,MROONGA,OQGRAPH,ROCKSDB,CONNECT,SPIDER}=NO -DWITH_SAFEMALLOC=OFF -DWITH_{ZLIB,SSL}=system -G Ninja -DWITH_SYSTEMD=no -DWITH_MARIABACKUP=OFF -DWITH_INNODB_{AHI,ROOT_GUESS,LZ4,LZMA,LZO,BZIP,SNAPPY}=OFF -DMYSQL_MAINTAINER_MODE=OFF ..
ninja

The following patch needs to be applied:

diff --git a/storage/innobase/CMakeLists.txt b/storage/innobase/CMakeLists.txt
index 8c608e82388..e54c36f9efd 100644
--- a/storage/innobase/CMakeLists.txt
+++ b/storage/innobase/CMakeLists.txt
@@ -18,17 +18,6 @@
 INCLUDE(CheckFunctionExists)
 INCLUDE(CheckCSourceCompiles)
 INCLUDE(CheckCSourceRuns)
-INCLUDE(lz4)
-INCLUDE(lzo)
-INCLUDE(lzma)
-INCLUDE(bzip2)
-INCLUDE(snappy)
-
-MYSQL_CHECK_LZ4()
-MYSQL_CHECK_LZO()
-MYSQL_CHECK_LZMA()
-MYSQL_CHECK_BZIP2()
-MYSQL_CHECK_SNAPPY()
 
 IF(CMAKE_CROSSCOMPILING)
   # Use CHECK_C_SOURCE_COMPILES instead of CHECK_C_SOURCE_RUNS when
diff --git a/storage/innobase/api/api0api.cc b/storage/innobase/api/api0api.cc
index 739ea9f7572..c637f44b376 100644
--- a/storage/innobase/api/api0api.cc
+++ b/storage/innobase/api/api0api.cc
@@ -2333,13 +2333,7 @@ ib_col_set_value(
 			uint pos = (uint)(col_len / cs->mbmaxlen);
 
 			if (len > 0 && cs->mbmaxlen > 1) {
-				true_len = (ulint)
-					cs->cset->well_formed_len(
-						cs,
-						(const char*)src,
-						(const char*)src + len,
-						pos,
-						&error);
+				true_len = len;
 
 				if (true_len < len) {
 					len = static_cast<ib_ulint_t>(true_len);
diff --git a/storage/innobase/handler/ha_innodb.cc b/storage/innobase/handler/ha_innodb.cc
index 91284c2c2fc..88f0a363679 100644
--- a/storage/innobase/handler/ha_innodb.cc
+++ b/storage/innobase/handler/ha_innodb.cc
@@ -55,7 +55,7 @@ MYSQL_PLUGIN_IMPORT extern char mysql_unpacked_real_data_home[];
 #include <io.h>
 #endif
 
-#include <my_systemd.h>
+#include <my_service_manager.h>
 
 /** @file ha_innodb.cc */
 
@@ -114,6 +114,7 @@ MYSQL_PLUGIN_IMPORT extern char mysql_unpacked_real_data_home[];
 #include "page0zip.h"
 #include "fil0pagecompress.h"
 
+#define ha_statistic_increment(x)
 #define thd_get_trx_isolation(X) ((enum_tx_isolation)thd_tx_isolation(X))
 
 #ifdef MYSQL_DYNAMIC_PLUGIN
@@ -2114,9 +2115,7 @@ innobase_check_identifier_length(
 	CHARSET_INFO	*cs = system_charset_info;
 	DBUG_ENTER("innobase_check_identifier_length");
 
-	size_t len = cs->cset->well_formed_len(
-		cs, id, id + strlen(id),
-		NAME_CHAR_LEN, &well_formed_error);
+	size_t len = strlen(id);
 
 	if (well_formed_error || len == NAME_CHAR_LEN) {
 		my_error(ER_TOO_LONG_IDENT, MYF(0), id);
@@ -3350,8 +3349,6 @@ innobase_init(
 	innobase_hton->flags =
 		HTON_SUPPORTS_EXTENDED_KEYS | HTON_SUPPORTS_FOREIGN_KEYS;
 
-	innobase_hton->release_temporary_latches =
-		innobase_release_temporary_latches;
 #ifdef WITH_WSREP
         innobase_hton->abort_transaction=wsrep_abort_transaction;
         innobase_hton->set_checkpoint=innobase_wsrep_set_checkpoint;
@@ -6855,18 +6852,6 @@ wsrep_store_key_val_for_row(
 
 			true_len = len;
 
-			/* For multi byte character sets we need to calculate
-			the true length of the key */
-
-			if (len > 0 && cs->mbmaxlen > 1) {
-				true_len = (ulint) cs->cset->well_formed_len(cs,
-						(const char *) data,
-						(const char *) data + len,
-                                                (uint) (key_len /
-                                                        cs->mbmaxlen),
-						&error);
-			}
-
 			/* In a column prefix index, we may need to truncate
 			the stored value: */
 
@@ -6942,19 +6927,6 @@ wsrep_store_key_val_for_row(
 			ut_a(get_field_offset(table, field)
 				== key_part->offset);
 
-			/* For multi byte character sets we need to calculate
-			the true length of the key */
-
-			if (blob_len > 0 && cs->mbmaxlen > 1) {
-				true_len = (ulint) cs->cset->well_formed_len(cs,
-						(const char *) blob_data,
-						(const char *) blob_data
-							+ blob_len,
-                                                (uint) (key_len /
-                                                        cs->mbmaxlen),
-						&error);
-			}
-
 			/* All indexes on BLOB and TEXT are column prefix
 			indexes, and we may need to truncate the data to be
 			stored in the key value: */
@@ -7029,20 +7001,6 @@ wsrep_store_key_val_for_row(
 
 				cs = field->charset();
 
-				/* For multi byte character sets we need to
-				calculate the true length of the key */
-
-				if (key_len > 0 && cs->mbmaxlen > 1) {
-
-					true_len = (ulint)
-						cs->cset->well_formed_len(cs,
-							(const char *)src_start,
-							(const char *)src_start
-								+ key_len,
-                                                        (uint) (key_len /
-                                                                cs->mbmaxlen),
-							&error);
-				}
 				memcpy(sorted, src_start, true_len);
 				true_len = wsrep_innobase_mysql_sort(
 					mysql_type, cs->number, sorted, true_len,
@@ -7166,17 +7124,6 @@ ha_innobase::store_key_val_for_row(
 
 			true_len = len;
 
-			/* For multi byte character sets we need to calculate
-			the true length of the key */
-
-			if (len > 0 && cs->mbmaxlen > 1) {
-				true_len = (ulint) cs->cset->well_formed_len(cs,
-						(const char*) data,
-						(const char*) data + len,
-						(uint) (key_len / cs->mbmaxlen),
-						&error);
-			}
-
 			/* In a column prefix index, we may need to truncate
 			the stored value: */
 
@@ -7237,18 +7184,6 @@ ha_innobase::store_key_val_for_row(
 			ut_a(get_field_offset(table, field)
 				== key_part->offset);
 
-			/* For multi byte character sets we need to calculate
-			the true length of the key */
-
-			if (blob_len > 0 && cs->mbmaxlen > 1) {
-				true_len = (ulint) cs->cset->well_formed_len(cs,
-						(const char*) blob_data,
-						(const char*) blob_data
-							+ blob_len,
-						(uint) (key_len / cs->mbmaxlen),
-						&error);
-			}
-
 			/* All indexes on BLOB and TEXT are column prefix
 			indexes, and we may need to truncate the data to be
 			stored in the key value: */
@@ -7295,34 +7230,6 @@ ha_innobase::store_key_val_for_row(
 			real_type = field->real_type();
 			true_len = key_len;
 
-			/* Character set for the field is defined only
-			to fields whose type is string and real field
-			type is not enum or set. For these fields check
-			if character set is multi byte. */
-
-			if (real_type != MYSQL_TYPE_ENUM
-				&& real_type != MYSQL_TYPE_SET
-				&& ( mysql_type == MYSQL_TYPE_VAR_STRING
-					|| mysql_type == MYSQL_TYPE_STRING)) {
-
-				cs = field->charset();
-
-				/* For multi byte character sets we need to
-				calculate the true length of the key */
-
-				if (key_len > 0 && cs->mbmaxlen > 1) {
-
-					true_len = (ulint)
-						cs->cset->well_formed_len(cs,
-							(const char*) src_start,
-							(const char*) src_start
-								+ key_len,
-							(uint) (key_len
-								/ cs->mbmaxlen),
-							&error);
-				}
-			}
-
 			memcpy(buff, src_start, true_len);
 			buff += true_len;
 
@@ -14233,10 +14140,6 @@ get_foreign_key_info(
 		ptr = "RESTRICT";
 	}
 
-	f_key_info.delete_method = thd_make_lex_string(
-		thd, f_key_info.delete_method, ptr,
-		static_cast<unsigned int>(len), 1);
-
 	if (foreign->type & DICT_FOREIGN_ON_UPDATE_CASCADE) {
 		len = 7;
 		ptr = "CASCADE";
@@ -14251,10 +14154,6 @@ get_foreign_key_info(
 		ptr = "RESTRICT";
 	}
 
-	f_key_info.update_method = thd_make_lex_string(
-		thd, f_key_info.update_method, ptr,
-		static_cast<unsigned int>(len), 1);
-
 	if (foreign->referenced_index && foreign->referenced_index->name) {
 		referenced_key_name = thd_make_lex_string(thd,
 					f_key_info.referenced_key_name,
diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc
index bb7efa104fa..7dc817db3ce 100644
--- a/storage/innobase/handler/handler0alter.cc
+++ b/storage/innobase/handler/handler0alter.cc
@@ -65,7 +65,6 @@ static const Alter_inplace_info::HA_ALTER_FLAGS INNOBASE_ALTER_REBUILD
 	/* CHANGE_CREATE_OPTION needs to check innobase_need_rebuild() */
 	| Alter_inplace_info::ALTER_COLUMN_NULLABLE
 	| Alter_inplace_info::ALTER_COLUMN_NOT_NULLABLE
-	| Alter_inplace_info::ALTER_COLUMN_ORDER
 	| Alter_inplace_info::DROP_COLUMN
 	| Alter_inplace_info::ADD_COLUMN
 	| Alter_inplace_info::RECREATE_TABLE
@@ -326,11 +325,6 @@ ha_innobase::check_if_supported_inplace_alter(
 		| INNOBASE_ALTER_NOREBUILD
 		| INNOBASE_ALTER_REBUILD)) {
 
-		if (ha_alter_info->handler_flags
-			& (Alter_inplace_info::ALTER_COLUMN_EQUAL_PACK_LENGTH
-			   | Alter_inplace_info::ALTER_COLUMN_TYPE))
-			ha_alter_info->unsupported_reason = innobase_get_err_msg(
-				ER_ALTER_OPERATION_NOT_SUPPORTED_REASON_COLUMN_TYPE);
 		DBUG_RETURN(HA_ALTER_INPLACE_NOT_SUPPORTED);
 	}
 
@@ -777,34 +771,6 @@ innobase_set_foreign_key_option(
 {
 	ut_ad(!foreign->type);
 
-	switch (fk_key->delete_opt) {
-	case Foreign_key::FK_OPTION_NO_ACTION:
-	case Foreign_key::FK_OPTION_RESTRICT:
-	case Foreign_key::FK_OPTION_DEFAULT:
-		foreign->type = DICT_FOREIGN_ON_DELETE_NO_ACTION;
-		break;
-	case Foreign_key::FK_OPTION_CASCADE:
-		foreign->type = DICT_FOREIGN_ON_DELETE_CASCADE;
-		break;
-	case Foreign_key::FK_OPTION_SET_NULL:
-		foreign->type = DICT_FOREIGN_ON_DELETE_SET_NULL;
-		break;
-	}
-
-	switch (fk_key->update_opt) {
-	case Foreign_key::FK_OPTION_NO_ACTION:
-	case Foreign_key::FK_OPTION_RESTRICT:
-	case Foreign_key::FK_OPTION_DEFAULT:
-		foreign->type |= DICT_FOREIGN_ON_UPDATE_NO_ACTION;
-		break;
-	case Foreign_key::FK_OPTION_CASCADE:
-		foreign->type |= DICT_FOREIGN_ON_UPDATE_CASCADE;
-		break;
-	case Foreign_key::FK_OPTION_SET_NULL:
-		foreign->type |= DICT_FOREIGN_ON_UPDATE_SET_NULL;
-		break;
-	}
-
 	return(innobase_check_fk_option(foreign));
 }
 
@@ -1125,7 +1091,7 @@ innobase_get_foreign_key_info(
 			    referenced_column_names, referenced_num_col)) {
 			mutex_exit(&dict_sys->mutex);
 			my_error(
-				ER_FK_DUP_NAME,
+				ER_GET_ERRNO,
 				MYF(0),
 				add_fk[num_fk]->id);
 			goto err_exit;
@@ -4041,12 +4007,7 @@ ha_innobase::prepare_inplace_alter_table(
 				 FTS_DOC_ID_INDEX_NAME);
 			goto err_exit;
 		case FTS_EXIST_DOC_ID_INDEX:
-			DBUG_ASSERT(doc_col_no == fts_doc_col_no
-				    || doc_col_no == ULINT_UNDEFINED
-				    || (ha_alter_info->handler_flags
-					& (Alter_inplace_info::ALTER_COLUMN_ORDER
-					   | Alter_inplace_info::DROP_COLUMN
-					   | Alter_inplace_info::ADD_COLUMN)));
+			break;
 		}
 	}
 
diff --git a/storage/innobase/include/ha_prototypes.h b/storage/innobase/include/ha_prototypes.h
index 12453099ef7..e9f569e17b5 100644
--- a/storage/innobase/include/ha_prototypes.h
+++ b/storage/innobase/include/ha_prototypes.h
@@ -37,6 +37,7 @@ Created 5/11/2006 Osku Salerma
 
 #include "trx0types.h"
 #include "m_ctype.h" /* CHARSET_INFO */
+#include "dur_prop.h"
 
 // Forward declarations
 class Field;
diff --git a/storage/innobase/log/log0recv.cc b/storage/innobase/log/log0recv.cc
index 9fde18757c5..43e00209327 100644
--- a/storage/innobase/log/log0recv.cc
+++ b/storage/innobase/log/log0recv.cc
@@ -30,7 +30,7 @@ Created 9/20/1997 Heikki Tuuri
 #include <stdio.h>                              // Solaris/x86 header file bug
 
 #include <vector>
-#include <my_systemd.h>
+#include <my_service_manager.h>
 
 #include "log0recv.h"
 

Comment by Marko Mäkelä [ 2020-04-02 ]

I realized that I could have built the old 10.2 by specifying cmake -DWITH_SSL=bundled -DMYSQL_MAINTAINER_MODE=OFF -DCMAKE_BUILD_TYPE=Debug:

git checkout 848d211c5c4df00b819cd84d7530cf7d29bb0524
git cherry-pick --no-commit f77bd5faf53fe89f3ad7fe53bb0cee44ddfb1cec

The cherry-pick is needed to be able to invoke ./mtr.

10.2 848d211c5c4df00b819cd84d7530cf7d29bb0524

SET sql_mode='';
CREATE TABLE t (c INT AUTO_INCREMENT KEY) ENGINE=InnoDB;
SET @@SESSION.insert_id=-0;
INSERT INTO t VALUES(0);
innodb.ai 'innodb_plugin'                [ fail ]
        Test ended at 2020-04-02 12:56:19
 
CURRENT_TEST: innodb.ai
mysqltest: At line 6: query 'INSERT INTO t VALUES(0)' failed: 2013: Lost connection to MySQL server during query
Version: '10.2.2-MariaDB-debug'  socket: '/dev/shm/10.2oo/mysql-test/var/tmp/mysqld.1.sock'  port: 16000  Source distribution
mysqld: /mariadb/10.2-transplant/sql/handler.cc:3080: int handler::update_auto_increment(): Assertion `nr != 0' failed.

Comment by Marko Mäkelä [ 2020-04-02 ]

I repeated the crash also on 10.2.0 and 10.2.1. The latest merge from 10.1 to MariaDB 10.2.0 was the mariadb-10.1.13 release tag.

Because of this, I tested mariadb-10.1.13, and it did not crash in either InnoDB or XtraDB.
The reason for it not crashing is that the failing assertion is not present there. The assertion in handler::update_auto_increment() was added in 10.2 only.

Comment by Roel Van de Paar [ 2020-04-28 ]

Different codepath testcase

# mysqld options required for replay: --sql_mode=
USE test;
SET @@session.insert_id=0;
CREATE TABLE t (c INT KEY);
INSERT INTO t VALUES (0);
ALTER TABLE t CHANGE c c INT AUTO_INCREMENT;

Leads to:

10.5.3 98003440c2f8d20164a191ced1b7d92b283bb68f

mysqld: /test/10.5_dbg/sql/handler.cc:3566: int handler::update_auto_increment(): Assertion `nr != 0' failed.

10.5.3 98003440c2f8d20164a191ced1b7d92b283bb68f

Core was generated by `/test/MD210420-mariadb-10.5.3-linux-x86_64-dbg/bin/mysqld --no-defaults --core-'.
Program terminated with signal SIGABRT, Aborted.
#0  __pthread_kill (threadid=<optimized out>, signo=signo@entry=6)
    at ../sysdeps/unix/sysv/linux/pthread_kill.c:57
[Current thread is 1 (Thread 0x7f2bad298700 (LWP 682258))]
(gdb) bt
#0  __pthread_kill (threadid=<optimized out>, signo=signo@entry=6) at ../sysdeps/unix/sysv/linux/pthread_kill.c:57
#1  0x0000555885a8903d in my_write_core (sig=sig@entry=6) at /test/10.5_dbg/mysys/stacktrace.c:518
#2  0x000055588522ed7b in handle_fatal_signal (sig=6) at /test/10.5_dbg/sql/signal_handler.cc:329
#3  <signal handler called>
#4  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#5  0x00007f2bab9dc801 in __GI_abort () at abort.c:79
#6  0x00007f2bab9cc39a in __assert_fail_base (fmt=0x7f2babb537d8 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=assertion@entry=0x555885d92100 "nr != 0", file=file@entry=0x555885d91a22 "/test/10.5_dbg/sql/handler.cc", line=line@entry=3566, function=function@entry=0x555885d95d80 <handler::update_auto_increment()::__PRETTY_FUNCTION__> "int handler::update_auto_increment()") at assert.c:92
#7  0x00007f2bab9cc412 in __GI___assert_fail (assertion=assertion@entry=0x555885d92100 "nr != 0", file=file@entry=0x555885d91a22 "/test/10.5_dbg/sql/handler.cc", line=line@entry=3566, function=function@entry=0x555885d95d80 <handler::update_auto_increment()::__PRETTY_FUNCTION__> "int handler::update_auto_increment()") at assert.c:101
#8  0x000055588523ab1e in handler::update_auto_increment (this=this@entry=0x7f2b7fd56ea0) at /test/10.5_dbg/sql/handler.cc:3566
#9  0x00005558855ff2b2 in ha_innobase::write_row (this=0x7f2b7fd56ea0, record=0x7f2b7fc570a8 "\377") at /test/10.5_dbg/storage/innobase/handler/ha_innodb.cc:7732
#10 0x0000555885242c5b in handler::ha_write_row (this=0x7f2b7fd56ea0, buf=0x7f2b7fc570a8 "\377") at /test/10.5_dbg/sql/handler.cc:6957
#11 0x000055588505ce34 in copy_data_between_tables (alter_ctx=0x7f2bad2956c0, keys_onoff=<optimized out>, deleted=<synthetic pointer>, copied=<synthetic pointer>, order=<optimized out>, order_num=0, ignore=false, create=..., to=0x7f2b7fd73088, from=0x7f2b7fcf0088, thd=0x7f2b7fc15088) at /test/10.5_dbg/sql/sql_table.cc:11214
#12 mysql_alter_table (thd=thd@entry=0x7f2b7fc15088, new_db=new_db@entry=0x7f2b7fc19940, new_name=new_name@entry=0x7f2b7fc19d48, create_info=create_info@entry=0x7f2bad2962b0, table_list=<optimized out>, table_list@entry=0x7f2b7fc741a8, alter_info=alter_info@entry=0x7f2bad2961e0, order_num=0, order=0x0, ignore=false, if_exists=false) at /test/10.5_dbg/sql/sql_table.cc:10588
#13 0x00005558850def31 in Sql_cmd_alter_table::execute (this=<optimized out>, thd=0x7f2b7fc15088) at /test/10.5_dbg/sql/sql_alter.cc:520
#14 0x0000555884f8a422 in mysql_execute_command (thd=thd@entry=0x7f2b7fc15088) at /test/10.5_dbg/sql/sql_parse.cc:5912
#15 0x0000555884f91f2b in mysql_parse (thd=thd@entry=0x7f2b7fc15088, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x7f2bad297450, is_com_multi=is_com_multi@entry=false, is_next_command=is_next_command@entry=false) at /test/10.5_dbg/sql/sql_parse.cc:7957
#16 0x0000555884f7dc45 in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x7f2b7fc15088, packet=packet@entry=0x7f2b7fc67089 "ALTER TABLE t CHANGE c c INT AUTO_INCREMENT", packet_length=packet_length@entry=43, is_com_multi=is_com_multi@entry=false, is_next_command=is_next_command@entry=false) at /test/10.5_dbg/sql/sql_parse.cc:1839
#17 0x0000555884f7c49b in do_command (thd=0x7f2b7fc15088) at /test/10.5_dbg/sql/sql_parse.cc:1358
#18 0x00005558850d7415 in do_handle_one_connection (connect=<optimized out>, connect@entry=0x7f2b8b3c53a8, put_in_cache=put_in_cache@entry=true) at /test/10.5_dbg/sql/sql_connect.cc:1422
#19 0x00005558850d7744 in handle_one_connection (arg=arg@entry=0x7f2b8b3c53a8) at /test/10.5_dbg/sql/sql_connect.cc:1319
#20 0x0000555885537fb0 in pfs_spawn_thread (arg=0x7f2baac45b08) at /test/10.5_dbg/storage/perfschema/pfs.cc:2201
#21 0x00007f2bac6bf6db in start_thread (arg=0x7f2bad298700) at pthread_create.c:463
#22 0x00007f2bababd88f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Bug confirmed present in:
MariaDB: 10.2.32 (dbg), 10.3.23 (dbg), 10.4.13 (dbg), 10.5.2 (dbg), 10.5.3 (dbg)

Bug confirmed not present in:
MariaDB: 10.1.45 (dbg), 10.1.45 (opt), 10.2.32 (opt), 10.3.23 (opt), 10.4.13 (opt), 10.5.2 (opt), 10.5.3 (opt)
MySQL: 5.5.62 (dbg), 5.5.62 (opt), 5.6.47 (dbg), 5.6.47 (opt), 5.7.29 (dbg), 5.7.29 (opt), 8.0.19 (dbg), 8.0.19 (opt)

Comment by Marko Mäkelä [ 2020-04-28 ]

Roel, did you try adding that failing debug assertion to the claimed unaffected versions? I think that the condition should fail also there.

Comment by Roel Van de Paar [ 2020-04-28 ]

Ah interesting. No did not change the code. Thanks for the update.

Comment by Roel Van de Paar [ 2020-10-02 ]

Onre more testcase

SET SQL_MODE='';
SET GLOBAL stored_program_cache = 0;
SET @start_value=@@GLOBAL.stored_program_cache;
SET SESSION insert_id=@start_value;
INSERT INTO mysql.time_zone VALUES (NULL, 'a');

Leads to:

10.5.6 2bac9782aa81ad386beaf00eb126ccf2d15031a1 (Debug)

mysqld: /test/10.5_dbg/sql/handler.cc:3648: int handler::update_auto_increment(): Assertion `nr != 0' failed.

10.5.6 2bac9782aa81ad386beaf00eb126ccf2d15031a1 (Debug)

Core was generated by `/test/MD150920-mariadb-10.5.6-linux-x86_64-dbg/bin/mysqld --no-defaults --core-'.
Program terminated with signal SIGABRT, Aborted.
#0  __pthread_kill (threadid=<optimized out>, signo=signo@entry=6)
    at ../sysdeps/unix/sysv/linux/pthread_kill.c:57
[Current thread is 1 (Thread 0x148129cd7700 (LWP 359056))]
(gdb) bt
#0  __pthread_kill (threadid=<optimized out>, signo=signo@entry=6) at ../sysdeps/unix/sysv/linux/pthread_kill.c:57
#1  0x0000556c2675a85a in my_write_core (sig=sig@entry=6) at /test/10.5_dbg/mysys/stacktrace.c:424
#2  0x0000556c25f213a9 in handle_fatal_signal (sig=6) at /test/10.5_dbg/sql/signal_handler.cc:330
#3  <signal handler called>
#4  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:51
#5  0x0000148127f6d8b1 in __GI_abort () at abort.c:79
#6  0x0000148127f5d42a in __assert_fail_base (fmt=0x1481280e4a38 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=assertion@entry=0x556c26a6ea30 "nr != 0", file=file@entry=0x556c26a6e322 "/test/10.5_dbg/sql/handler.cc", line=line@entry=3648, function=function@entry=0x556c26a726e0 <handler::update_auto_increment()::__PRETTY_FUNCTION__> "int handler::update_auto_increment()") at assert.c:92
#7  0x0000148127f5d4a2 in __GI___assert_fail (assertion=assertion@entry=0x556c26a6ea30 "nr != 0", file=file@entry=0x556c26a6e322 "/test/10.5_dbg/sql/handler.cc", line=line@entry=3648, function=function@entry=0x556c26a726e0 <handler::update_auto_increment()::__PRETTY_FUNCTION__> "int handler::update_auto_increment()") at assert.c:101
#8  0x0000556c25f2d54e in handler::update_auto_increment (this=0x1481058330a0) at /test/10.5_dbg/sql/handler.cc:3648
#9  0x0000556c26172a8c in ha_maria::write_row (this=0x1481058330a0, buf=0x1481058520b0 "\377") at /test/10.5_dbg/storage/maria/ha_maria.cc:1256
#10 0x0000556c25f357fc in handler::ha_write_row (this=0x1481058330a0, buf=0x1481058520b0 "\377") at /test/10.5_dbg/sql/handler.cc:7137
#11 0x0000556c25c2d821 in write_record (thd=thd@entry=0x148105815088, table=table@entry=0x148105851188, info=info@entry=0x148129cd59e0, sink=sink@entry=0x0) at /test/10.5_dbg/sql/sql_insert.cc:2092
#12 0x0000556c25c3887f in mysql_insert (thd=thd@entry=0x148105815088, table_list=0x1481058741c0, fields=@0x14810581a0d0: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x556c274b33e0 <end_of_list>, last = 0x14810581a0d0, elements = 0}, <No data fields>}, values_list=@0x14810581a118: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x148105874e68, last = 0x148105874e68, elements = 1}, <No data fields>}, update_fields=@0x14810581a100: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x556c274b33e0 <end_of_list>, last = 0x14810581a100, elements = 0}, <No data fields>}, update_values=@0x14810581a0e8: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x556c274b33e0 <end_of_list>, last = 0x14810581a0e8, elements = 0}, <No data fields>}, duplic=DUP_ERROR, ignore=false, result=0x0) at /test/10.5_dbg/sql/sql_insert.cc:1087
#13 0x0000556c25c6fc6e in mysql_execute_command (thd=thd@entry=0x148105815088) at /test/10.5_dbg/sql/sql_parse.cc:4546
#14 0x0000556c25c7b324 in mysql_parse (thd=thd@entry=0x148105815088, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x148129cd6350, is_com_multi=is_com_multi@entry=false, is_next_command=is_next_command@entry=false) at /test/10.5_dbg/sql/sql_parse.cc:7994
#15 0x0000556c25c67d54 in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x148105815088, packet=packet@entry=0x148105867089 "INSERT INTO mysql.time_zone VALUES (NULL, 'a')", packet_length=packet_length@entry=46, is_com_multi=is_com_multi@entry=false, is_next_command=is_next_command@entry=false) at /test/10.5_dbg/sql/sql_parse.cc:1867
#16 0x0000556c25c6653e in do_command (thd=0x148105815088) at /test/10.5_dbg/sql/sql_parse.cc:1348
#17 0x0000556c25dc5893 in do_handle_one_connection (connect=<optimized out>, connect@entry=0x148108cd43a8, put_in_cache=put_in_cache@entry=true) at /test/10.5_dbg/sql/sql_connect.cc:1410
#18 0x0000556c25dc5fb7 in handle_one_connection (arg=arg@entry=0x148108cd43a8) at /test/10.5_dbg/sql/sql_connect.cc:1312
#19 0x0000556c262305c2 in pfs_spawn_thread (arg=0x148126846508) at /test/10.5_dbg/storage/perfschema/pfs.cc:2201
#20 0x0000148128c506db in start_thread (arg=0x148129cd7700) at pthread_create.c:463
#21 0x000014812804ea3f in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Bug confirmed present in:
MariaDB: 10.2.34 (dbg), 10.3.25 (dbg), 10.4.15 (dbg), 10.5.6 (dbg)

Bug confirmed not present in:
MariaDB: 10.1.47 (dbg), 10.1.47 (opt), 10.2.34 (opt), 10.3.25 (opt), 10.4.15 (opt), 10.5.6 (opt), 10.6.0 (dbg), 10.6.0 (opt)
MySQL: 5.5.62 (dbg), 5.5.62 (opt), 5.6.49 (dbg), 5.6.49 (opt), 5.7.31 (dbg), 5.7.31 (opt), 8.0.21 (dbg), 8.0.21 (opt)

Comment by Roel Van de Paar [ 2021-01-22 ]

Yet another slightly different one.

SET SESSION insert_id=0;
ALTER TABLE mysql.general_log ENGINE=MyISAM;
ALTER TABLE mysql.general_log ADD COLUMN seq INT AUTO_INCREMENT PRIMARY KEY;
SET GLOBAL log_output="TABLE";
SET GLOBAL general_log=1;
INSERT INTO non_existing VALUES (1);

Leads to:

10.6.0 9118fd360a3da0bba521caf2a35c424968235ac4 (Debug)

mysqld: /test/10.6_dbg/sql/handler.cc:3653: int handler::update_auto_increment(): Assertion `nr != 0' failed.

10.6.0 9118fd360a3da0bba521caf2a35c424968235ac4 (Debug)

Core was generated by `/test/MD010121-mariadb-10.6.0-linux-x86_64-dbg/bin/mysqld --no-defaults --core-'.
Program terminated with signal SIGABRT, Aborted.
#0  __pthread_kill (threadid=<optimized out>, signo=signo@entry=6)
    at ../sysdeps/unix/sysv/linux/pthread_kill.c:56
[Current thread is 1 (Thread 0x151bb4147700 (LWP 1478014))]
(gdb) bt
#0  __pthread_kill (threadid=<optimized out>, signo=signo@entry=6) at ../sysdeps/unix/sysv/linux/pthread_kill.c:56
#1  0x0000563141fe80d7 in my_write_core (sig=sig@entry=6) at /test/10.6_dbg/mysys/stacktrace.c:424
#2  0x000056314177cab1 in handle_fatal_signal (sig=6) at /test/10.6_dbg/sql/signal_handler.cc:330
#3  <signal handler called>
#4  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#5  0x0000151bb6502859 in __GI_abort () at abort.c:79
#6  0x0000151bb6502729 in __assert_fail_base (fmt=0x151bb6698588 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x5631422da270 "nr != 0", file=0x5631422d9aff "/test/10.6_dbg/sql/handler.cc", line=3653, function=<optimized out>) at assert.c:92
#7  0x0000151bb6513f36 in __GI___assert_fail (assertion=assertion@entry=0x5631422da270 "nr != 0", file=file@entry=0x5631422d9aff "/test/10.6_dbg/sql/handler.cc", line=line@entry=3653, function=function@entry=0x5631422dbb70 "int handler::update_auto_increment()") at assert.c:101
#8  0x0000563141788a99 in handler::update_auto_increment (this=0x151b64028c10) at /test/10.6_dbg/sql/handler.cc:3653
#9  0x0000563141f75e52 in ha_myisam::write_row (this=0x151b64028c10, buf=0x151b64030b20 "`\n\222\035\017\001\264\031") at /test/10.6_dbg/storage/myisam/ha_myisam.cc:951
#10 0x0000563141790e67 in handler::ha_write_row (this=0x151b64028c10, buf=0x151b64030b20 "`\n\222\035\017\001\264\031") at /test/10.6_dbg/sql/handler.cc:7144
#11 0x00005631418db513 in Log_to_csv_event_handler::log_general (this=<optimized out>, thd=0x151b64000db8, event_time=<optimized out>, user_host=0x151bb4146050 "root[root] @ localhost []", user_host_len=25, thread_id_arg=4, command_type=0x56314215297b "Query", command_type_len=5, sql_text=0x151b640126c0 "INSERT INTO non_existing VALUES (1)", sql_text_len=35, client_cs=0x563142a6a380 <my_charset_utf8mb3_general_ci>) at /test/10.6_dbg/sql/log.cc:813
#12 0x00005631418dde79 in LOGGER::general_log_write (this=this@entry=0x563142ab4720 <logger>, thd=thd@entry=0x151b64000db8, command=command@entry=COM_QUERY, query=query@entry=0x151b640126c0 "INSERT INTO non_existing VALUES (1)", query_length=query_length@entry=35) at /test/10.6_dbg/sql/log.cc:1403
#13 0x00005631418de0b6 in general_log_write (thd=thd@entry=0x151b64000db8, command=command@entry=COM_QUERY, query=0x151b640126c0 "INSERT INTO non_existing VALUES (1)", query_length=35) at /test/10.6_dbg/sql/log.cc:6877
#14 0x00005631414b2103 in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x151b64000db8, packet=packet@entry=0x151b64008d39 "INSERT INTO non_existing VALUES (1)", packet_length=packet_length@entry=35) at /test/10.6_dbg/sql/sql_class.h:1293
#15 0x00005631414b552d in do_command (thd=0x151b64000db8) at /test/10.6_dbg/sql/sql_parse.cc:1348
#16 0x00005631416117fc in do_handle_one_connection (connect=<optimized out>, connect@entry=0x563144ccc9a8, put_in_cache=put_in_cache@entry=true) at /test/10.6_dbg/sql/sql_connect.cc:1410
#17 0x0000563141611f03 in handle_one_connection (arg=arg@entry=0x563144ccc9a8) at /test/10.6_dbg/sql/sql_connect.cc:1312
#18 0x0000563141ac788f in pfs_spawn_thread (arg=0x563144bf4898) at /test/10.6_dbg/storage/perfschema/pfs.cc:2201
#19 0x0000151bb6a10609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#20 0x0000151bb65ff293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Bug confirmed present in:
MariaDB: 10.2.37 (dbg), 10.3.28 (dbg), 10.4.18 (dbg), 10.6.0 (dbg)

Bug (or feature/syntax) confirmed not present in:
MariaDB: 10.2.37 (opt), 10.3.28 (opt), 10.4.18 (opt), 10.5.9 (dbg), 10.5.9 (opt), 10.6.0 (opt)
MySQL: 5.5.62 (dbg), 5.5.62 (opt), 5.6.50 (dbg), 5.6.50 (opt), 5.7.32 (dbg), 5.7.32 (opt), 8.0.22 (dbg), 8.0.22 (opt)

Comment by Roel Van de Paar [ 2021-01-22 ]

Unique ID's seen so far

nr != 0|SIGABRT|handler::update_auto_increment|ha_myisam::write_row|handler::ha_write_row|Log_to_csv_event_handler::log_general 
nr != 0|SIGABRT|handler::update_auto_increment|ha_myisam::write_row|handler::ha_write_row|copy_data_between_tables  
nr != 0|SIGABRT|handler::update_auto_increment|ha_heap::write_row|handler::ha_write_row|copy_data_between_tables 
nr != 0|SIGABRT|handler::update_auto_increment|ha_maria::write_row|handler::ha_write_row|copy_data_between_tables   
nr != 0|SIGABRT|handler::update_auto_increment|ha_innobase::write_row|handler::ha_write_row|copy_data_between_tables
nr != 0|SIGABRT|handler::update_auto_increment|ha_myisam::write_row|handler::ha_write_row|write_record  
nr != 0|SIGABRT|handler::update_auto_increment|ha_heap::write_row|handler::ha_write_row|write_record
nr != 0|SIGABRT|handler::update_auto_increment|ha_maria::write_row|handler::ha_write_row|write_record   
nr != 0|SIGABRT|handler::update_auto_increment|ha_innobase::write_row|handler::ha_write_row|write_record
nr != 0|SIGABRT|handler::update_auto_increment|ha_archive::write_row|handler::ha_write_row|write_record

Comment by Roel Van de Paar [ 2021-01-24 ]

SET SESSION insert_id=-1;
CREATE TABLE t (c INT AUTO_INCREMENT PRIMARY KEY, c2 INT);
INSERT INTO t (c2) VALUES (1);

Comment by Roel Van de Paar [ 2021-02-13 ]

SET SESSION insert_id=FALSE;
INSTALL PLUGIN ARCHIVE SONAME 'ha_archive.so';
CREATE TABLE t (a INT AUTO_INCREMENT,b BLOB,KEY (a)) ENGINE=ARCHIVE;
INSERT INTO t VALUES(0,'');

Leads to:

10.6.0 bfb4761ca04704d68dba51f76d7c9967f880a6ee (Debug)

mysqld: /test/10.6_dbg/sql/handler.cc:3660: int handler::update_auto_increment(): Assertion `nr != 0' failed.

10.6.0 bfb4761ca04704d68dba51f76d7c9967f880a6ee (Debug)

Core was generated by `/test/MD110221-mariadb-10.6.0-linux-x86_64-dbg/bin/mysqld --no-defaults --core-'.
Program terminated with signal SIGABRT, Aborted.
#0  __pthread_kill (threadid=<optimized out>, signo=signo@entry=6)
    at ../sysdeps/unix/sysv/linux/pthread_kill.c:56
[Current thread is 1 (Thread 0x15060c051700 (LWP 4063501))]
(gdb) bt
#0  __pthread_kill (threadid=<optimized out>, signo=signo@entry=6) at ../sysdeps/unix/sysv/linux/pthread_kill.c:56
#1  0x000055e13917755c in my_write_core (sig=sig@entry=6) at /test/10.6_dbg/mysys/stacktrace.c:424
#2  0x000055e13890f4de in handle_fatal_signal (sig=6) at /test/10.6_dbg/sql/signal_handler.cc:330
#3  <signal handler called>
#4  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#5  0x000015060c8b8859 in __GI_abort () at abort.c:79
#6  0x000015060c8b8729 in __assert_fail_base (fmt=0x15060ca4e588 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x55e139470070 "nr != 0", file=0x55e13946f8ff "/test/10.6_dbg/sql/handler.cc", line=3660, function=<optimized out>) at assert.c:92
#7  0x000015060c8c9f36 in __GI___assert_fail (assertion=assertion@entry=0x55e139470070 "nr != 0", file=file@entry=0x55e13946f8ff "/test/10.6_dbg/sql/handler.cc", line=line@entry=3660, function=function@entry=0x55e139471970 "int handler::update_auto_increment()") at assert.c:101
#8  0x000055e13891b419 in handler::update_auto_increment (this=this@entry=0x1505c804f8d0) at /test/10.6_dbg/sql/handler.cc:3660
#9  0x00001505f59e06f6 in ha_archive::write_row (this=0x1505c804f8d0, buf=0x1505c8036a18 "\376") at /test/10.6_dbg/storage/archive/ha_archive.cc:983
#10 0x000055e138923826 in handler::ha_write_row (this=0x1505c804f8d0, buf=0x1505c8036a18 "\376") at /test/10.6_dbg/sql/handler.cc:7151
#11 0x000055e1385f9547 in write_record (thd=thd@entry=0x1505c8000db8, table=table@entry=0x1505c8036588, info=info@entry=0x15060c04fc60, sink=sink@entry=0x0) at /test/10.6_dbg/sql/sql_insert.cc:2106
#12 0x000055e138605c0a in mysql_insert (thd=thd@entry=0x1505c8000db8, table_list=0x1505c80127a0, fields=@0x1505c8005e30: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x55e139c18300 <end_of_list>, last = 0x1505c8005e30, elements = 0}, <No data fields>}, values_list=@0x1505c8005e78: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x1505c8013450, last = 0x1505c8013450, elements = 1}, <No data fields>}, update_fields=@0x1505c8005e60: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x55e139c18300 <end_of_list>, last = 0x1505c8005e60, elements = 0}, <No data fields>}, update_values=@0x1505c8005e48: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x55e139c18300 <end_of_list>, last = 0x1505c8005e48, elements = 0}, <No data fields>}, duplic=DUP_ERROR, ignore=false, result=0x0) at /test/10.6_dbg/sql/sql_insert.cc:1099
#13 0x000055e13864c7a2 in mysql_execute_command (thd=thd@entry=0x1505c8000db8) at /test/10.6_dbg/sql/sql_parse.cc:4453
#14 0x000055e13863721a in mysql_parse (thd=thd@entry=0x1505c8000db8, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x15060c0503d0) at /test/10.6_dbg/sql/sql_parse.cc:7906
#15 0x000055e13864530b in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x1505c8000db8, packet=packet@entry=0x1505c801aac9 "INSERT INTO t VALUES(0,'')", packet_length=packet_length@entry=26) at /test/10.6_dbg/sql/sql_class.h:1295
#16 0x000055e13864863d in do_command (thd=0x1505c8000db8) at /test/10.6_dbg/sql/sql_parse.cc:1365
#17 0x000055e1387a41ab in do_handle_one_connection (connect=<optimized out>, connect@entry=0x55e13b4ae6a8, put_in_cache=put_in_cache@entry=true) at /test/10.6_dbg/sql/sql_connect.cc:1410
#18 0x000055e1387a48af in handle_one_connection (arg=arg@entry=0x55e13b4ae6a8) at /test/10.6_dbg/sql/sql_connect.cc:1312
#19 0x000055e138c5827d in pfs_spawn_thread (arg=0x55e13b3e31f8) at /test/10.6_dbg/storage/perfschema/pfs.cc:2201
#20 0x000015060cdc6609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#21 0x000015060c9b5293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Bug confirmed present in:
MariaDB: 10.2.37 (dbg), 10.3.28 (dbg), 10.4.18 (dbg), 10.5.9 (dbg), 10.6.0 (dbg)

Bug (or feature/syntax) confirmed not present in:
MariaDB: 10.2.37 (opt), 10.3.28 (opt), 10.4.18 (opt), 10.5.9 (opt), 10.6.0 (opt)
MySQL: 5.5.62 (dbg), 5.5.62 (opt), 5.6.51 (dbg), 5.6.51 (opt), 5.7.33 (dbg), 5.7.33 (opt), 8.0.23 (dbg), 8.0.23 (opt)

Comment by Roel Van de Paar [ 2021-02-18 ]

SET SESSION insert_id=0;
CREATE TABLE t (a SERIAL KEY,b INT);
INSERT INTO t (b) VALUES (1);

Leads to:

10.6.0 bfb4761ca04704d68dba51f76d7c9967f880a6ee (Debug)

mysqld: /test/10.6_dbg/sql/handler.cc:3660: int handler::update_auto_increment(): Assertion `nr != 0' failed.

10.6.0 bfb4761ca04704d68dba51f76d7c9967f880a6ee (Debug)

Core was generated by `/test/MD110221-mariadb-10.6.0-linux-x86_64-dbg/bin/mysqld --no-defaults --core-'.
Program terminated with signal SIGABRT, Aborted.
#0  __pthread_kill (threadid=<optimized out>, signo=signo@entry=6)
    at ../sysdeps/unix/sysv/linux/pthread_kill.c:56
[Current thread is 1 (Thread 0x147c200b1700 (LWP 2994100))]
(gdb) bt
#0  __pthread_kill (threadid=<optimized out>, signo=signo@entry=6) at ../sysdeps/unix/sysv/linux/pthread_kill.c:56
#1  0x0000561c887b055c in my_write_core (sig=sig@entry=6) at /test/10.6_dbg/mysys/stacktrace.c:424
#2  0x0000561c87f484de in handle_fatal_signal (sig=6) at /test/10.6_dbg/sql/signal_handler.cc:330
#3  <signal handler called>
#4  __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50
#5  0x0000147c2266d859 in __GI_abort () at abort.c:79
#6  0x0000147c2266d729 in __assert_fail_base (fmt=0x147c22803588 "%s%s%s:%u: %s%sAssertion `%s' failed.\n%n", assertion=0x561c88aa9070 "nr != 0", file=0x561c88aa88ff "/test/10.6_dbg/sql/handler.cc", line=3660, function=<optimized out>) at assert.c:92
#7  0x0000147c2267ef36 in __GI___assert_fail (assertion=assertion@entry=0x561c88aa9070 "nr != 0", file=file@entry=0x561c88aa88ff "/test/10.6_dbg/sql/handler.cc", line=line@entry=3660, function=function@entry=0x561c88aaa970 "int handler::update_auto_increment()") at assert.c:101
#8  0x0000561c87f54419 in handler::update_auto_increment (this=this@entry=0x147bdc025c80) at /test/10.6_dbg/sql/handler.cc:3660
#9  0x0000561c883540a8 in ha_innobase::write_row (this=0x147bdc025c80, record=0x147bdc025818 <incomplete sequence \375>) at /test/10.6_dbg/storage/innobase/handler/ha_innodb.cc:7324
#10 0x0000561c87f5c826 in handler::ha_write_row (this=0x147bdc025c80, buf=0x147bdc025818 <incomplete sequence \375>) at /test/10.6_dbg/sql/handler.cc:7151
#11 0x0000561c87c32547 in write_record (thd=thd@entry=0x147bdc000db8, table=table@entry=0x147bdc022148, info=info@entry=0x147c200afc60, sink=sink@entry=0x0) at /test/10.6_dbg/sql/sql_insert.cc:2106
#12 0x0000561c87c3ec0a in mysql_insert (thd=thd@entry=0x147bdc000db8, table_list=0x147bdc0127a0, fields=@0x147bdc005e30: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x147bdc012fc0, last = 0x147bdc012fc0, elements = 1}, <No data fields>}, values_list=@0x147bdc005e78: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x147bdc013500, last = 0x147bdc013500, elements = 1}, <No data fields>}, update_fields=@0x147bdc005e60: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x561c89251300 <end_of_list>, last = 0x147bdc005e60, elements = 0}, <No data fields>}, update_values=@0x147bdc005e48: {<base_list> = {<Sql_alloc> = {<No data fields>}, first = 0x561c89251300 <end_of_list>, last = 0x147bdc005e48, elements = 0}, <No data fields>}, duplic=DUP_ERROR, ignore=false, result=0x0) at /test/10.6_dbg/sql/sql_insert.cc:1099
#13 0x0000561c87c857a2 in mysql_execute_command (thd=thd@entry=0x147bdc000db8) at /test/10.6_dbg/sql/sql_parse.cc:4453
#14 0x0000561c87c7021a in mysql_parse (thd=thd@entry=0x147bdc000db8, rawbuf=<optimized out>, length=<optimized out>, parser_state=parser_state@entry=0x147c200b03d0) at /test/10.6_dbg/sql/sql_parse.cc:7906
#15 0x0000561c87c7e30b in dispatch_command (command=command@entry=COM_QUERY, thd=thd@entry=0x147bdc000db8, packet=packet@entry=0x147bdc01aac9 "INSERT INTO t (b) VALUES (1)", packet_length=packet_length@entry=28) at /test/10.6_dbg/sql/sql_class.h:1295
#16 0x0000561c87c8163d in do_command (thd=0x147bdc000db8) at /test/10.6_dbg/sql/sql_parse.cc:1365
#17 0x0000561c87ddd1ab in do_handle_one_connection (connect=<optimized out>, connect@entry=0x561c8ac86448, put_in_cache=put_in_cache@entry=true) at /test/10.6_dbg/sql/sql_connect.cc:1410
#18 0x0000561c87ddd8af in handle_one_connection (arg=arg@entry=0x561c8ac86448) at /test/10.6_dbg/sql/sql_connect.cc:1312
#19 0x0000561c8829127d in pfs_spawn_thread (arg=0x561c8ab6b998) at /test/10.6_dbg/storage/perfschema/pfs.cc:2201
#20 0x0000147c22b7b609 in start_thread (arg=<optimized out>) at pthread_create.c:477
#21 0x0000147c2276a293 in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:95

Bug confirmed present in:
MariaDB: 10.2.37 (dbg), 10.3.28 (dbg), 10.4.18 (dbg), 10.5.9 (dbg), 10.6.0 (dbg)

Bug (or feature/syntax) confirmed not present in:
MariaDB: 10.2.37 (opt), 10.3.28 (opt), 10.4.18 (opt), 10.5.9 (opt), 10.6.0 (opt)
MySQL: 5.5.62 (dbg), 5.5.62 (opt), 5.6.51 (dbg), 5.6.51 (opt), 5.7.33 (dbg), 5.7.33 (opt), 8.0.23 (dbg), 8.0.23 (opt)

Comment by Roel Van de Paar [ 2021-08-30 ]

Additional testcase

CREATE TEMPORARY TABLE t0 (id INT AUTO_INCREMENT KEY,a INT,INDEX (a));
SET SESSION insert_id=0;
INSERT INTO t0 (a) VALUES (0),(0),(0),(0);

Comment by Roel Van de Paar [ 2021-09-10 ]

sanja When you have a moment, a fix for this bug would be helpful. Thank you.

Comment by Oleksandr Byelkin [ 2021-09-16 ]

After discussing with Monty we figured out that insert_id shoud not have value of 0 (because 0 and NULL are special values which mean insert next value)

Comment by Oleksandr Byelkin [ 2021-09-17 ]

commit 054dcdbeef649628e3e53cc538f243c55d8e7f87 (HEAD -> bb-10.2-MDEV-22118, origin/bb-10.2-MDEV-22118)
Author: Oleksandr Byelkin <sanja@mariadb.com>
Date:   Thu Sep 16 20:51:22 2021 +0200
 
    MDEV-22118: handler::update_auto_increment(): Assertion `nr != 0' failed. | SIGABRT in handler::update_auto_increment
    
    Changed insert_id default and range to exclude 0 (because it is special value)

Generated at Thu Feb 08 09:12:19 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.