Details
-
Bug
-
Status: Closed (View Workflow)
-
Critical
-
Resolution: Fixed
-
10.0.27, 10.1.26, 10.0(EOL), 10.1(EOL), 10.2(EOL)
-
10.2.10
Description
After altering a partitioned table, some queries can return invalid results.
To reproduce, first create a partitioned table and insert some data:
drop table if exists t;
|
|
CREATE TABLE `t` (
|
`id` bigint(20) unsigned NOT NULL auto_increment,
|
`d` date NOT NULL,
|
`a` bigint(20) unsigned NOT NULL,
|
`b` smallint(5) unsigned DEFAULT NULL,
|
PRIMARY KEY (`id`,`d`)
|
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_general_cs STATS_SAMPLE_PAGES=200
|
/*!50500 PARTITION BY RANGE COLUMNS(d)
|
(PARTITION p20170913 VALUES LESS THAN ('2017-09-14') ENGINE = InnoDB,
|
PARTITION p20170914 VALUES LESS THAN ('2017-09-15') ENGINE = InnoDB,
|
PARTITION p20170915 VALUES LESS THAN ('2017-09-16') ENGINE = InnoDB,
|
PARTITION p20170916 VALUES LESS THAN ('2017-09-17') ENGINE = InnoDB,
|
PARTITION p20170917 VALUES LESS THAN ('2017-09-18') ENGINE = InnoDB,
|
PARTITION p99991231 VALUES LESS THAN (MAXVALUE) ENGINE = InnoDB) */;
|
|
insert into t(d,a,b) values ('2017-09-15',rand()*10000,rand()*10);
|
insert into t(d,a,b) values ('2017-09-15',rand()*10000,rand()*10);
|
|
replace into t(d,a,b) select '2017-09-15',rand()*10000,rand()*10 from t t1, t t2, t t3, t t4, t t5, t t6, t t7, t t8, t t9, t t10, t t11, t t12, t t13, t t14;
|
We can see that the table has over 16k rows:
MariaDB [db1]> select count(*) from t where d ='2017-09-15';
|
+----------+
|
| count(*) |
|
+----------+
|
| 16386 |
|
+----------+
|
1 row in set (0.00 sec)
|
But things break if we alter the table:
ALTER TABLE t CHANGE b c smallint(5) unsigned , ADD KEY idx_d_a (d, a);
|
analyze table t;
|
Now that the table has been altered, let's compare the output of these two queries:
select count(*) from t where d ='2017-09-15';
|
select count(*) from t force index(primary) where d ='2017-09-15';
|
Here's the actual output:
MariaDB [db1]> select count(*) from t where d ='2017-09-15';
|
+----------+
|
| count(*) |
|
+----------+
|
| 0 |
|
+----------+
|
1 row in set (0.00 sec)
|
|
MariaDB [db1]> select count(*) from t force index(primary) where d ='2017-09-15';
|
+----------+
|
| count(*) |
|
+----------+
|
| 16386 |
|
+----------+
|
1 row in set (0.00 sec)
|
We can see that output for the first query is incorrect.
Rebuilding the table seems to fix it:
MariaDB [db1]> alter table t engine = InnoDB;
|
Query OK, 0 rows affected (0.24 sec)
|
Records: 0 Duplicates: 0 Warnings: 0
|
|
MariaDB [db1]> select count(*) from t where d ='2017-09-15';
|
+----------+
|
| count(*) |
|
+----------+
|
| 16386 |
|
+----------+
|
1 row in set (0.00 sec)
|
Attachments
Issue Links
- relates to
-
MDEV-7367 Updating a virtual column corrupts table which crashes server
-
- Closed
-
-
MDEV-9469 'Incorrect key file' on ALTER TABLE
-
- Closed
-
-
MDEV-10535 ALTER TABLE causes standalone/wsrep cluster crash
-
- Closed
-
-
MDEV-13668 InnoDB unnecessarily rebuilds table when renaming a column and adding index
-
- Closed
-
-
MDEV-13671 InnoDB should use case-insensitive column name comparisons like the rest of the server
-
- Closed
-
Reproducible on 10.x.
Not reproducible on MySQL 5.6, 5.7, MariaDB 5.5.
The same test case suitable for MTR
--source include/have_innodb.inc
--source include/have_partition.inc
/*!50500 PARTITION BY RANGE COLUMNS(d)
(PARTITION p20170913 VALUES LESS THAN ('2017-09-14') ENGINE = InnoDB,
PARTITION p20170914 VALUES LESS THAN ('2017-09-15') ENGINE = InnoDB,
PARTITION p20170915 VALUES LESS THAN ('2017-09-16') ENGINE = InnoDB,
PARTITION p20170916 VALUES LESS THAN ('2017-09-17') ENGINE = InnoDB,
PARTITION p20170917 VALUES LESS THAN ('2017-09-18') ENGINE = InnoDB,
# Cleanup
Release builds produce a wrong result as described. Debug builds fail with the assertion failure:
10.0 a870099817
2017-09-19 02:19:19 7ff78f817700 InnoDB: Warning: using a partial-field key prefix in search.
InnoDB: index `idx_d_a` of table `test`.`t` /* Partition `p20170915` */. Last data field length 8 bytes,
InnoDB: key ptr now exceeds key end by 5 bytes.
InnoDB: Key value in the MySQL format:
len 3; hex 2fc30f; asc / ;
2017-09-19 02:19:19 7ff78f817700 InnoDB: Assertion failure in thread 140701241276160 in file row0sel.cc line 2497
InnoDB: Failing assertion: 0
#5 0x00007ff78d4eb3fa in abort () from /lib/x86_64-linux-gnu/libc.so.6
#6 0x00007ff786060fdc in row_sel_convert_mysql_key_to_innobase (tuple=0x7ff779415278, buf=0x7ff7797b03f0 "", buf_len=11, index=0x7ff7795d10f8, key_ptr=0x7ff779798118 "\245\245\245\245\245\245\245\245/\303\017", '\245' <repeats 13 times>, "\003", key_len=3, trx=0x7ff779552278) at /data/src/10.0/storage/innobase/row/row0sel.cc:2497
#7 0x00007ff785f4d88e in ha_innodb::records_in_range (this=0x7ff779566288, keynr=1, min_key=0x7ff78f814020, max_key=0x7ff78f814040) at /data/src/10.0/storage/innobase/handler/ha_innodb.cc:11141
#8 0x0000000000df43ab in ha_partition::records_in_range (this=0x7ff77950b088, inx=1, min_key=0x7ff78f814020, max_key=0x7ff78f814040) at /data/src/10.0/sql/ha_partition.cc:7645
#9 0x00000000007a4eba in handler::multi_range_read_info_const (this=0x7ff77950b088, keyno=1, seq=0x7ff78f814120, seq_init_param=0x7ff78f814150, n_ranges_arg=0, bufsz=0x7ff78f814730, flags=0x7ff78f814734, cost=0x7ff78f814700) at /data/src/10.0/sql/multi_range_read.cc:94
#10 0x000000000095b7c3 in check_quick_select (param=0x7ff78f8149d0, idx=0, index_only=true, tree=0x7ff779798390, update_tbl_stats=true, mrr_flags=0x7ff78f814734, bufsize=0x7ff78f814730, cost=0x7ff78f814700) at /data/src/10.0/sql/opt_range.cc:10748
#11 0x00000000009543ba in get_key_scans_params (param=0x7ff78f8149d0, tree=0x7ff779798130, index_read_must_be_used=false, update_tbl_stats=true, read_time=3434.5177501826147) at /data/src/10.0/sql/opt_range.cc:7369
#12 0x000000000094b74e in SQL_SELECT::test_quick_select (this=0x7ff7795f3088, thd=0x7ff781b69070, keys_to_use=..., prev_tables=0, limit=18446744073709551615, force_quick_range=false, ordered_output=false) at /data/src/10.0/sql/opt_range.cc:3184
#13 0x0000000000688d36 in get_quick_record_count (thd=0x7ff781b69070, select=0x7ff7795f3088, table=0x7ff7795c9070, keys=0x7ff7794fb788, limit=18446744073709551615) at /data/src/10.0/sql/sql_select.cc:3355
#14 0x000000000068adcf in make_join_statistics (join=0x7ff7794fad88, tables_list=..., conds=0x7ff7794fb3e0, keyuse_array=0x7ff7794fb0b0) at /data/src/10.0/sql/sql_select.cc:3963
#15 0x0000000000681ded in JOIN::optimize_inner (this=0x7ff7794fad88) at /data/src/10.0/sql/sql_select.cc:1345
#16 0x0000000000680ce6 in JOIN::optimize (this=0x7ff7794fad88) at /data/src/10.0/sql/sql_select.cc:1029
#17 0x0000000000688ab1 in mysql_select (thd=0x7ff781b69070, rref_pointer_array=0x7ff781b6d388, tables=0x7ff7794fa388, wild_num=0, fields=..., conds=0x7ff7794fab58, og_num=0, order=0x0, group=0x0, having=0x0, proc_param=0x0, select_options=2147748608, result=0x7ff7794fad68, unit=0x7ff781b6ca08, select_lex=0x7ff781b6d0f8) at /data/src/10.0/sql/sql_select.cc:3304
#18 0x000000000067ee2e in handle_select (thd=0x7ff781b69070, lex=0x7ff781b6c940, result=0x7ff7794fad68, setup_tables_done_option=0) at /data/src/10.0/sql/sql_select.cc:373
#19 0x000000000065355a in execute_sqlcom_select (thd=0x7ff781b69070, all_tables=0x7ff7794fa388) at /data/src/10.0/sql/sql_parse.cc:5302
#20 0x000000000064bae5 in mysql_execute_command (thd=0x7ff781b69070) at /data/src/10.0/sql/sql_parse.cc:2562
#21 0x00000000006561da in mysql_parse (thd=0x7ff781b69070, rawbuf=0x7ff7794fa088 "select count(*) from t where d ='2017-09-15'", length=44, parser_state=0x7ff78f816640) at /data/src/10.0/sql/sql_parse.cc:6578
#22 0x0000000000648d07 in dispatch_command (command=COM_QUERY, thd=0x7ff781b69070, packet=0x7ff7875ef071 "select count(*) from t where d ='2017-09-15'", packet_length=44) at /data/src/10.0/sql/sql_parse.cc:1305
#23 0x0000000000648021 in do_command (thd=0x7ff781b69070) at /data/src/10.0/sql/sql_parse.cc:999
#24 0x0000000000767cd8 in do_handle_one_connection (thd_arg=0x7ff781b69070) at /data/src/10.0/sql/sql_connect.cc:1377
#25 0x0000000000767a4a in handle_one_connection (arg=0x7ff781b69070) at /data/src/10.0/sql/sql_connect.cc:1292
#26 0x0000000000ac7cfa in pfs_spawn_thread (arg=0x7ff781b19670) at /data/src/10.0/storage/perfschema/pfs.cc:1860
#27 0x00007ff78f454494 in start_thread (arg=0x7ff78f817700) at pthread_create.c:333
#28 0x00007ff78d59f93f in clone () from /lib/x86_64-linux-gnu/libc.so.6
The test case is related to
MDEV-10535(possibly the underlying problem also is). 10.0.23 works all right. 10.0.24-26 fail withMDEV-10535. 10.0.27+ fail as described here.