Commit f2d603c2 authored by sergefp@mysql.com's avatar sergefp@mysql.com

WL#2985 "Partition Pruning": post-review fixes: Better comments

parent 328f8fa7
...@@ -259,3 +259,18 @@ explain partitions select * from t1 where a is not null; ...@@ -259,3 +259,18 @@ explain partitions select * from t1 where a is not null;
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 p0,p1 ALL NULL NULL NULL NULL 2 Using where 1 SIMPLE t1 p0,p1 ALL NULL NULL NULL NULL 2 Using where
drop table t1; drop table t1;
create table t1 (a int not null, b int not null, key(a), key(b))
partition by hash(a) partitions 4;
insert into t1 values (1,1),(2,2),(3,3),(4,4);
explain partitions
select * from t1 X, t1 Y
where X.b = Y.b and (X.a=1 or X.a=2) and (Y.a=2 or Y.a=3);
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE X p1,p2 ALL a,b NULL NULL NULL 4 Using where
1 SIMPLE Y p2,p3 ref a,b b 4 test.X.b 2 Using where
explain partitions
select * from t1 X, t1 Y where X.a = Y.a and (X.a=1 or X.a=2);
id select_type table partitions type possible_keys key key_len ref rows Extra
1 SIMPLE X p1,p2 ALL a NULL NULL NULL 4 Using where
1 SIMPLE Y p1,p2 ref a a 4 test.X.a 2
drop table t1;
...@@ -230,9 +230,22 @@ create table t1 (a int) partition by hash(a) partitions 2; ...@@ -230,9 +230,22 @@ create table t1 (a int) partition by hash(a) partitions 2;
insert into t1 values (1),(2); insert into t1 values (1),(2);
explain partitions select * from t1 where a is null; explain partitions select * from t1 where a is null;
# this selects both # this uses both partitions
explain partitions select * from t1 where a is not null; explain partitions select * from t1 where a is not null;
drop table t1; drop table t1;
# Join tests
create table t1 (a int not null, b int not null, key(a), key(b))
partition by hash(a) partitions 4;
insert into t1 values (1,1),(2,2),(3,3),(4,4);
explain partitions
select * from t1 X, t1 Y
where X.b = Y.b and (X.a=1 or X.a=2) and (Y.a=2 or Y.a=3);
explain partitions
select * from t1 X, t1 Y where X.a = Y.a and (X.a=1 or X.a=2);
drop table t1;
# No tests for NULLs in RANGE(monotonic_expr()) - they depend on BUG#15447 # No tests for NULLs in RANGE(monotonic_expr()) - they depend on BUG#15447
# being fixed. # being fixed.
...@@ -567,9 +567,9 @@ class partition_info :public Sql_alloc { ...@@ -567,9 +567,9 @@ class partition_info :public Sql_alloc {
*/ */
get_subpart_id_func get_subpartition_id; get_subpart_id_func get_subpartition_id;
/* NULL-terminated list of fields used in partitioned expression */ /* NULL-terminated array of fields used in partitioned expression */
Field **part_field_array; Field **part_field_array;
/* NULL-terminated list of fields used in subpartitioned expression */ /* NULL-terminated array of fields used in subpartitioned expression */
Field **subpart_field_array; Field **subpart_field_array;
/* /*
......
...@@ -2246,11 +2246,11 @@ typedef struct st_part_prune_param ...@@ -2246,11 +2246,11 @@ typedef struct st_part_prune_param
/*************************************************************** /***************************************************************
Following fields are used to store an 'iterator' that can be Following fields are used to store an 'iterator' that can be
used to obtain a set of used artitions. used to obtain a set of used partitions.
**************************************************************/ **************************************************************/
/* /*
Start and end+1 partition "numbers". They can have two meanings depending Start and end+1 partition "numbers". They can have two meanings depending
depending of the value of part_num_to_part_id: of the value of part_num_to_part_id:
part_num_to_part_id_range - numbers are partition ids part_num_to_part_id_range - numbers are partition ids
part_num_to_part_id_list - numbers are indexes in part_info->list_array part_num_to_part_id_list - numbers are indexes in part_info->list_array
*/ */
...@@ -2536,7 +2536,7 @@ static uint32 part_num_to_part_id_list(PART_PRUNE_PARAM* ppar, uint32 num) ...@@ -2536,7 +2536,7 @@ static uint32 part_num_to_part_id_list(PART_PRUNE_PARAM* ppar, uint32 num)
List<SEL_IMERGE> represents "imerge1 AND imerge2 AND ...". List<SEL_IMERGE> represents "imerge1 AND imerge2 AND ...".
The set of used partitions is an intersection of used partitions sets The set of used partitions is an intersection of used partitions sets
for imerge_{i}. for imerge_{i}.
We accumulate this intersection a separate bitmap. We accumulate this intersection in a separate bitmap.
RETURN RETURN
See find_used_partitions() See find_used_partitions()
...@@ -2554,7 +2554,7 @@ static int find_used_partitions_imerge_list(PART_PRUNE_PARAM *ppar, ...@@ -2554,7 +2554,7 @@ static int find_used_partitions_imerge_list(PART_PRUNE_PARAM *ppar,
bitmap_bytes))) bitmap_bytes)))
{ {
/* /*
Fallback, process just first SEL_IMERGE. This can leave us with more Fallback, process just the first SEL_IMERGE. This can leave us with more
partitions marked as used then actually needed. partitions marked as used then actually needed.
*/ */
return find_used_partitions_imerge(ppar, merges.head()); return find_used_partitions_imerge(ppar, merges.head());
...@@ -2623,20 +2623,20 @@ int find_used_partitions_imerge(PART_PRUNE_PARAM *ppar, SEL_IMERGE *imerge) ...@@ -2623,20 +2623,20 @@ int find_used_partitions_imerge(PART_PRUNE_PARAM *ppar, SEL_IMERGE *imerge)
/* /*
Recursively walk the SEL_ARG tree, find/mark partitions that need to be used Collect partitioning ranges for the SEL_ARG tree and mark partitions as used
SYNOPSIS SYNOPSIS
find_used_partitions() find_used_partitions()
ppar Partition pruning context. ppar Partition pruning context.
key_tree Intervals tree to perform pruning for. key_tree SEL_ARG range tree to perform pruning for
DESCRIPTION DESCRIPTION
This function This function
* recursively walks the SEL_ARG* tree collecting partitioning * recursively walks the SEL_ARG* tree collecting partitioning "intervals"
"intervals"; * finds the partitions one needs to use to get rows in these intervals
* finds the partitions one needs to use to get rows in these intervals; * marks these partitions as used
* marks these partitions as used.
NOTES
WHAT IS CONSIDERED TO BE "INTERVALS" WHAT IS CONSIDERED TO BE "INTERVALS"
A partition pruning "interval" is equivalent to condition in one of the A partition pruning "interval" is equivalent to condition in one of the
forms: forms:
...@@ -2687,7 +2687,7 @@ int find_used_partitions(PART_PRUNE_PARAM *ppar, SEL_ARG *key_tree) ...@@ -2687,7 +2687,7 @@ int find_used_partitions(PART_PRUNE_PARAM *ppar, SEL_ARG *key_tree)
{ {
/* /*
Partitioning is done by RANGE|INTERVAL(monotonic_expr(fieldX)), and Partitioning is done by RANGE|INTERVAL(monotonic_expr(fieldX)), and
we got "const1 < fieldX < const2" interval. we got "const1 CMP fieldX CMP const2" interval
*/ */
DBUG_EXECUTE("info", dbug_print_segment_range(key_tree, DBUG_EXECUTE("info", dbug_print_segment_range(key_tree,
ppar->range_param. ppar->range_param.
...@@ -2761,7 +2761,7 @@ int find_used_partitions(PART_PRUNE_PARAM *ppar, SEL_ARG *key_tree) ...@@ -2761,7 +2761,7 @@ int find_used_partitions(PART_PRUNE_PARAM *ppar, SEL_ARG *key_tree)
DBUG_EXECUTE("info", dbug_print_singlepoint_range(ppar->arg_stack, DBUG_EXECUTE("info", dbug_print_singlepoint_range(ppar->arg_stack,
ppar->part_fields);); ppar->part_fields););
uint32 part_id; uint32 part_id;
/* then find in which partition the {const1, ...,constN} tuple goes */ /* Find in which partition the {const1, ...,constN} tuple goes */
if (ppar->get_top_partition_id_func(ppar->part_info, &part_id)) if (ppar->get_top_partition_id_func(ppar->part_info, &part_id))
{ {
res= 0; /* No satisfying partitions */ res= 0; /* No satisfying partitions */
...@@ -2843,7 +2843,10 @@ int find_used_partitions(PART_PRUNE_PARAM *ppar, SEL_ARG *key_tree) ...@@ -2843,7 +2843,10 @@ int find_used_partitions(PART_PRUNE_PARAM *ppar, SEL_ARG *key_tree)
if (set_full_part_if_bad_ret) if (set_full_part_if_bad_ret)
{ {
/* Restore the "used partition iterator" to its default */ /*
Restore the "used partitions iterator" to the default setting that
specifies iteration over all partitions.
*/
ppar->part_num_to_part_id= part_num_to_part_id_range; ppar->part_num_to_part_id= part_num_to_part_id_range;
ppar->start_part_num= 0; ppar->start_part_num= 0;
ppar->end_part_num= ppar->part_info->no_parts; ppar->end_part_num= ppar->part_info->no_parts;
......
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