Skip to content

Commit 19d24f0

Browse files
committed
MDEV-10763: Wrong result - server does not return NULL values from default list partition after ALTER table
Fixed partition pruning for NULL value.
1 parent b22ed66 commit 19d24f0

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

mysql-test/r/partition_default.result

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,3 +1204,32 @@ where a>=10 and (a <=10 and b <=30);
12041204
id select_type table partitions type possible_keys key key_len ref rows Extra
12051205
1 SIMPLE t1 p1,p2,p3 ALL NULL NULL NULL NULL 3 Using where
12061206
drop table t1;
1207+
#
1208+
# MDEV-10763: Wrong result - server does not return NULL values
1209+
# from default list partition after ALTER table
1210+
#
1211+
create table t1 (i int) partition by list (i) ( partition p1 default);
1212+
insert into t1 values (null);
1213+
select * from t1 where i is null;
1214+
i
1215+
NULL
1216+
alter table t1 partition by list (i) ( partition p1 values in (1), partition p2 default);
1217+
select * from t1 where i is null;
1218+
i
1219+
NULL
1220+
explain partitions
1221+
select * from t1 where i is null;
1222+
id select_type table partitions type possible_keys key key_len ref rows Extra
1223+
1 SIMPLE t1 p2 system NULL NULL NULL NULL 1
1224+
alter table t1 partition by list (i) (
1225+
partition p0 values in (NULL),
1226+
partition p1 values in (1),
1227+
partition p2 default);
1228+
select * from t1 where i is null;
1229+
i
1230+
NULL
1231+
explain partitions
1232+
select * from t1 where i is null;
1233+
id select_type table partitions type possible_keys key key_len ref rows Extra
1234+
1 SIMPLE t1 p0 system NULL NULL NULL NULL 1
1235+
drop table t1;

mysql-test/t/partition_default.test

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -498,5 +498,25 @@ insert into t1 values
498498
explain partitions
499499
select * from t1
500500
where a>=10 and (a <=10 and b <=30);
501+
drop table t1;
502+
503+
--echo #
504+
--echo # MDEV-10763: Wrong result - server does not return NULL values
505+
--echo # from default list partition after ALTER table
506+
--echo #
507+
create table t1 (i int) partition by list (i) ( partition p1 default);
508+
insert into t1 values (null);
509+
select * from t1 where i is null;
510+
alter table t1 partition by list (i) ( partition p1 values in (1), partition p2 default);
511+
select * from t1 where i is null;
512+
explain partitions
513+
select * from t1 where i is null;
514+
alter table t1 partition by list (i) (
515+
partition p0 values in (NULL),
516+
partition p1 values in (1),
517+
partition p2 default);
518+
select * from t1 where i is null;
519+
explain partitions
520+
select * from t1 where i is null;
501521

502522
drop table t1;

sql/sql_partition.cc

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7960,8 +7960,19 @@ int get_part_iter_for_interval_via_mapping(partition_info *part_info,
79607960
/* col = x and F(x) = NULL -> only search NULL partition */
79617961
part_iter->part_nums.cur= part_iter->part_nums.start= 0;
79627962
part_iter->part_nums.end= 0;
7963-
part_iter->ret_null_part= part_iter->ret_null_part_orig= TRUE;
7964-
DBUG_RETURN(1);
7963+
/*
7964+
if NULL partition exists:
7965+
for RANGE it is the first partition (always exists);
7966+
for LIST should be indicator that it is present
7967+
*/
7968+
if (part_info->part_type == RANGE_PARTITION ||
7969+
part_info->has_null_value)
7970+
{
7971+
part_iter->ret_null_part= part_iter->ret_null_part_orig= TRUE;
7972+
DBUG_RETURN(1);
7973+
}
7974+
// If no NULL partition look up in DEFAULT or there is no such value
7975+
goto not_found;
79657976
}
79667977
part_iter->part_nums.cur= part_iter->part_nums.start;
79677978
if (check_zero_dates && !part_info->part_expr->null_value)

0 commit comments

Comments
 (0)