1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008-2009 Sun Microsystems, Inc.
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; version 2 of the License.
10
* This program is distributed in the hope that it will be useful,
11
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
* GNU General Public License for more details.
15
* You should have received a copy of the GNU General Public License
16
* along with this program; if not, write to the Free Software
17
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20
#ifndef DRIZZLED_OPTIMIZER_SEL_TREE_H
21
#define DRIZZLED_OPTIMIZER_SEL_TREE_H
23
#include "drizzled/memory/sql_alloc.h"
36
class SEL_TREE : public drizzled::memory::SqlAlloc
40
Starting an effort to document this field:
41
(for some i, keys[i]->type == optimizer::SEL_ARG::IMPOSSIBLE) =>
42
(type == SEL_TREE::IMPOSSIBLE)
53
SEL_TREE(enum Type type_arg) :type(type_arg) {}
57
memset(keys, 0, sizeof(keys));
60
Note: there may exist SEL_TREE objects with sel_tree->type=KEY and
61
keys[i]=0 for all i. (SergeyP: it is not clear whether there is any
62
merit in range analyzer functions (e.g. get_mm_parts) returning a
63
pointer to such SEL_TREE instead of NULL)
65
SEL_ARG *keys[MAX_KEY];
66
key_map keys_map; /* bitmask of non-NULL elements in keys */
69
Possible ways to read rows using index_merge. The list is non-empty only
70
if type==KEY. Currently can be non empty only if keys_map.none().
72
List<SEL_IMERGE> merges;
74
/* The members below are filled/used only after get_mm_tree is done */
75
key_map ror_scans_map; /* bitmask of ROR scan-able elements in keys */
76
uint32_t n_ror_scans; /* number of set bits in ror_scans_map */
78
RorScanInfo **ror_scans; /* list of ROR key scans */
79
RorScanInfo **ror_scans_end; /* last ROR scan */
80
/* Note that #records for each key scan is stored in table->quick_rows */
85
Check if two optimizer::SEL_TREES can be combined into one (i.e. a single key range
86
read can be constructed for "cond_of_tree1 OR cond_of_tree2" ) without
89
bool sel_trees_can_be_ored(SEL_TREE *tree1,
91
RangeParameter* param);
94
tree_or(RangeParameter *param, SEL_TREE *tree1, SEL_TREE *tree2);
97
Remove the trees that are not suitable for record retrieval.
99
param Range analysis parameter
100
tree Tree to be processed, tree->type is KEY or KEY_SMALLER
103
This function walks through tree->keys[] and removes the SEL_ARG* trees
104
that are not "maybe" trees (*) and cannot be used to construct quick range
106
(*) - have type MAYBE or MAYBE_KEY. Perhaps we should remove trees of
107
these types here as well.
109
A SEL_ARG* tree cannot be used to construct quick select if it has
110
tree->part != 0. (e.g. it could represent "keypart2 < const").
112
WHY THIS FUNCTION IS NEEDED
114
Normally we allow construction of optimizer::SEL_TREE objects that have SEL_ARG
115
trees that do not allow quick range select construction. For example for
116
" keypart1=1 AND keypart2=2 " the execution will proceed as follows:
117
tree1= optimizer::SEL_TREE { SEL_ARG{keypart1=1} }
118
tree2= optimizer::SEL_TREE { SEL_ARG{keypart2=2} } -- can't make quick range select
120
call tree_and(tree1, tree2) -- this joins SEL_ARGs into a usable SEL_ARG
123
There is an exception though: when we construct index_merge optimizer::SEL_TREE,
124
any SEL_ARG* tree that cannot be used to construct quick range select can
125
be removed, because current range analysis code doesn't provide any way
126
that tree could be later combined with another tree.
127
Consider an example: we should not construct
128
st1 = optimizer::SEL_TREE {
129
merges = SEL_IMERGE {
130
optimizer::SEL_TREE(t.key1part1 = 1),
131
optimizer::SEL_TREE(t.key2part2 = 2) -- (*)
135
- (*) cannot be used to construct quick range select,
136
- There is no execution path that would cause (*) to be converted to
137
a tree that could be used.
139
The latter is easy to verify: first, notice that the only way to convert
140
(*) into a usable tree is to call tree_and(something, (*)).
142
Second look at what tree_and/tree_or function would do when passed a
143
optimizer::SEL_TREE that has the structure like st1 tree has, and conlcude that
144
tree_and(something, (*)) will not be called.
147
0 Ok, some suitable trees left
148
1 No tree->keys[] left.
150
bool remove_nonrange_trees(RangeParameter *param, SEL_TREE *tree);
152
} /* namespace optimizer */
154
} /* namespace drizzled */
156
#endif /* DRIZZLED_OPTIMIZER_SEL_TREE_H */