Skip to content

Commit

Permalink
MDEV-21134 Crash with partitioned table, PARTITION syntax, and index_…
Browse files Browse the repository at this point in the history
…merge.

When the partition table is cloned, the handlers for the partitions that were not opened
should anyway be created (but not opened).
  • Loading branch information
Alexey Botchkov committed Sep 27, 2022
1 parent 47e9678 commit b2cfcf1
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 5 deletions.
82 changes: 80 additions & 2 deletions mysql-test/main/partition_explicit_prune.result
Original file line number Diff line number Diff line change
Expand Up @@ -1888,7 +1888,7 @@ ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2;
SELECT * FROM t1 PARTITION (p0);
i
UNLOCK TABLES;
DROP TABLE t1;
DROP TABLE t1, t2;
#
# MDEV-18371 Server crashes in ha_innobase::cmp_ref upon UPDATE with PARTITION clause.
#
Expand All @@ -1906,4 +1906,82 @@ a b
4 3
8 2
2 6
DROP TABLE t1, t2;
DROP TABLE t1;
#
# MDEV-21134 Crash with partitioned table, PARTITION syntax, and index_merge.
#
create table t1 (
pk int primary key,
a int,
b int,
filler char(32),
key (a),
key (b)
) engine=myisam partition by range(pk) (
partition p0 values less than (10),
partition p1 values less than MAXVALUE
) ;
insert into t1 select
seq,
MOD(seq, 100),
MOD(seq, 100),
'filler-data-filler-data'
from
seq_1_to_5000;
explain select * from t1 partition (p1) where a=10 and b=10;
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE t1 index_merge a,b a,b 5,5 NULL 1 Using intersect(a,b); Using where
flush tables;
select * from t1 partition (p1)where a=10 and b=10;
pk a b filler
10 10 10 filler-data-filler-data
110 10 10 filler-data-filler-data
210 10 10 filler-data-filler-data
310 10 10 filler-data-filler-data
410 10 10 filler-data-filler-data
510 10 10 filler-data-filler-data
610 10 10 filler-data-filler-data
710 10 10 filler-data-filler-data
810 10 10 filler-data-filler-data
910 10 10 filler-data-filler-data
1010 10 10 filler-data-filler-data
1110 10 10 filler-data-filler-data
1210 10 10 filler-data-filler-data
1310 10 10 filler-data-filler-data
1410 10 10 filler-data-filler-data
1510 10 10 filler-data-filler-data
1610 10 10 filler-data-filler-data
1710 10 10 filler-data-filler-data
1810 10 10 filler-data-filler-data
1910 10 10 filler-data-filler-data
2010 10 10 filler-data-filler-data
2110 10 10 filler-data-filler-data
2210 10 10 filler-data-filler-data
2310 10 10 filler-data-filler-data
2410 10 10 filler-data-filler-data
2510 10 10 filler-data-filler-data
2610 10 10 filler-data-filler-data
2710 10 10 filler-data-filler-data
2810 10 10 filler-data-filler-data
2910 10 10 filler-data-filler-data
3010 10 10 filler-data-filler-data
3110 10 10 filler-data-filler-data
3210 10 10 filler-data-filler-data
3310 10 10 filler-data-filler-data
3410 10 10 filler-data-filler-data
3510 10 10 filler-data-filler-data
3610 10 10 filler-data-filler-data
3710 10 10 filler-data-filler-data
3810 10 10 filler-data-filler-data
3910 10 10 filler-data-filler-data
4010 10 10 filler-data-filler-data
4110 10 10 filler-data-filler-data
4210 10 10 filler-data-filler-data
4310 10 10 filler-data-filler-data
4410 10 10 filler-data-filler-data
4510 10 10 filler-data-filler-data
4610 10 10 filler-data-filler-data
4710 10 10 filler-data-filler-data
4810 10 10 filler-data-filler-data
4910 10 10 filler-data-filler-data
DROP TABLE t1;
34 changes: 31 additions & 3 deletions mysql-test/main/partition_explicit_prune.test
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
--source include/have_innodb.inc
--source include/have_partition.inc
--source include/have_sequence.inc

# Helper statement
let $get_handler_status_counts= SELECT * FROM INFORMATION_SCHEMA.SESSION_STATUS
Expand Down Expand Up @@ -874,7 +875,7 @@ SELECT * FROM t1 PARTITION (p0);
ALTER TABLE t1 EXCHANGE PARTITION p0 WITH TABLE t2;
SELECT * FROM t1 PARTITION (p0);
UNLOCK TABLES;
DROP TABLE t1;
DROP TABLE t1, t2;

--echo #
--echo # MDEV-18371 Server crashes in ha_innobase::cmp_ref upon UPDATE with PARTITION clause.
Expand All @@ -885,7 +886,34 @@ INSERT INTO t1 VALUES (3,0),(8,2),(7,8),(3,4),(2,4),(0,7),(4,3),(3,6);
FLUSH TABLES;
UPDATE t1 PARTITION (p3,p1) SET a = 2 WHERE a = 3;
SELECT * FROM t1;
DROP TABLE t1;

--echo #
--echo # MDEV-21134 Crash with partitioned table, PARTITION syntax, and index_merge.
--echo #

create table t1 (
pk int primary key,
a int,
b int,
filler char(32),
key (a),
key (b)
) engine=myisam partition by range(pk) (
partition p0 values less than (10),
partition p1 values less than MAXVALUE
) ;

insert into t1 select
seq,
MOD(seq, 100),
MOD(seq, 100),
'filler-data-filler-data'
from
seq_1_to_5000;

explain select * from t1 partition (p1) where a=10 and b=10;
flush tables;
select * from t1 partition (p1)where a=10 and b=10;

# Cleanup
DROP TABLE t1, t2;
DROP TABLE t1;
15 changes: 15 additions & 0 deletions sql/ha_partition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3637,7 +3637,22 @@ int ha_partition::open(const char *name, int mode, uint test_if_locked)
for (i= 0; i < m_tot_parts; i++)
{
if (!bitmap_is_set(&m_is_clone_of->m_opened_partitions, i))
{
/* Here we should just create the handler instance, not open it. */
if (!(m_file[i]= get_new_handler(table->s, m_clone_mem_root,
file[i]->ht)))
{
error= HA_ERR_INITIALIZATION;
file= &m_file[i];
goto err_handler;
}
if (m_file[i]->set_ha_share_ref(file[i]->ha_share))
{
error= HA_ERR_INITIALIZATION;
goto err_handler;
}
continue;
}

if (unlikely((error= create_partition_name(name_buff, sizeof(name_buff),
name, name_buffer_ptr,
Expand Down

0 comments on commit b2cfcf1

Please sign in to comment.