Skip to content

Commit

Permalink
MDEV-10763: Wrong result - server does not return NULL values from de…
Browse files Browse the repository at this point in the history
…fault list partition after ALTER table

Fixed partition pruning for NULL value.
  • Loading branch information
sanja-byelkin committed Sep 9, 2016
1 parent b22ed66 commit 19d24f0
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
29 changes: 29 additions & 0 deletions mysql-test/r/partition_default.result
Original file line number Diff line number Diff line change
Expand Up @@ -1204,3 +1204,32 @@ where a>=10 and (a <=10 and b <=30);
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 p1,p2,p3 ALL NULL NULL NULL NULL 3 Using where
drop table t1;
#
# MDEV-10763: Wrong result - server does not return NULL values
# from default list partition after ALTER table
#
create table t1 (i int) partition by list (i) ( partition p1 default);
insert into t1 values (null);
select * from t1 where i is null;
i
NULL
alter table t1 partition by list (i) ( partition p1 values in (1), partition p2 default);
select * from t1 where i is null;
i
NULL
explain partitions
select * from t1 where i is null;
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 p2 system NULL NULL NULL NULL 1
alter table t1 partition by list (i) (
partition p0 values in (NULL),
partition p1 values in (1),
partition p2 default);
select * from t1 where i is null;
i
NULL
explain partitions
select * from t1 where i is null;
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE t1 p0 system NULL NULL NULL NULL 1
drop table t1;
20 changes: 20 additions & 0 deletions mysql-test/t/partition_default.test
Original file line number Diff line number Diff line change
Expand Up @@ -498,5 +498,25 @@ insert into t1 values
explain partitions
select * from t1
where a>=10 and (a <=10 and b <=30);
drop table t1;

--echo #
--echo # MDEV-10763: Wrong result - server does not return NULL values
--echo # from default list partition after ALTER table
--echo #
create table t1 (i int) partition by list (i) ( partition p1 default);
insert into t1 values (null);
select * from t1 where i is null;
alter table t1 partition by list (i) ( partition p1 values in (1), partition p2 default);
select * from t1 where i is null;
explain partitions
select * from t1 where i is null;
alter table t1 partition by list (i) (
partition p0 values in (NULL),
partition p1 values in (1),
partition p2 default);
select * from t1 where i is null;
explain partitions
select * from t1 where i is null;

drop table t1;
15 changes: 13 additions & 2 deletions sql/sql_partition.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7960,8 +7960,19 @@ int get_part_iter_for_interval_via_mapping(partition_info *part_info,
/* col = x and F(x) = NULL -> only search NULL partition */
part_iter->part_nums.cur= part_iter->part_nums.start= 0;
part_iter->part_nums.end= 0;
part_iter->ret_null_part= part_iter->ret_null_part_orig= TRUE;
DBUG_RETURN(1);
/*
if NULL partition exists:
for RANGE it is the first partition (always exists);
for LIST should be indicator that it is present
*/
if (part_info->part_type == RANGE_PARTITION ||
part_info->has_null_value)
{
part_iter->ret_null_part= part_iter->ret_null_part_orig= TRUE;
DBUG_RETURN(1);
}
// If no NULL partition look up in DEFAULT or there is no such value
goto not_found;
}
part_iter->part_nums.cur= part_iter->part_nums.start;
if (check_zero_dates && !part_info->part_expr->null_value)
Expand Down

0 comments on commit 19d24f0

Please sign in to comment.