Commit 8dbdb863 authored by Igor Babaev's avatar Igor Babaev

WL#24: post review fixes.

parent 1fd5ecdb
...@@ -262,8 +262,8 @@ class SEL_ARG :public Sql_alloc ...@@ -262,8 +262,8 @@ class SEL_ARG :public Sql_alloc
uint8 part; // Which key part uint8 part; // Which key part
uint8 maybe_null; uint8 maybe_null;
/* /*
The ordinal number the least significant component encountered the ranges The ordinal number the least significant component encountered in
of the SEL_ARG tree (the first component has number 1) the ranges of the SEL_ARG tree (the first component has number 1)
*/ */
uint16 max_part_no; uint16 max_part_no;
/* /*
...@@ -851,8 +851,7 @@ static bool eq_tree(SEL_ARG* a,SEL_ARG *b); ...@@ -851,8 +851,7 @@ static bool eq_tree(SEL_ARG* a,SEL_ARG *b);
static SEL_ARG null_element(SEL_ARG::IMPOSSIBLE); static SEL_ARG null_element(SEL_ARG::IMPOSSIBLE);
static bool null_part_in_key(KEY_PART *key_part, const uchar *key, static bool null_part_in_key(KEY_PART *key_part, const uchar *key,
uint length); uint length);
static bool sel_trees_have_common_keys(RANGE_OPT_PARAM* param, static bool sel_trees_have_common_keys(SEL_TREE *tree1, SEL_TREE *tree2,
SEL_TREE *tree1, SEL_TREE *tree2,
key_map *common_keys); key_map *common_keys);
static void eliminate_single_tree_imerges(RANGE_OPT_PARAM *param, static void eliminate_single_tree_imerges(RANGE_OPT_PARAM *param,
SEL_TREE *tree); SEL_TREE *tree);
...@@ -964,7 +963,7 @@ bool SEL_IMERGE::have_common_keys(RANGE_OPT_PARAM *param, SEL_TREE *tree) ...@@ -964,7 +963,7 @@ bool SEL_IMERGE::have_common_keys(RANGE_OPT_PARAM *param, SEL_TREE *tree)
or_tree != bound; or_tree++) or_tree != bound; or_tree++)
{ {
key_map common_keys; key_map common_keys;
if (sel_trees_have_common_keys(param, *or_tree, tree, &common_keys)) if (sel_trees_have_common_keys(*or_tree, tree, &common_keys))
return TRUE; return TRUE;
} }
return FALSE; return FALSE;
...@@ -988,12 +987,15 @@ bool SEL_IMERGE::have_common_keys(RANGE_OPT_PARAM *param, SEL_TREE *tree) ...@@ -988,12 +987,15 @@ bool SEL_IMERGE::have_common_keys(RANGE_OPT_PARAM *param, SEL_TREE *tree)
If this imerge m represent the formula If this imerge m represent the formula
RT_1 OR ... OR RT_k RT_1 OR ... OR RT_k
then the resulting imerge of the function represents the formula then the resulting imerge of the function represents the formula
(RT_1 AND RT) OR ... (RT_k AND RT) (RT_1 AND RT) OR ... OR (RT_k AND RT)
The function calls the function and_range_trees to construct the The function calls the function and_range_trees to construct the
range tree representing (RT_i AND RT). range tree representing (RT_i AND RT).
NOTE NOTE
The function may return an empty imerge without any range trees The function may return an empty imerge without any range trees.
This happens when each call of and_range_trees returns an
impossible range tree (SEL_TREE::IMPOSSIBLE).
Example: (key1 < 2 AND key2 > 10) AND (key1 > 4 OR key2 < 6).
RETURN RETURN
0 if the operation is a success 0 if the operation is a success
...@@ -1005,13 +1007,12 @@ int SEL_IMERGE::and_sel_tree(RANGE_OPT_PARAM *param, SEL_TREE *tree, ...@@ -1005,13 +1007,12 @@ int SEL_IMERGE::and_sel_tree(RANGE_OPT_PARAM *param, SEL_TREE *tree,
{ {
for (SEL_TREE** or_tree= trees; or_tree != trees_next; or_tree++) for (SEL_TREE** or_tree= trees; or_tree != trees_next; or_tree++)
{ {
SEL_TREE *result= 0; SEL_TREE *res_or_tree= 0;
key_map result_keys; if (!(res_or_tree= new SEL_TREE()))
if (!(result= new SEL_TREE()))
return (-1); return (-1);
if (!and_range_trees(param, *or_tree, tree, result)) if (!and_range_trees(param, *or_tree, tree, res_or_tree))
{ {
if (new_imerge->or_sel_tree(param, result)) if (new_imerge->or_sel_tree(param, res_or_tree))
return (-1); return (-1);
} }
} }
...@@ -1030,7 +1031,7 @@ int SEL_IMERGE::and_sel_tree(RANGE_OPT_PARAM *param, SEL_TREE *tree, ...@@ -1030,7 +1031,7 @@ int SEL_IMERGE::and_sel_tree(RANGE_OPT_PARAM *param, SEL_TREE *tree,
is_last_check_pass OUT <=> no more calls of the function for this imerge is_last_check_pass OUT <=> no more calls of the function for this imerge
DESCRIPTION DESCRIPTION
The functions performs OR operation on this imerge m and the range part The function performs OR operation on this imerge m and the range part
of the SEL_TREE tree rt. It always replaces this imerge with the result of the SEL_TREE tree rt. It always replaces this imerge with the result
of the operation. of the operation.
...@@ -1044,7 +1045,7 @@ int SEL_IMERGE::and_sel_tree(RANGE_OPT_PARAM *param, SEL_TREE *tree, ...@@ -1044,7 +1045,7 @@ int SEL_IMERGE::and_sel_tree(RANGE_OPT_PARAM *param, SEL_TREE *tree,
1. In the first mode, when is_first_check_pass==TRUE : 1. In the first mode, when is_first_check_pass==TRUE :
1.1. If rt must be ored(see the function sel_trees_must_be_ored) with 1.1. If rt must be ored(see the function sel_trees_must_be_ored) with
some rt_j (there may be only one such range tree in the imerge) some rt_j (there may be only one such range tree in the imerge)
then the function produces the imerge representing the formula then the function produces an imerge representing the formula
RT_1 OR ... OR (RT_j OR RT) OR ... OR RT_k, RT_1 OR ... OR (RT_j OR RT) OR ... OR RT_k,
where the tree for (RT_j OR RT) is built by oring the pairs where the tree for (RT_j OR RT) is built by oring the pairs
of SEL_ARG trees for the corresponding indexes of SEL_ARG trees for the corresponding indexes
...@@ -1090,7 +1091,8 @@ int SEL_IMERGE::or_sel_tree_with_checks(RANGE_OPT_PARAM *param, ...@@ -1090,7 +1091,8 @@ int SEL_IMERGE::or_sel_tree_with_checks(RANGE_OPT_PARAM *param,
{ {
bool must_be_ored= sel_trees_must_be_ored(param, *or_tree, tree, bool must_be_ored= sel_trees_must_be_ored(param, *or_tree, tree,
ored_keys); ored_keys);
if (must_be_ored == is_first_check_pass) { if (must_be_ored == is_first_check_pass)
{
result_keys.clear_all(); result_keys.clear_all();
result= *or_tree; result= *or_tree;
for (uint key_no= 0; key_no < param->keys; key_no++) for (uint key_no= 0; key_no < param->keys; key_no++)
...@@ -6962,7 +6964,6 @@ void eliminate_single_tree_imerges(RANGE_OPT_PARAM *param, SEL_TREE *tree) ...@@ -6962,7 +6964,6 @@ void eliminate_single_tree_imerges(RANGE_OPT_PARAM *param, SEL_TREE *tree)
SYNOPSIS SYNOPSIS
sel_trees_have_common_keys() sel_trees_have_common_keys()
param Context info for the function
tree1 SEL_TREE for the first tree tree1 SEL_TREE for the first tree
tree2 SEL_TREE for the second tree tree2 SEL_TREE for the second tree
common_keys OUT bitmap of all indexes with ranges in both trees common_keys OUT bitmap of all indexes with ranges in both trees
...@@ -6979,8 +6980,7 @@ void eliminate_single_tree_imerges(RANGE_OPT_PARAM *param, SEL_TREE *tree) ...@@ -6979,8 +6980,7 @@ void eliminate_single_tree_imerges(RANGE_OPT_PARAM *param, SEL_TREE *tree)
*/ */
static static
bool sel_trees_have_common_keys(RANGE_OPT_PARAM* param, bool sel_trees_have_common_keys(SEL_TREE *tree1, SEL_TREE *tree2,
SEL_TREE *tree1, SEL_TREE *tree2,
key_map *common_keys) key_map *common_keys)
{ {
*common_keys= tree1->keys_map; *common_keys= tree1->keys_map;
...@@ -7027,7 +7027,7 @@ bool sel_trees_can_be_ored(RANGE_OPT_PARAM* param, ...@@ -7027,7 +7027,7 @@ bool sel_trees_can_be_ored(RANGE_OPT_PARAM* param,
key_map *common_keys) key_map *common_keys)
{ {
DBUG_ENTER("sel_trees_can_be_ored"); DBUG_ENTER("sel_trees_can_be_ored");
if (!sel_trees_have_common_keys(param, tree1, tree2, common_keys)) if (!sel_trees_have_common_keys(tree1, tree2, common_keys))
DBUG_RETURN(FALSE); DBUG_RETURN(FALSE);
int key_no; int key_no;
key_map::Iterator it(*common_keys); key_map::Iterator it(*common_keys);
...@@ -7151,7 +7151,7 @@ bool sel_trees_must_be_ored(RANGE_OPT_PARAM* param, ...@@ -7151,7 +7151,7 @@ bool sel_trees_must_be_ored(RANGE_OPT_PARAM* param,
key1part1=1 AND key2part1=3 OR key2part1=3 AND key2part2=2 key1part1=1 AND key2part1=3 OR key2part1=3 AND key2part2=2
for which an index merge can be built. for which an index merge can be built.
Any final SEL_TREE may contains SEL_ARG trees for which no quick select Any final SEL_TREE may contain SEL_ARG trees for which no quick select
can be built. Such SEL_ARG trees should be removed from the range part can be built. Such SEL_ARG trees should be removed from the range part
before different range scans are evaluated. Such SEL_ARG trees also should before different range scans are evaluated. Such SEL_ARG trees also should
be removed from all range trees of each index merge before different be removed from all range trees of each index merge before different
......
...@@ -235,14 +235,11 @@ class base_list :public Sql_alloc ...@@ -235,14 +235,11 @@ class base_list :public Sql_alloc
{ {
if (!list->is_empty()) if (!list->is_empty())
{ {
#if 0
#else
if (is_empty()) if (is_empty())
{ {
*this= *list; *this= *list;
return; return;
} }
#endif
*last= list->first; *last= list->first;
last= list->last; last= list->last;
elements+= list->elements; elements+= list->elements;
......
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