From d6c2a6daeca742d1054535bb026c2b14183efb8f Mon Sep 17 00:00:00 2001 From: unknown Date: Sat, 5 Aug 2006 16:12:24 -0400 Subject: [PATCH] BUG#21339: Crash at EXPLAIN PARTITIONS Caused by missing check for end of partitions in prune range check mysql-test/r/partition.result: Added test case for duplicate bug#21388 mysql-test/r/partition_range.result: Added new test case for bug#21339 mysql-test/t/partition.test: Added test case for duplicate bug#21388 mysql-test/t/partition_range.test: Added new test case for bug#21339 sql/sql_partition.cc: Check so that we don't set outer range to be larger than max_partition --- mysql-test/r/partition.result | 28 ++++++++++++++++++++++++++++ mysql-test/r/partition_range.result | 10 ++++++++++ mysql-test/t/partition.test | 18 ++++++++++++++++++ mysql-test/t/partition_range.test | 13 +++++++++++++ sql/sql_partition.cc | 11 +++++++---- 5 files changed, 76 insertions(+), 4 deletions(-) diff --git a/mysql-test/r/partition.result b/mysql-test/r/partition.result index e95489864f7..6f72068c0b7 100644 --- a/mysql-test/r/partition.result +++ b/mysql-test/r/partition.result @@ -1117,4 +1117,32 @@ hello/master-data/tmpinx/t1#P#p1#SP#subpart11.MYI hello/master-data/tmpinx/t1#P#p2#SP#subpart20.MYI hello/master-data/tmpinx/t1#P#p2#SP#subpart21.MYI drop table t1; +create table t1 (a bigint unsigned not null, primary key(a)) +engine = myisam +partition by key (a) +partitions 10; +show create table t1; +Table Create Table +t1 CREATE TABLE `t1` ( + `a` bigint(20) unsigned NOT NULL, + PRIMARY KEY (`a`) +) ENGINE=MyISAM DEFAULT CHARSET=latin1 /*!50100 PARTITION BY KEY (a) PARTITIONS 10 */ +insert into t1 values (18446744073709551615), (0xFFFFFFFFFFFFFFFE), +(18446744073709551613), (18446744073709551612); +select * from t1; +a +18446744073709551612 +18446744073709551613 +18446744073709551614 +18446744073709551615 +select * from t1 where a = 18446744073709551615; +a +18446744073709551615 +delete from t1 where a = 18446744073709551615; +select * from t1; +a +18446744073709551612 +18446744073709551613 +18446744073709551614 +drop table t1; End of 5.1 tests diff --git a/mysql-test/r/partition_range.result b/mysql-test/r/partition_range.result index 9812c80040b..be88d9f6639 100644 --- a/mysql-test/r/partition_range.result +++ b/mysql-test/r/partition_range.result @@ -1,4 +1,14 @@ drop table if exists t1; +create table t1 (a date) +engine = innodb +partition by range (year(a)) +(partition p0 values less than (2006), +partition p1 values less than (2007)); +explain partitions select * from t1 +where a between '2006-01-01' and '2007-06-01'; +id select_type table partitions type possible_keys key key_len ref rows Extra +1 SIMPLE t1 p1 ALL NULL NULL NULL NULL 2 Using where +drop table t1; create table t1 (a int unsigned) partition by range (a) (partition pnull values less than (0), diff --git a/mysql-test/t/partition.test b/mysql-test/t/partition.test index d4e930f91ec..6e6e4cb304d 100644 --- a/mysql-test/t/partition.test +++ b/mysql-test/t/partition.test @@ -1300,4 +1300,22 @@ eval ALTER TABLE t1 REORGANIZE PARTITION p0 INTO drop table t1; --exec rmdir $MYSQLTEST_VARDIR/master-data/tmpdata || true --exec rmdir $MYSQLTEST_VARDIR/master-data/tmpinx || true + +# +# Bug 21388: Bigint fails to find record +# +create table t1 (a bigint unsigned not null, primary key(a)) +engine = myisam +partition by key (a) +partitions 10; + +show create table t1; +insert into t1 values (18446744073709551615), (0xFFFFFFFFFFFFFFFE), +(18446744073709551613), (18446744073709551612); +select * from t1; +select * from t1 where a = 18446744073709551615; +delete from t1 where a = 18446744073709551615; +select * from t1; +drop table t1; + --echo End of 5.1 tests diff --git a/mysql-test/t/partition_range.test b/mysql-test/t/partition_range.test index 670b9333ab9..8719cbd98c4 100644 --- a/mysql-test/t/partition_range.test +++ b/mysql-test/t/partition_range.test @@ -9,6 +9,18 @@ drop table if exists t1; --enable_warnings +# +# Bug 21339: Crash in Explain Partitions +# +create table t1 (a date) +engine = innodb +partition by range (year(a)) +(partition p0 values less than (2006), + partition p1 values less than (2007)); +explain partitions select * from t1 +where a between '2006-01-01' and '2007-06-01'; +drop table t1; + # # More checks for partition pruning # @@ -686,3 +698,4 @@ EXPLAIN PARTITIONS SELECT * from t1 WHERE (a >= '2004-07-01' AND a <= '2004-09-30') OR (a >= '2005-07-01' AND a <= '2005-09-30'); DROP TABLE t1; + diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index 73091c0994e..e214b41400a 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -2573,10 +2573,13 @@ uint32 get_partition_id_range_for_endpoint(partition_info *part_info, } else { - if (part_func_value == range_array[loc_part_id]) - loc_part_id += test(include_endpoint); - else if (part_func_value > range_array[loc_part_id]) - loc_part_id++; + if (loc_part_id < max_partition) + { + if (part_func_value == range_array[loc_part_id]) + loc_part_id += test(include_endpoint); + else if (part_func_value > range_array[loc_part_id]) + loc_part_id++; + } loc_part_id++; } DBUG_RETURN(loc_part_id);