From d3ea7430152fad48cabd9efb8c80d177405dd090 Mon Sep 17 00:00:00 2001 From: Mattias Jonsson Date: Fri, 10 Oct 2008 12:01:01 +0200 Subject: Bug#37721: ORDER BY when WHERE contains non-partitioned index column There was actually two problems 1) when clustered pk, order by non pk index should also compare with pk as last resort to differ keys from each other 2) bug in the index search handling in ha_partition (was found when extending the test case Solution to 1 was to include the pk in key compare if clustered pk and search on other index. Solution for 2 was to remove the optimization from ordered scan to unordered scan if clustered pk. mysql-test/r/partition_innodb.result: Bug#37721: ORDER BY when WHERE contains non-partitioned index column updated test result. mysql-test/t/partition_innodb.test: Bug#37721: ORDER BY when WHERE contains non-partitioned index column Added test case for bug verification. sql/ha_partition.cc: Bug#37721: ORDER BY when WHERE contains non-partitioned index column using m_curr_key_info with both given index and PK if clustered PK. Also including PK in read_set. Added debug prints for easier verification. sql/ha_partition.h: Bug#37721: ORDER BY when WHERE contains non-partitioned index column Changed m_curr_key_info to a null terminated array with max 2 keys and a terminating null. For use with key_rec_cmp with both given index and PK. sql/key.cc: Bug#37721: ORDER BY when WHERE contains non-partitioned index column added handling of a null terminated array of keys for use in compare. --- sql/ha_partition.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'sql/ha_partition.h') diff --git a/sql/ha_partition.h b/sql/ha_partition.h index 685f057dfce..6e52106dfa5 100644 --- a/sql/ha_partition.h +++ b/sql/ha_partition.h @@ -74,9 +74,16 @@ private: handler **m_added_file; // Added parts kept for errors partition_info *m_part_info; // local reference to partition Field **m_part_field_array; // Part field array locally to save acc - uchar *m_ordered_rec_buffer; // Row and key buffer for ord. idx scan - KEY *m_curr_key_info; // Current index - uchar *m_rec0; // table->record[0] + uchar *m_ordered_rec_buffer; // Row and key buffer for ord. idx scan + /* + Current index. + When used in key_rec_cmp: If clustered pk, index compare + must compare pk if given index is same for two rows. + So normally m_curr_key_info[0]= current index and m_curr_key[1]= NULL, + and if clustered pk, [0]= current index, [1]= pk, [2]= NULL + */ + KEY *m_curr_key_info[3]; // Current index + uchar *m_rec0; // table->record[0] QUEUE m_queue; // Prio queue used by sorted read /* Since the partition handler is a handler on top of other handlers, it -- cgit v1.2.1