[MDEV-18794] Assertion `!m_innodb' failed in ha_partition::cmp_ref upon SELECT from partitioned table Created: 2019-03-02  Updated: 2023-01-21  Resolved: 2020-05-28

Status: Closed
Project: MariaDB Server
Component/s: Data Definition - Alter Table, Partitioning
Affects Version/s: 10.3, 10.4
Fix Version/s: 10.5.4, 10.3.24, 10.4.14

Type: Bug Priority: Major
Reporter: Elena Stepanova Assignee: Aleksey Midenkov
Resolution: Fixed Votes: 0
Labels: None

Issue Links:
Duplicate
is duplicated by MDEV-17091 Assertion `old_part_id == m_last_part... Closed
Problem/Incident
is caused by MDEV-19751 Wrong partitioning by KEY() after key... Closed
Relates
relates to MDEV-30442 Assertion `!m_innodb' failed in ha_pa... Closed

 Description   

Note: I'm not sure that versioning has anything to do with it, but I couldn't get rid of it in the test case.

--source include/have_innodb.inc
--source include/have_partition.inc
 
CREATE TABLE t1 (pk INT AUTO_INCREMENT, i INT, c CHAR(1), PRIMARY KEY (pk), KEY(i)) 
ENGINE=InnoDB WITH SYSTEM VERSIONING PARTITION BY KEY() PARTITIONS 2;
 
INSERT INTO t1 (i,c) VALUES (1,'a'),(2,'b'),(NULL,'c'),(NULL,'b');
ALTER TABLE t1 DROP SYSTEM VERSIONING;
REPLACE INTO t1 SELECT * FROM t1;
SELECT * FROM t1 WHERE i > 0 OR pk = 1000 LIMIT 1;
 
# Cleanup
DROP TABLE t1;

10.3 82da9855

mysqld: /data/src/10.3/sql/ha_partition.cc:10301: virtual int ha_partition::cmp_ref(const uchar*, const uchar*): Assertion `!m_innodb' failed.
190302 17:15:54 [ERROR] mysqld got signal 6 ;
 
