diff --git a/mysql-test/r/partition_default.result b/mysql-test/r/partition_default.result index 4d9984126b5..fcf16ba7ccf 100644 --- a/mysql-test/r/partition_default.result +++ b/mysql-test/r/partition_default.result @@ -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; diff --git a/mysql-test/t/partition_default.test b/mysql-test/t/partition_default.test index e6eec53761a..1110b311c29 100644 --- a/mysql-test/t/partition_default.test +++ b/mysql-test/t/partition_default.test @@ -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; diff --git a/sql/sql_partition.cc b/sql/sql_partition.cc index 034816ada3f..324eef09854 100644 --- a/sql/sql_partition.cc +++ b/sql/sql_partition.cc @@ -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)