[MDEV-18719] Assertion `!((c.prtype ^ o->prtype) & ~(256U | (16384U|32768U)))' failed in dict_table_t::instant_column Created: 2019-02-24  Updated: 2020-01-21  Resolved: 2019-02-25

Status: Closed
Project: MariaDB Server
Component/s: Data Definition - Alter Table, Storage Engine - InnoDB
Affects Version/s: 10.4
Fix Version/s: 10.4.4

Type: Bug Priority: Major
Reporter: Elena Stepanova Assignee: Marko Mäkelä
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Problem/Incident
is caused by MDEV-15563 Instant failure-free data type conver... Closed
Relates
relates to MDEV-21539 Assertion `!((new_col->prtype ^ col->... Closed

 Description   

--source include/have_innodb.inc
 
CREATE TABLE t1 (PK INT, f VARCHAR(8), PRIMARY KEY (pk)) ENGINE=InnoDB;
ALTER TABLE t1 MODIFY f VARCHAR(256) FIRST;
 
# Cleanup
DROP TABLE t1;

10.4 fb01193c

mysqld: /data/src/10.4/storage/innobase/handler/handler0alter.cc:539: bool dict_table_t::instant_column(const dict_table_t&, const ulint*): Assertion `!((c.prtype ^ o->prtype) & ~(256U | (16384U|32768U)))' failed.
190224 18:41:46 [ERROR] mysqld got signal 6 ;
 
#7  0x00007f359676eee2 in __assert_fail () from /lib/x86_64-linux-gnu/libc.so.6
#8  0x0000564baf6c140d in dict_table_t::instant_column (this=0x7f353c00dd58, table=..., col_map=0x7f353c15d018) at /data/src/10.4/storage/innobase/handler/handler0alter.cc:538
#9  0x0000564baf6c40dd in ha_innobase_inplace_ctx::instant_column (this=0x7f353c016cb8) at /data/src/10.4/storage/innobase/handler/handler0alter.cc:1081
#10 0x0000564baf6a99ca in innobase_instant_try (ha_alter_info=0x7f35902e4900, ctx=0x7f353c016cb8, altered_table=0x7f353c153460, table=0x7f353c1a2fb0, trx=0x7f359057f268) at /data/src/10.4/storage/innobase/handler/handler0alter.cc:5507
#11 0x0000564baf6c7194 in commit_try_norebuild (ha_alter_info=0x7f35902e4900, ctx=0x7f353c016cb8, altered_table=0x7f353c153460, old_table=0x7f353c1a2fb0, trx=0x7f359057f268, table_name=0x7f353c1a1195 "t1") at /data/src/10.4/storage/innobase/handler/handler0alter.cc:10154
#12 0x0000564baf6b90d8 in ha_innobase::commit_inplace_alter_table (this=0x7f353c1a3e18, altered_table=0x7f353c153460, ha_alter_info=0x7f35902e4900, commit=true) at /data/src/10.4/storage/innobase/handler/handler0alter.cc:10823
#13 0x0000564baf33571e in handler::ha_commit_inplace_alter_table (this=0x7f353c1a3e18, altered_table=0x7f353c153460, ha_alter_info=0x7f35902e4900, commit=true) at /data/src/10.4/sql/handler.cc:4678
#14 0x0000564baf0cbcff in mysql_inplace_alter_table (thd=0x7f353c000b00, table_list=0x7f353c0155b0, table=0x7f353c1a2fb0, altered_table=0x7f353c153460, ha_alter_info=0x7f35902e4900, inplace_supported=HA_ALTER_INPLACE_INSTANT, target_mdl_request=0x7f35902e4b30, alter_ctx=0x7f35902e50e0) at /data/src/10.4/sql/sql_table.cc:7692
#15 0x0000564baf0d2373 in mysql_alter_table (thd=0x7f353c000b00, new_db=0x7f353c005290, new_name=0x7f353c005690, create_info=0x7f35902e5cd0, table_list=0x7f353c0155b0, alter_info=0x7f35902e5c10, order_num=0, order=0x0, ignore=false) at /data/src/10.4/sql/sql_table.cc:9919
#16 0x0000564baf160922 in Sql_cmd_alter_table::execute (this=0x7f353c015d88, thd=0x7f353c000b00) at /data/src/10.4/sql/sql_alter.cc:499
#17 0x0000564baeff1aca in mysql_execute_command (thd=0x7f353c000b00) at /data/src/10.4/sql/sql_parse.cc:6346
#18 0x0000564baeff6c72 in mysql_parse (thd=0x7f353c000b00, rawbuf=0x7f353c0154a8 "ALTER TABLE t1 MODIFY f VARCHAR(256) FIRST", length=42, parser_state=0x7f35902e7180, is_com_multi=false, is_next_command=false) at /data/src/10.4/sql/sql_parse.cc:8157
#19 0x0000564baefe2360 in dispatch_command (command=COM_QUERY, thd=0x7f353c000b00, packet=0x7f353c13a181 "ALTER TABLE t1 MODIFY f VARCHAR(256) FIRST", packet_length=42, is_com_multi=false, is_next_command=false) at /data/src/10.4/sql/sql_parse.cc:1829
#20 0x0000564baefe0b34 in do_command (thd=0x7f353c000b00) at /data/src/10.4/sql/sql_parse.cc:1358
#21 0x0000564baf15a837 in do_handle_one_connection (connect=0x564bb1938d10) at /data/src/10.4/sql/sql_connect.cc:1399
#22 0x0000564baf15a5a8 in handle_one_connection (arg=0x564bb1938d10) at /data/src/10.4/sql/sql_connect.cc:1302
#23 0x0000564baf651979 in pfs_spawn_thread (arg=0x564bb197eb80) at /data/src/10.4/storage/perfschema/pfs.cc:1862
#24 0x00007f3598445494 in start_thread (arg=0x7f35902e8700) at pthread_create.c:333
#25 0x00007f359682b93f in clone () from /lib/x86_64-linux-gnu/libc.so.6

Not reproducible on 10.3.
No obvious effect on a non-debug build.

Note:
When the same test case is run on a build with DDBUG_ASSERT_AS_PRINTF, two assertion failures are reported. The first one is apparently the same as above, just in a different form:

Warning: assertion failed: !((c.prtype ^ o->prtype) & ~(DATA_NOT_NULL | DATA_VERSIONED)) at /data/src/10.4-bug/storage/innobase/handler/handler0alter.cc line 539

and after that another one:

10.4 31b65d3d

Warning: assertion failed: !old || col->same_format(*old) at /data/src/10.4-bug/storage/innobase/handler/handler0alter.cc line 5598
Attempting backtrace to find out the reason for the assert:
stack_bottom = 0x0 thread_stack 0x49000
mysys/stacktrace.c:270(my_print_stacktrace)[0x55ca9ef64269]
handler/handler0alter.cc:5598(innobase_instant_try(Alter_inplace_info const*, ha_innobase_inplace_ctx*, TABLE const*, TABLE const*, trx_t*) [clone .isra.201])[0x55ca9e738bc9]
handler/handler0alter.cc:10154(commit_try_norebuild)[0x55ca9ecbc71f]
sql/sql_table.cc:7692(mysql_inplace_alter_table(THD*, TABLE_LIST*, TABLE*, TABLE*, Alter_inplace_info*, enum_alter_inplace_result, MDL_request*, Alter_table_ctx*) [clone .isra.168])[0x55ca9e73216c]
sql/sql_table.cc:9919(mysql_alter_table(THD*, st_mysql_const_lex_string const*, st_mysql_const_lex_string const*, HA_CREATE_INFO*, TABLE_LIST*, Alter_info*, unsigned int, st_order*, bool))[0x55ca9e8cec49]
sql/sql_alter.cc:499(Sql_cmd_alter_table::execute(THD*))[0x55ca9e922cb2]
sql/sql_parse.cc:6346(mysql_execute_command(THD*))[0x55ca9e83182f]
sql/sql_parse.cc:8174(mysql_parse(THD*, char*, unsigned int, Parser_state*, bool, bool))[0x55ca9e839610]
sql/sql_parse.cc:1893(dispatch_command(enum_server_command, THD*, char*, unsigned int, bool, bool))[0x55ca9e83c2b5]
sql/sql_parse.cc:1359(do_command(THD*))[0x55ca9e83d392]
sql/sql_connect.cc:1399(do_handle_one_connection(CONNECT*))[0x55ca9e91fd7c]
sql/sql_connect.cc:1304(handle_one_connection)[0x55ca9e91fee4]
perfschema/pfs.cc:1865(pfs_spawn_thread)[0x55ca9ec810f4]
nptl/pthread_create.c:333(start_thread)[0x7fa811b25494]
x86_64/clone.S:99(clone)[0x7fa80ff0b93f]



 Comments   
Comment by Marko Mäkelä [ 2019-02-25 ]

The ha_alter_info->handler_flags seem OK to me:

ha_alter_info->handler_flags =
ALTER_STORED_COLUMN_ORDER |
ALTER_COLUMN_EQUAL_PACK_LENGTH |
ALTER_CHANGE_COLUMN_DEFAULT;

The DATA_LONG_TRUE_VARCHAR flag is not set on the old column’s prtype, but it is set on the new copy of the column. The reason for this seems to be that this flag would only be set when Field_varstring::length_bytes is 2. For VARCHAR(8) it would probably be 1.

It looks like we should ignore that flag when comparing the metadata. This should be a bogus debug assertion.
The following patch should fix this:

diff --git a/storage/innobase/handler/handler0alter.cc b/storage/innobase/handler/handler0alter.cc
index 23e7eda8b66..8102060414b 100644
--- a/storage/innobase/handler/handler0alter.cc
+++ b/storage/innobase/handler/handler0alter.cc
@@ -536,7 +536,8 @@ inline bool dict_table_t::instant_column(const dict_table_t& table,
 		if (const dict_col_t* o = find(old_cols, col_map, n_cols, i)) {
 			c.def_val = o->def_val;
 			DBUG_ASSERT(!((c.prtype ^ o->prtype)
-				      & ~(DATA_NOT_NULL | DATA_VERSIONED)));
+				      & ~(DATA_NOT_NULL | DATA_VERSIONED
+					  | DATA_LONG_TRUE_VARCHAR)));
 			DBUG_ASSERT(c.mtype == o->mtype);
 			DBUG_ASSERT(c.len >= o->len);
 
diff --git a/storage/innobase/include/dict0mem.h b/storage/innobase/include/dict0mem.h
index 11e150c4f78..9f76728e6cf 100644
--- a/storage/innobase/include/dict0mem.h
+++ b/storage/innobase/include/dict0mem.h
@@ -693,7 +693,8 @@ struct dict_col_t{
 			&& mbminlen == other.mbminlen
 			&& mbmaxlen == other.mbmaxlen
 			&& !((prtype ^ other.prtype)
-			     & ~(DATA_NOT_NULL | DATA_VERSIONED));
+			     & ~(DATA_NOT_NULL | DATA_VERSIONED
+				 | DATA_LONG_TRUE_VARCHAR));
 	}
 };
 

Comment by Marko Mäkelä [ 2019-02-25 ]

This was a too strict debug assertion. No impact on non-debug buids.

Generated at Thu Feb 08 08:46:13 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.