#7  0x00007f2b87fa0ee2 in __assert_fail () from /lib/x86_64-linux-gnu/libc.so.6
#8  0x0000555ad89680ac in ha_partition::cmp_ref (this=0x7f2b2c00d418, ref1=0x7f2b2c05f780 "", ref2=0x7f2b2c183da8 "\001") at /data/src/10.3/sql/ha_partition.cc:10301
#9  0x0000555ad839a1e0 in refpos_order_cmp (arg=0x7f2b2c00d418, a=0x7f2b2c05f780, b=0x7f2b2c183da8) at /data/src/10.3/sql/sql_delete.cc:990
#10 0x0000555ad89a6697 in tree_insert (tree=0x7f2b2c019b58, key=0x7f2b2c183da8, key_size=0, custom_arg=0x7f2b2c00d418) at /data/src/10.3/mysys/tree.c:250
#11 0x0000555ad7fb825a in Unique::unique_add (this=0x7f2b2c0199b8, ptr=0x7f2b2c183da8) at /data/src/10.3/sql/uniques.h:60
#12 0x0000555ad8368b75 in read_keys_and_merge_scans (thd=0x7f2b2c000b00, head=0x7f2b2c0a6c30, quick_selects=..., pk_quick_select=0x7f2b2c172330, read_record=0x7f2b2c172268, intersection=false, filtered_scans=0x0, unique_ptr=0x7f2b2c1721f0) at /data/src/10.3/sql/opt_range.cc:11055
#13 0x0000555ad8368cdf in QUICK_INDEX_MERGE_SELECT::read_keys_and_merge (this=0x7f2b2c1721b0) at /data/src/10.3/sql/opt_range.cc:11086
#14 0x0000555ad8351b79 in QUICK_INDEX_SORT_SELECT::reset (this=0x7f2b2c1721b0) at /data/src/10.3/sql/opt_range.cc:1370
#15 0x0000555ad7f711e2 in join_init_read_record (tab=0x7f2b2c0181d0) at /data/src/10.3/sql/sql_select.cc:20316
#16 0x0000555ad7f6efb8 in sub_select (join=0x7f2b2c015da8, join_tab=0x7f2b2c0181d0, end_of_records=false) at /data/src/10.3/sql/sql_select.cc:19392
#17 0x0000555ad7f6e554 in do_select (join=0x7f2b2c015da8, procedure=0x0) at /data/src/10.3/sql/sql_select.cc:18935
#18 0x0000555ad7f4714d in JOIN::exec_inner (this=0x7f2b2c015da8) at /data/src/10.3/sql/sql_select.cc:4040
#19 0x0000555ad7f4658e in JOIN::exec (this=0x7f2b2c015da8) at /data/src/10.3/sql/sql_select.cc:3834
#20 0x0000555ad7f4782e in mysql_select (thd=0x7f2b2c000b00, tables=0x7f2b2c014f28, wild_num=1, fields=..., conds=0x7f2b2c015bb0, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2147748608, result=0x7f2b2c015d80, unit=0x7f2b2c0049c8, select_lex=0x7f2b2c005138) at /data/src/10.3/sql/sql_select.cc:4239
#21 0x0000555ad7f39754 in handle_select (thd=0x7f2b2c000b00, lex=0x7f2b2c004900, result=0x7f2b2c015d80, setup_tables_done_option=0) at /data/src/10.3/sql/sql_select.cc:385
#22 0x0000555ad7f0418c in execute_sqlcom_select (thd=0x7f2b2c000b00, all_tables=0x7f2b2c014f28) at /data/src/10.3/sql/sql_parse.cc:6551
#23 0x0000555ad7efa7fd in mysql_execute_command (thd=0x7f2b2c000b00) at /data/src/10.3/sql/sql_parse.cc:3772
#24 0x0000555ad7f08145 in mysql_parse (thd=0x7f2b2c000b00, rawbuf=0x7f2b2c014cf8 "SELECT * FROM t1 WHERE i > 0 OR pk = 1000 LIMIT 1", length=49, parser_state=0x7f2b812e65f0, is_com_multi=false, is_next_command=false) at /data/src/10.3/sql/sql_parse.cc:8095
#25 0x0000555ad7ef52f9 in dispatch_command (command=COM_QUERY, thd=0x7f2b2c000b00, packet=0x7f2b2c162281 "", packet_length=49, is_com_multi=false, is_next_command=false) at /data/src/10.3/sql/sql_parse.cc:1854
#26 0x0000555ad7ef3cd1 in do_command (thd=0x7f2b2c000b00) at /data/src/10.3/sql/sql_parse.cc:1396
#27 0x0000555ad805c41f in do_handle_one_connection (connect=0x555adad67bc0) at /data/src/10.3/sql/sql_connect.cc:1403
#28 0x0000555ad805c1a3 in handle_one_connection (arg=0x555adad67bc0) at /data/src/10.3/sql/sql_connect.cc:1309
#29 0x0000555ad84f88b3 in pfs_spawn_thread (arg=0x555adada9480) at /data/src/10.3/storage/perfschema/pfs.cc:1862
#30 0x00007f2b89c77494 in start_thread (arg=0x7f2b812e7700) at pthread_create.c:333
#31 0x00007f2b8805d93f in clone () from /lib/x86_64-linux-gnu/libc.so.6

No obvious effect on a non-debug build.



 Comments   
Comment by Aleksey Midenkov [ 2019-05-31 ]

Reproducible without System versioning

create or replace table t1 (pk int, x timestamp(6), primary key (pk, x)) engine innodb
partition by key() partitions 2;
 
insert into t1 (pk, x) values (1, '2000-01-01 00:00'), (2, '2000-01-01 00:01');
alter table t1 drop primary key, drop column x, add primary key (pk); 
select * from t1 partition (p0);

Result

+----+
| pk |
+----+
|  1 |
|  2 |
+----+

Both records are in p0 which is unacceptable for new partitioning expression.

Expected

Table is repartitioned by pk.

Cause

Empty key() clause implies that key might be changed by ALTER, but inplace algorithm must not be used since repartitioning is required for a different key.

Fix

Prohibit inplace when there is DROP PRIMARY KEY and table is partitioned by key.

More details

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