Commit 0494d585 authored by Mattias Jonsson's avatar Mattias Jonsson

Bug#30573: Ordered range scan over partitioned tables returns some rows twice

and
Bug#33555: Group By Query does not correctly aggregate partitions

Backport of bug-33257 which is the same bug.

read_range_*() calls was not passed to the partition handlers,
but was translated to index_read/next family calls.
Resulting in duplicates rows and wrong aggregations.
parent cb8a39e7
...@@ -742,3 +742,23 @@ WHERE (a >= '2004-07-01' AND a <= '2004-09-30') OR ...@@ -742,3 +742,23 @@ WHERE (a >= '2004-07-01' AND a <= '2004-09-30') OR
id select_type table partitions type possible_keys key key_len ref rows Extra id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 p407,p408,p409,p507,p508,p509 ALL NULL NULL NULL NULL 18 Using where 1 SIMPLE t1 p407,p408,p409,p507,p508,p509 ALL NULL NULL NULL NULL 18 Using where
DROP TABLE t1; DROP TABLE t1;
create table t1 (a int);
insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
CREATE TABLE t2 (
defid int(10) unsigned NOT NULL,
day int(10) unsigned NOT NULL,
count int(10) unsigned NOT NULL,
filler char(200),
KEY (defid,day)
)
PARTITION BY RANGE (day) (
PARTITION p7 VALUES LESS THAN (20070401) ,
PARTITION p8 VALUES LESS THAN (20070501));
insert into t2 select 20, 20070311, 1, 'filler' from t1 A, t1 B;
insert into t2 select 20, 20070411, 1, 'filler' from t1 A, t1 B;
insert into t2 values(52, 20070321, 123, 'filler') ;
insert into t2 values(52, 20070322, 456, 'filler') ;
select sum(count) from t2 ch where ch.defid in (50,52) and ch.day between 20070320 and 20070401 group by defid;
sum(count)
579
drop table t1, t2;
...@@ -807,24 +807,24 @@ DROP TABLE t1; ...@@ -807,24 +807,24 @@ DROP TABLE t1;
# #
# BUG#30573: get wrong result with "group by" on PARTITIONed table # BUG#30573: get wrong result with "group by" on PARTITIONed table
# #
#create table t1 (a int); create table t1 (a int);
#insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9); insert into t1 values (0),(1),(2),(3),(4),(5),(6),(7),(8),(9);
#CREATE TABLE t2 ( CREATE TABLE t2 (
# defid int(10) unsigned NOT NULL, defid int(10) unsigned NOT NULL,
# day int(10) unsigned NOT NULL, day int(10) unsigned NOT NULL,
# count int(10) unsigned NOT NULL, count int(10) unsigned NOT NULL,
# filler char(200), filler char(200),
# KEY (defid,day) KEY (defid,day)
#) )
#PARTITION BY RANGE (day) ( PARTITION BY RANGE (day) (
# PARTITION p7 VALUES LESS THAN (20070401) , PARTITION p7 VALUES LESS THAN (20070401) ,
# PARTITION p8 VALUES LESS THAN (20070501)); PARTITION p8 VALUES LESS THAN (20070501));
#insert into t2 select 20, 20070311, 1, 'filler' from t1 A, t1 B; insert into t2 select 20, 20070311, 1, 'filler' from t1 A, t1 B;
#insert into t2 select 20, 20070411, 1, 'filler' from t1 A, t1 B; insert into t2 select 20, 20070411, 1, 'filler' from t1 A, t1 B;
#insert into t2 values(52, 20070321, 123, 'filler') ; insert into t2 values(52, 20070321, 123, 'filler') ;
#insert into t2 values(52, 20070322, 456, 'filler') ; insert into t2 values(52, 20070322, 456, 'filler') ;
#select sum(count) from t2 ch where ch.defid in (50,52) and ch.day between 20070320 and 20070401 group by defid; select sum(count) from t2 ch where ch.defid in (50,52) and ch.day between 20070320 and 20070401 group by defid;
#drop table t1, t2; drop table t1, t2;
This diff is collapsed.
...@@ -49,7 +49,8 @@ private: ...@@ -49,7 +49,8 @@ private:
partition_index_first_unordered= 2, partition_index_first_unordered= 2,
partition_index_last= 3, partition_index_last= 3,
partition_index_read_last= 4, partition_index_read_last= 4,
partition_no_index_scan= 5 partition_read_range = 5,
partition_no_index_scan= 6
}; };
/* Data for the partition handler */ /* Data for the partition handler */
int m_mode; // Open mode int m_mode; // Open mode
...@@ -63,8 +64,6 @@ private: ...@@ -63,8 +64,6 @@ private:
handler **m_reorged_file; // Reorganised partitions handler **m_reorged_file; // Reorganised partitions
handler **m_added_file; // Added parts kept for errors handler **m_added_file; // Added parts kept for errors
partition_info *m_part_info; // local reference to partition partition_info *m_part_info; // local reference to partition
uchar *m_start_key_ref; // Reference of start key in current
// index scan info
Field **m_part_field_array; // Part field array locally to save acc 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 uchar *m_ordered_rec_buffer; // Row and key buffer for ord. idx scan
KEY *m_curr_key_info; // Current index KEY *m_curr_key_info; // Current index
...@@ -429,9 +428,7 @@ public: ...@@ -429,9 +428,7 @@ public:
virtual int read_range_next(); virtual int read_range_next();
private: private:
int common_index_read(uchar * buf, const uchar * key, int common_index_read(uchar * buf, bool have_start_key);
key_part_map keypart_map,
enum ha_rkey_function find_flag);
int common_first_last(uchar * buf); int common_first_last(uchar * buf);
int partition_scan_set_up(uchar * buf, bool idx_read_flag); int partition_scan_set_up(uchar * buf, bool idx_read_flag);
int handle_unordered_next(uchar * buf, bool next_same); int handle_unordered_next(uchar * buf, bool next_same);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment