Skip to content

Commit fb8b793

Browse files
author
Mattias Jonsson
committed
Bug#18383840: SEGV IN MEMCPY(), HA_PARTITION::POSITION
post-push fix for: Regression from bug#18167648: WRONG RESULTS WITH PARTITIONING, INDEX_MERGE MYISAM AND NO PK INNODB The priority queue is setup in ha_partition::index_init() and also sets m_sec_sort_by_rowid. But in case the index scan is only done on one partition, due to pruning, the priority queue will not be used and the ref will not be copied into the priority queue. So only checking m_sec_sort_by_rowid is not enough to ensure that the ref is accessible. Fixed by checking that ordered scan is used.
1 parent c87c177 commit fb8b793

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

mysql-test/r/partition_index_innodb.result

+6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ a b c
3434
2 2 17
3535
2 2 20
3636
2 2 25
37+
EXPLAIN PARTITIONS SELECT a,b,c FROM t1 WHERE a = 2 AND b = 2 AND c IN (13,25,28);
38+
id select_type table partitions type possible_keys key key_len ref rows Extra
39+
1 SIMPLE t1 p1 index_merge a,b a,b 3,3 NULL 1 Using intersect(a,b); Using where
40+
SELECT a,b,c FROM t1 WHERE a = 2 AND b = 2 AND c IN (13,25,28);
41+
a b c
42+
2 2 25
3743
SET SESSION optimizer_switch="index_merge_intersection=off";
3844
SELECT a,b,c FROM t1 WHERE b = 2 AND a = 2 AND c > 0 AND c < 100;
3945
a b c

mysql-test/t/partition_index_innodb.test

+2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ SELECT TRACE FROM INFORMATION_SCHEMA.OPTIMIZER_TRACE;
6262
# No more match...
6363

6464
SELECT a,b,c FROM t1 WHERE b = 2 AND a = 2 AND c > 0 AND c < 100;
65+
EXPLAIN PARTITIONS SELECT a,b,c FROM t1 WHERE a = 2 AND b = 2 AND c IN (13,25,28);
66+
SELECT a,b,c FROM t1 WHERE a = 2 AND b = 2 AND c IN (13,25,28);
6567
SET SESSION optimizer_switch="index_merge_intersection=off";
6668
SELECT a,b,c FROM t1 WHERE b = 2 AND a = 2 AND c > 0 AND c < 100;
6769
EXPLAIN SELECT a,b,c FROM t1 WHERE b = 2 AND a = 2 AND c > 0 AND c < 100;

sql/ha_partition.cc

+6-2
Original file line numberDiff line numberDiff line change
@@ -4785,9 +4785,13 @@ void ha_partition::position(const uchar *record)
47854785
DBUG_ENTER("ha_partition::position");
47864786

47874787
int2store(ref, m_last_part);
4788-
if (m_sec_sort_by_rowid)
4788+
/*
4789+
If m_sec_sort_by_rowid is set, then the ref is already stored in the
4790+
priority queue (m_queue) when doing ordered scans.
4791+
*/
4792+
if (m_sec_sort_by_rowid && m_ordered_scan_ongoing)
47894793
{
4790-
DBUG_ASSERT(m_ordered_scan_ongoing);
4794+
DBUG_ASSERT(m_queue.elements);
47914795
DBUG_ASSERT(m_ordered_rec_buffer);
47924796
DBUG_ASSERT(!m_curr_key_info[1]);
47934797
/* We already have the ref. */

0 commit comments

Comments
 (0)