MySQL 8.4.0
Source Code Documentation
tree.h
Go to the documentation of this file.
1/* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24#ifndef SQL_RANGE_OPTIMIZER_TREE_H_
25#define SQL_RANGE_OPTIMIZER_TREE_H_
26
27#include <assert.h>
28#include <string.h>
29#include <sys/types.h>
30
31#include "my_alloc.h"
32#include "my_base.h"
33#include "my_inttypes.h"
34#include "sql/field.h"
35#include "sql/mem_root_array.h"
38#include "sql/sql_bitmap.h"
39#include "sql/sql_const.h"
40#include "sql/sql_list.h"
41
42class Cost_estimate;
43class SEL_ARG;
44class SEL_ROOT;
45class SEL_TREE;
46struct KEY_PART;
47struct ROR_SCAN_INFO;
48
49// Note: tree1 and tree2 are not usable by themselves after tree_and() or
50// tree_or().
51SEL_TREE *tree_and(RANGE_OPT_PARAM *param, SEL_TREE *tree1, SEL_TREE *tree2);
52SEL_TREE *tree_or(RANGE_OPT_PARAM *param, bool remove_jump_scans,
53 SEL_TREE *tree1, SEL_TREE *tree2);
56
57bool sel_trees_can_be_ored(SEL_TREE *tree1, SEL_TREE *tree2,
58 RANGE_OPT_PARAM *param);
59
60/**
61 A graph of (possible multiple) key ranges, represented as a red-black
62 binary tree. There are three types (see the Type enum); if KEY_RANGE,
63 we have zero or more SEL_ARGs, described in the documentation on SEL_ARG.
64
65 As a special case, a nullptr SEL_ROOT means a range that is always true.
66 This is true both for keys[] and next_key_part.
67*/
68class SEL_ROOT {
69 public:
70 /**
71 Used to indicate if the range predicate for an index is always
72 true/false, depends on values from other tables or can be
73 evaluated as is.
74 */
75 enum class Type {
76 /** The range predicate for this index is always false. */
78 /**
79 There is a range predicate that refers to another table. The
80 range access method cannot be used on this index unless that
81 other table is earlier in the join sequence. The bit
82 representing the index is set in JOIN_TAB::needed_reg to
83 notify the join optimizer that there is a table dependency.
84 After deciding on join order, the optimizer may chose to rerun
85 the range optimizer for tables with such dependencies.
86 */
88 /**
89 There is a range condition that can be used on this index. The
90 range conditions for this index in stored in the SEL_ARG tree.
91 */
94
95 /**
96 Constructs a tree of type KEY_RANGE, using the given root.
97 (The root is allowed to have children.)
98 */
100
101 /**
102 Used to construct MAYBE_KEY and IMPOSSIBLE SEL_ARGs.
103 */
104 SEL_ROOT(MEM_ROOT *memroot, Type type_arg);
105
106 /**
107 Note that almost all SEL_ROOTs are created on the MEM_ROOT,
108 so this destructor will only rarely be called.
109 */
110 ~SEL_ROOT() { assert(use_count == 0); }
111
112 /**
113 Returns true iff we have a single node that has no max nor min.
114 Note that by convention, a nullptr SEL_ROOT means the same.
115 */
116 bool is_always() const;
117
118 /**
119 Returns a number of keypart values appended to the key buffer
120 for min key and max key. This function is used by both Range
121 Analysis and Partition pruning. For partition pruning we have
122 to ensure that we don't store also subpartition fields. Thus
123 we have to stop at the last partition part and not step into
124 the subpartition fields. For Range Analysis we set last_part
125 to MAX_KEY which we should never reach.
126 */
127 int store_min_key(KEY_PART *key, uchar **range_key, uint *range_key_flag,
128 uint last_part, bool start_key);
129
130 /* returns a number of keypart values appended to the key buffer */
131 int store_max_key(KEY_PART *key, uchar **range_key, uint *range_key_flag,
132 uint last_part, bool start_key);
133
134 /**
135 Signal to the tree that the caller will shortly be dropping it
136 on the floor; if others are still using it, this is a no-op,
137 but if the caller was the last one, it is now an orphan, and
138 references from it should not count.
139 */
140 void free_tree();
141
142 /**
143 Insert the given node into the tree, and update the root.
144
145 @param key The node to insert.
146 */
147 void insert(SEL_ARG *key);
148
149 /**
150 Delete the given node from the tree, and update the root.
151
152 @param key The node to delete. Must exist in the tree.
153 */
154 void tree_delete(SEL_ARG *key);
155
156 /**
157 Find best key with min <= given key.
158 Because of the call context, this should never return nullptr to get_range.
159
160 @param key The key to search for.
161 */
162 SEL_ARG *find_range(const SEL_ARG *key) const;
163
164 /**
165 Create a new tree that's a duplicate of this one.
166
167 @param param The parameters for the new tree. Used to find out which
168 MEM_ROOT to allocate the new nodes on.
169
170 @return The new tree, or nullptr in case of out of memory.
171 */
172 SEL_ROOT *clone_tree(RANGE_OPT_PARAM *param) const;
173
174 /**
175 Check if SEL_ROOT::use_count value is correct. See the definition
176 of use_count for what is "correct".
177
178 @param root The origin tree of the SEL_ARG graph (an RB-tree that
179 has the least value of root->sel_root->root->part in the
180 entire graph, and thus is the "origin" of the graph)
181
182 @return true iff an incorrect SEL_ARG::use_count is found.
183 */
184 bool test_use_count(const SEL_ROOT *root) const;
185
186 /** Returns true iff this is a single-element, single-field predicate. */
187 inline bool simple_key() const;
188
189 /**
190 The root node of the tree. Note that this may change as the result
191 of rotations during insertions or deletions, so pointers should be
192 to the SEL_ROOT, not individual SEL_ARG nodes.
193
194 This element can never be nullptr, but can be null_element
195 if type == KEY_RANGE and the tree is empty (which then means the same as
196 type == IMPOSSIBLE).
197
198 If type == IMPOSSIBLE or type == MAYBE_KEY, there's a single root
199 element which only serves to hold next_key_part (we don't really care
200 about root->part in this case); the actual min/max values etc.
201 do not matter and should not be accessed.
202 */
204
205 /**
206 Number of references to this SEL_ARG tree. References may be from
207 SEL_ARG::next_key_part of SEL_ARGs from earlier keyparts or
208 SEL_TREE::keys[i].
209
210 The SEL_ARG trees are re-used in a lazy-copy manner based on this
211 reference counting.
212 */
213 ulong use_count{0};
214
215 /**
216 Number of nodes in the RB-tree, not including sentinels.
217 */
219};
220
221int sel_cmp(Field *f, uchar *a, uchar *b, uint8 a_flag, uint8 b_flag);
222
223/**
224 A helper function to invert min flags to max flags for DESC key parts.
225 It changes NEAR_MIN, NO_MIN_RANGE to NEAR_MAX, NO_MAX_RANGE appropriately
226*/
227
228inline uint invert_min_flag(uint min_flag) {
229 uint max_flag_out = min_flag & ~(NEAR_MIN | NO_MIN_RANGE);
230 if (min_flag & NEAR_MIN) max_flag_out |= NEAR_MAX;
231 if (min_flag & NO_MIN_RANGE) max_flag_out |= NO_MAX_RANGE;
232 return max_flag_out;
233}
234
235/**
236 A helper function to invert max flags to min flags for DESC key parts.
237 It changes NEAR_MAX, NO_MAX_RANGE to NEAR_MIN, NO_MIN_RANGE appropriately
238*/
239
240inline uint invert_max_flag(uint max_flag) {
241 uint min_flag_out = max_flag & ~(NEAR_MAX | NO_MAX_RANGE);
242 if (max_flag & NEAR_MAX) min_flag_out |= NEAR_MIN;
243 if (max_flag & NO_MAX_RANGE) min_flag_out |= NO_MIN_RANGE;
244 return min_flag_out;
245}
246
247/*
248 A construction block of the SEL_ARG-graph.
249
250 One SEL_ARG object represents an "elementary interval" in form
251
252 min_value <=? table.keypartX <=? max_value
253
254 The interval is a non-empty interval of any kind: with[out] minimum/maximum
255 bound, [half]open/closed, single-point interval, etc.
256
257 1. SEL_ARG GRAPH STRUCTURE
258
259 SEL_ARG objects are linked together in a graph, represented by the SEL_ROOT.
260 The meaning of the graph is better demonstrated by an example:
261
262 tree->keys[i]
263 |
264 | $ $
265 | part=1 $ part=2 $ part=3
266 | $ $
267 | +-------+ $ +-------+ $ +--------+
268 | | kp1<1 |--$-->| kp2=5 |--$-->| kp3=10 |
269 | +-------+ $ +-------+ $ +--------+
270 | | $ $ |
271 | | $ $ +--------+
272 | | $ $ | kp3=12 |
273 | | $ $ +--------+
274 | +-------+ $ $
275 \->| kp1=2 |--$--------------$-+
276 +-------+ $ $ | +--------+
277 | $ $ ==>| kp3=11 |
278 +-------+ $ $ | +--------+
279 | kp1=3 |--$--------------$-+ |
280 +-------+ $ $ +--------+
281 | $ $ | kp3=14 |
282 ... $ $ +--------+
283
284 The entire graph is partitioned into "interval lists".
285
286 An interval list is a sequence of ordered disjoint intervals over
287 the same key part. SEL_ARG are linked via "next" and "prev" pointers
288 with NULL as sentinel.
289
290 In the example pic, there are 4 interval lists:
291 "kp<1 OR kp1=2 OR kp1=3", "kp2=5", "kp3=10 OR kp3=12", "kp3=11 OR kp3=13".
292 The vertical lines represent SEL_ARG::next/prev pointers.
293
294 Additionally, all intervals in the list form a red-black (RB) tree,
295 linked via left/right/parent pointers with null_element as sentinel. The
296 red-black tree root SEL_ARG object will be further called "root of the
297 interval list".
298
299 A red-black tree with 7 SEL_ARGs will look similar to what is shown
300 below. Left/right/parent pointers are shown while next pointers go from a
301 node with number X to the node with number X+1 (and prev in the
302 opposite direction):
303
304 Root
305 +---+
306 | 4 |
307 +---+
308 left/ \ right
309 __/ \__
310 / \
311 +---+ +---+
312 | 2 | | 6 |
313 +---+ +---+
314 left / \ right left / \ right
315 | | | |
316 +---+ +---+ +---+ +---+
317 | 1 | | 3 | | 5 | | 7 |
318 +---+ +---+ +---+ +---+
319
320 In this tree,
321 * node1->prev == node7->next == NULL
322 * node1->left == node1->right ==
323 node3->left == ... node7->right == null_element
324
325 In an interval list, each member X may have SEL_ARG::next_key_part pointer
326 pointing to the root of another interval list Y. The pointed interval list
327 must cover a key part with greater number (i.e. Y->part > X->part).
328
329 In the example pic, the next_key_part pointers are represented by
330 horisontal lines.
331
332 2. SEL_ARG GRAPH SEMANTICS
333
334 It represents a condition in a special form (we don't have a name for it ATM)
335 The SEL_ARG::next/prev is "OR", and next_key_part is "AND".
336
337 For example, the picture represents the condition in form:
338 (kp1 < 1 AND kp2=5 AND (kp3=10 OR kp3=12)) OR
339 (kp1=2 AND (kp3=11 OR kp3=14)) OR
340 (kp1=3 AND (kp3=11 OR kp3=14))
341
342 In red-black tree form:
343
344 +-------+ +--------+
345 | kp1=2 |.................| kp3=14 |
346 +-------+ +--------+
347 / \ /
348 +---------+ +-------+ +--------+
349 | kp1 < 1 | | kp1=3 | | kp3=11 |
350 +---------+ +-------+ +--------+
351 . .
352 ...... .......
353 . .
354 +-------+ +--------+
355 | kp2=5 | | kp3=14 |
356 +-------+ +--------+
357 . /
358 . +--------+
359 (root of R-B tree | kp3=11 |
360 for "kp3={10|12}") +--------+
361
362
363 Where / and \ denote left and right pointers and ... denotes
364 next_key_part pointers to the root of the R-B tree of intervals for
365 consecutive key parts.
366
367 3. SEL_ARG GRAPH USE
368
369 Use get_mm_tree() to construct SEL_ARG graph from WHERE condition.
370 Then walk the SEL_ARG graph and get a list of dijsoint ordered key
371 intervals (i.e. intervals in form
372
373 (constA1, .., const1_K) < (keypart1,.., keypartK) < (constB1, .., constB_K)
374
375 Those intervals can be used to access the index. The uses are in:
376 - check_quick_select() - Walk the SEL_ARG graph and find an estimate of
377 how many table records are contained within all
378 intervals.
379 - get_ranges_from_tree() - Walk the SEL_ARG, materialize the key intervals.
380
381 4. SPACE COMPLEXITY NOTES
382
383 SEL_ARG graph is a representation of an ordered disjoint sequence of
384 intervals over the ordered set of index tuple values.
385
386 For multi-part keys, one can construct a WHERE expression such that its
387 list of intervals will be of combinatorial size. Here is an example:
388
389 (keypart1 IN (1,2, ..., n1)) AND
390 (keypart2 IN (1,2, ..., n2)) AND
391 (keypart3 IN (1,2, ..., n3))
392
393 For this WHERE clause the list of intervals will have n1*n2*n3 intervals
394 of form
395
396 (keypart1, keypart2, keypart3) = (k1, k2, k3), where 1 <= k{i} <= n{i}
397
398 SEL_ARG graph structure aims to reduce the amount of required space by
399 "sharing" the elementary intervals when possible (the pic at the
400 beginning of this comment has examples of such sharing). The sharing may
401 prevent combinatorial blowup:
402
403 There are WHERE clauses that have combinatorial-size interval lists but
404 will be represented by a compact SEL_ARG graph.
405 Example:
406 (keypartN IN (1,2, ..., n1)) AND
407 ...
408 (keypart2 IN (1,2, ..., n2)) AND
409 (keypart1 IN (1,2, ..., n3))
410
411 but not in all cases:
412
413 - There are WHERE clauses that do have a compact SEL_ARG-graph
414 representation but get_mm_tree() and its callees will construct a
415 graph of combinatorial size.
416 Example:
417 (keypart1 IN (1,2, ..., n1)) AND
418 (keypart2 IN (1,2, ..., n2)) AND
419 ...
420 (keypartN IN (1,2, ..., n3))
421
422 - There are WHERE clauses for which the minimal possible SEL_ARG graph
423 representation will have combinatorial size.
424 Example:
425 By induction: Let's take any interval on some keypart in the middle:
426
427 kp15=c0
428
429 Then let's AND it with this interval 'structure' from preceding and
430 following keyparts:
431
432 (kp14=c1 AND kp16=c3) OR keypart14=c2) (*)
433
434 We will obtain this SEL_ARG graph:
435
436 kp14 $ kp15 $ kp16
437 $ $
438 +---------+ $ +---------+ $ +---------+
439 | kp14=c1 |--$-->| kp15=c0 |--$-->| kp16=c3 |
440 +---------+ $ +---------+ $ +---------+
441 | $ $
442 +---------+ $ +---------+ $
443 | kp14=c2 |--$-->| kp15=c0 | $
444 +---------+ $ +---------+ $
445 $ $
446
447 Note that we had to duplicate "kp15=c0" and there was no way to avoid
448 that.
449 The induction step: AND the obtained expression with another "wrapping"
450 expression like (*).
451 When the process ends because of the limit on max. number of keyparts
452 we'll have:
453
454 WHERE clause length is O(3*#max_keyparts)
455 SEL_ARG graph size is O(2^(#max_keyparts/2))
456
457 (it is also possible to construct a case where instead of 2 in 2^n we
458 have a bigger constant, e.g. 4, and get a graph with 4^(31/2)= 2^31
459 nodes)
460
461 We avoid consuming too much memory by setting a limit on the number of
462 SEL_ARG object we can construct during one range analysis invocation.
463*/
464
465class SEL_ARG {
466 public:
468
469 /**
470 maybe_flag signals that this range is AND-ed with some unknown range
471 (a MAYBE_KEY node). This means that the range could be smaller than
472 what it would otherwise denote; e.g., a range such as
473
474 (0 < x < 3) AND x=( SELECT ... )
475
476 could in reality be e.g. (1 < x < 2), depending on what the subselect
477 returns (and we don't know that when planning), but it could never be
478 bigger.
479
480 FIXME: It's unclear if this is really kept separately per SEL_ARG or is
481 meaningful only at the root node, and thus should be moved to the
482 SEL_ROOT. Most code seems to assume the latter, but a few select places,
483 non-root nodes appear to be modified.
484 */
485 bool maybe_flag{false};
486
487 /*
488 Which key part. TODO: This is the same for all values in a SEL_ROOT,
489 so we should move it there.
490 */
492
493 bool maybe_null() const { return field->is_nullable(); }
494
495 /**
496 The rtree index interval to scan, undefined unless
497 SEL_ARG::min_flag == GEOM_FLAG.
498 */
500
501 /*
502 TODO: This is the same for all values in a SEL_ROOT, so we should
503 move it there; however, be careful about cmp_* functions.
504 Note that this should never be nullptr except in the special case
505 where we have a dummy SEL_ARG to hold next_key_part only
506 (see SEL_ROOT::root for more information).
507 */
508 Field *field{nullptr};
509 uchar *min_value, *max_value; // Pointer to range
510
511 /*
512 eq_tree(), first(), last() etc require that left == right == NULL
513 if the type is MAYBE_KEY. Todo: fix this so SEL_ARGs without R-B
514 children are handled consistently. See related WL#5894.
515 */
516 SEL_ARG *left, *right; /* R-B tree children */
517 SEL_ARG *next, *prev; /* Links for bi-directional interval list */
518 SEL_ARG *parent{nullptr}; /* R-B tree parent (nullptr for root) */
519 /*
520 R-B tree of intervals covering keyparts consecutive to this
521 SEL_ARG. See documentation of SEL_ARG GRAPH semantics for details.
522 */
524
525 /**
526 Convenience function for removing the next_key_part. The typical
527 use for this function is to disconnect the next_key_part from the
528 root, send it to key_and() or key_or(), and then connect the
529 result of that function back to the SEL_ARG using set_next_key_part().
530
531 @return The previous value of next_key_part.
532 */
534 SEL_ROOT *ret = next_key_part;
535 if (next_key_part) {
536 assert(next_key_part->use_count > 0);
538 }
539 next_key_part = nullptr;
540 return ret;
541 }
542
543 /**
544 Convenience function for changing next_key_part, including
545 updating the use_count. The argument is allowed to be nullptr.
546
547 @param next_key_part_arg New value for next_key_part.
548 */
549 void set_next_key_part(SEL_ROOT *next_key_part_arg) {
551 next_key_part = next_key_part_arg;
553 }
554
556
557 bool is_ascending; ///< true - ASC order, false - DESC
558
559 SEL_ARG() = default;
560 SEL_ARG(SEL_ARG &);
561 SEL_ARG(Field *, const uchar *, const uchar *, bool asc);
563 uint8 min_flag, uint8 max_flag, bool maybe_flag, bool asc,
564 ha_rkey_function gis_flag);
565 /**
566 Note that almost all SEL_ARGs are created on the MEM_ROOT,
567 so this destructor will only rarely be called.
568 */
570
571 /**
572 returns true if a range predicate is equal. Use all_same()
573 to check for equality of all the predicates on this keypart.
574 */
575 inline bool is_same(const SEL_ARG *arg) const {
576 if (part != arg->part) return false;
577 return cmp_min_to_min(arg) == 0 && cmp_max_to_max(arg) == 0;
578 }
579
580 inline void merge_flags(SEL_ARG *arg) { maybe_flag |= arg->maybe_flag; }
581 inline void maybe_smaller() { maybe_flag = true; }
582 /* Return true iff it's a single-point null interval */
583 inline bool is_null_interval() { return maybe_null() && max_value[0] == 1; }
584 inline int cmp_min_to_min(const SEL_ARG *arg) const {
585 return sel_cmp(field, min_value, arg->min_value, min_flag, arg->min_flag);
586 }
587 inline int cmp_min_to_max(const SEL_ARG *arg) const {
588 return sel_cmp(field, min_value, arg->max_value, min_flag, arg->max_flag);
589 }
590 inline int cmp_max_to_max(const SEL_ARG *arg) const {
591 return sel_cmp(field, max_value, arg->max_value, max_flag, arg->max_flag);
592 }
593 inline int cmp_max_to_min(const SEL_ARG *arg) const {
594 return sel_cmp(field, max_value, arg->min_value, max_flag, arg->min_flag);
595 }
597 MEM_ROOT *mem_root) { // Get intersection of ranges.
598 uchar *new_min, *new_max;
599 uint8 flag_min, flag_max;
600 if (cmp_min_to_min(arg) >= 0) {
601 new_min = min_value;
602 flag_min = min_flag;
603 } else {
604 new_min = arg->min_value;
605 flag_min = arg->min_flag; /* purecov: deadcode */
606 }
607 if (cmp_max_to_max(arg) <= 0) {
608 new_max = max_value;
609 flag_max = max_flag;
610 } else {
611 new_max = arg->max_value;
612 flag_max = arg->max_flag;
613 }
614 return new (mem_root)
615 SEL_ARG(field, part, new_min, new_max, flag_min, flag_max,
618 }
620 MEM_ROOT *mem_root) { // arg->min <= X < arg->min
621 return new (mem_root) SEL_ARG(
623 arg->min_flag & NEAR_MIN ? 0 : NEAR_MAX, maybe_flag || arg->maybe_flag,
625 }
627 MEM_ROOT *mem_root) { // arg->min <= X <= key_max
628 return new (mem_root)
632 }
633 SEL_ARG *clone(RANGE_OPT_PARAM *param, SEL_ARG *new_parent, SEL_ARG **next);
634
635 bool copy_min(SEL_ARG *arg) { // max(this->min, arg->min) <= x <= this->max
636 if (cmp_min_to_min(arg) > 0) {
637 min_value = arg->min_value;
638 min_flag = arg->min_flag;
640 return true; // Full range
641 }
642 maybe_flag |= arg->maybe_flag;
643 return false;
644 }
645 bool copy_max(SEL_ARG *arg) { // this->min <= x <= min(this->max, arg->max)
646 if (cmp_max_to_max(arg) <= 0) {
647 max_value = arg->max_value;
648 max_flag = arg->max_flag;
650 return true; // Full range
651 }
652 maybe_flag |= arg->maybe_flag;
653 return false;
654 }
655
657 min_value = arg->min_value;
658 min_flag = arg->min_flag;
659 }
661 max_value = arg->min_value;
662 max_flag = arg->min_flag & NEAR_MIN ? 0 : NEAR_MAX;
663 }
665 min_value = arg->max_value;
666 min_flag = arg->max_flag & NEAR_MAX ? 0 : NEAR_MIN;
667 }
668
669 /**
670 Set spatial index range scan parameters. This object will be used to do
671 spatial index range scan after this call.
672
673 @param rkey_func The scan function to perform. It must be one of the
674 spatial index specific scan functions.
675 */
677 assert(rkey_func >= HA_READ_MBR_CONTAIN && rkey_func <= HA_READ_MBR_EQUAL);
679 rkey_func_flag = rkey_func;
681 }
682
683 /* returns a number of keypart values (0 or 1) appended to the key buffer */
684 int store_min_value(uint length, uchar **min_key, uint min_key_flag) {
685 /* "(kp1 > c1) AND (kp2 OP c2) AND ..." -> (kp1 > c1) */
686 if ((min_flag & GEOM_FLAG) ||
687 (!(min_flag & NO_MIN_RANGE) &&
688 !(min_key_flag & (NO_MIN_RANGE | NEAR_MIN)))) {
689 if (maybe_null() && *min_value) {
690 **min_key = 1;
691 memset(*min_key + 1, 0, length - 1);
692 } else
693 memcpy(*min_key, min_value, length);
694 (*min_key) += length;
695 return 1;
696 }
697 return 0;
698 }
699 /* returns a number of keypart values (0 or 1) appended to the key buffer */
700 int store_max_value(uint length, uchar **max_key, uint max_key_flag) {
701 if (!(max_flag & NO_MAX_RANGE) &&
702 !(max_key_flag & (NO_MAX_RANGE | NEAR_MAX))) {
703 if (maybe_null() && *max_value) {
704 **max_key = 1;
705 memset(*max_key + 1, 0, length - 1);
706 } else
707 memcpy(*max_key, max_value, length);
708 (*max_key) += length;
709 return 1;
710 }
711 return 0;
712 }
713
714 /*
715 Returns a number of keypart values appended to the key buffer
716 for min key and max key. This function is used by both Range
717 Analysis and Partition pruning. For partition pruning we have
718 to ensure that we don't store also subpartition fields. Thus
719 we have to stop at the last partition part and not step into
720 the subpartition fields. For Range Analysis we set last_part
721 to MAX_KEY which we should never reach.
722
723 Note: Caller of this function should take care of sending the
724 correct flags and correct key to be stored into. In case of
725 ascending indexes, store_min_key() gets called to store the
726 min_value to range start_key. In case of descending indexes, it's
727 called for storing min_value to range end_key.
728 */
729 /**
730 Helper function for storing min/max values of SEL_ARG taking into account
731 key part's order.
732 */
733 void store_min_max_values(uint length, uchar **min_key, uint min_flag,
734 uchar **max_key, uint max_flag, int *min_part,
735 int *max_part) {
736 if (is_ascending) {
737 *min_part += store_min_value(length, min_key, min_flag);
738 *max_part += store_max_value(length, max_key, max_flag);
739 } else {
740 *max_part += store_min_value(length, max_key, min_flag);
741 *min_part += store_max_value(length, min_key, max_flag);
742 }
743 }
744
745 /**
746 Helper function for storing min/max keys of next SEL_ARG taking into
747 account key part's order.
748
749 @note On checking min/max flags: Flags are used to track whether there's
750 a partial key in the key buffer. So for ASC key parts the flag
751 corresponding to the key being added to should be checked, not
752 corresponding to the value being added. I.e min_flag for min_key.
753 For DESC key parts it's opposite - max_flag for min_key. It's flag
754 of prev key part that should be checked.
755
756 */
758 uint *cur_min_flag, uchar **cur_max_key,
759 uint *cur_max_flag, int *min_part,
760 int *max_part) {
761 assert(next_key_part);
762 const bool asc = next_key_part->root->is_ascending;
763 if (!get_min_flag()) {
764 if (asc)
765 *min_part += next_key_part->store_min_key(key, cur_min_key,
766 cur_min_flag, MAX_KEY, true);
767 else {
768 uint tmp_flag = invert_min_flag(*cur_min_flag);
769 *min_part += next_key_part->store_max_key(key, cur_min_key, &tmp_flag,
770 MAX_KEY, true);
771 *cur_min_flag = invert_max_flag(tmp_flag);
772 }
773 }
774 if (!get_max_flag()) {
775 if (asc)
776 *max_part += next_key_part->store_max_key(key, cur_max_key,
777 cur_max_flag, MAX_KEY, false);
778 else {
779 uint tmp_flag = invert_max_flag(*cur_max_flag);
780 *max_part += next_key_part->store_min_key(key, cur_max_key, &tmp_flag,
781 MAX_KEY, false);
782 *cur_max_flag = invert_min_flag(tmp_flag);
783 }
784 }
785 }
786
787 SEL_ARG *rb_insert(SEL_ARG *leaf);
788 friend SEL_ARG *rb_delete_fixup(SEL_ARG *root, SEL_ARG *key, SEL_ARG *par);
789#ifndef NDEBUG
790 friend int test_rb_tree(SEL_ARG *element, SEL_ARG *parent);
791#endif
792 SEL_ARG *first();
793 const SEL_ARG *first() const;
794 SEL_ARG *last();
795 void make_root() {
797 color = BLACK;
798 parent = next = prev = nullptr;
799 }
800
801 inline SEL_ARG **parent_ptr() {
802 return parent->left == this ? &parent->left : &parent->right;
803 }
804
805 /*
806 Check if this SEL_ARG object represents a single-point interval
807
808 SYNOPSIS
809 is_singlepoint()
810
811 DESCRIPTION
812 Check if this SEL_ARG object (not tree) represents a single-point
813 interval, i.e. if it represents a "keypart = const" or
814 "keypart IS NULL".
815
816 RETURN
817 true This SEL_ARG object represents a singlepoint interval
818 false Otherwise
819 */
820
821 bool is_singlepoint() const {
822 /*
823 Check for NEAR_MIN ("strictly less") and NO_MIN_RANGE (-inf < field)
824 flags, and the same for right edge.
825 */
826 if (min_flag || max_flag) return false;
827 uchar *min_val = min_value;
828 uchar *max_val = max_value;
829
830 if (maybe_null()) {
831 /* First byte is a NULL value indicator */
832 if (*min_val != *max_val) return false;
833
834 if (*min_val) return true; /* This "x IS NULL" */
835 min_val++;
836 max_val++;
837 }
838 return !field->key_cmp(min_val, max_val);
839 }
840 /**
841 Return correct min_flag.
842
843 For DESC key parts max flag should be used as min flag, but in order to
844 be checked correctly, max flag should be flipped as code doesn't expect
845 e.g NEAR_MAX in min flag.
846 */
849 }
850 /**
851 Return correct max_flag.
852
853 For DESC key parts min flag should be used as max flag, but in order to
854 be checked correctly, min flag should be flipped as code doesn't expect
855 e.g NEAR_MIN in max flag.
856 */
859 }
860};
861
862inline bool SEL_ROOT::is_always() const {
863 return type == Type::KEY_RANGE && elements == 1 && !root->maybe_flag &&
865}
866
867inline bool SEL_ROOT::simple_key() const {
868 return elements == 1 && !root->next_key_part;
869}
870
871class SEL_TREE {
872 public:
873 /**
874 Starting an effort to document this field:
875
876 IMPOSSIBLE: if keys[i]->type == SEL_ROOT::Type::IMPOSSIBLE for some i,
877 then type == SEL_TREE::IMPOSSIBLE. Rationale: if the predicate for
878 one of the indexes is always false, then the full predicate is also
879 always false.
880
881 ALWAYS: if either (keys[i]->is_always()) or (keys[i] == NULL) for all i,
882 then type == SEL_TREE::ALWAYS. Rationale: the range access method
883 will not be able to filter out any rows when there are no range
884 predicates that can be used to filter on any index.
885
886 KEY: There are range predicates that can be used on at least one
887 index.
888 */
890
891 /**
892 Whether this SEL_TREE is an inexact (too broad) representation of the
893 predicates it is based on; that is, if it does not necessarily subsume
894 all of them. Note that a nullptr return from get_mm_tree() (which means
895 “could not generate a tree from this predicate”) is by definition inexact.
896
897 There are two main ways a SEL_TREE can become inexact:
898
899 - The predicate references fields not contained in any indexes tracked
900 by the SEL_TREE.
901 - The predicate could be of a form that is not representable as a range.
902 E.g., x > 30 is a range, x mod 2 = 1 is not (although it could
903 in theory be converted to a large amount of disjunct ranges).
904
905 If a SEL_TREE is inexact, the predicates must be rechecked after the
906 range scan, using a filter. (Note that it is never too narrow, only ever
907 exact or too broad.) The old join optimizer always does this, no matter
908 what the inexact flag is set to.
909
910 Note that additional checks are needed to subsume a predicate even if
911 inexact == false. In particular, SEL_TREE contains information for all
912 indexes over a table, but if a regular range scan is chosen, it can use
913 only one index. So one must then go through all predicates to see if they
914 refer to fields not contained in the given index. Furthermore, range scans
915 on composite (multi-part) indexes can drop predicates on the later keyparts
916 (making predicates on those keyparts inexact), since range scans only
917 support inequalities on the last keypart in any given range. This check
918 must be done in get_ranges_from_tree().
919 */
920 bool inexact = false;
921
922 SEL_TREE(enum Type type_arg, MEM_ROOT *root, size_t num_keys)
923 : type(type_arg), keys(root, num_keys), n_ror_scans(0) {}
924 SEL_TREE(MEM_ROOT *root, size_t num_keys)
925 : type(KEY), keys(root, num_keys), n_ror_scans(0) {}
926 /**
927 Constructor that performs deep-copy of the SEL_ARG trees in
928 'keys[]' and the index merge alternatives in 'merges'.
929
930 @param arg The SEL_TREE to copy
931 @param param Parameters for range analysis
932 */
933 SEL_TREE(SEL_TREE *arg, RANGE_OPT_PARAM *param);
934 /*
935 Possible ways to read rows using a single index because the
936 conditions of the query consists of single-index conjunctions:
937
938 (ranges_for_idx_1) AND (ranges_for_idx_2) AND ...
939
940 The SEL_ARG graph for each non-NULL element in keys[] may consist
941 of many single-index ranges (disjunctions), so ranges_for_idx_1
942 may e.g. be:
943
944 "idx_field1 = 1 OR (idx_field1 > 5 AND idx_field2 = 10)"
945
946 assuming that index1 is a composite index covering
947 (idx_field1,...,idx_field2,..)
948
949 Index merge intersection intersects ranges on SEL_ARGs from two or
950 more indexes.
951
952 Note: there may exist SEL_TREE objects with sel_tree->type=KEY and
953 keys[i]=0 for all i. (SergeyP: it is not clear whether there is any
954 merit in range analyzer functions (e.g. get_mm_parts) returning a
955 pointer to such SEL_TREE instead of NULL)
956
957 Note: If you want to set an element in keys[], use set_key()
958 or release_key() to make sure the SEL_ARG's use_count is correctly
959 updated.
960 */
962 Key_map keys_map; /* bitmask of non-NULL elements in keys */
963
964 /*
965 Possible ways to read rows using Index merge (sort) union.
966
967 Each element in 'merges' consists of multi-index disjunctions,
968 which means that Index merge (sort) union must be applied to read
969 rows. The nodes in the 'merges' list forms a conjunction of such
970 multi-index disjunctions.
971
972 The list is non-empty only if type==KEY.
973 */
975
976 /* The members below are filled/used only after get_mm_tree is done */
977 Key_map ror_scans_map; /* bitmask of ROR scan-able elements in keys */
978 uint n_ror_scans; /* number of set bits in ror_scans_map */
979
980 /**
981 Convenience function for removing an element in keys[]. The typical
982 use for this function is to disconnect the next_key_part from the
983 root, send it to key_and() or key_or(), and then connect the
984 result of that function back to the SEL_ROOT using set_key().
985
986 @param index Which index slot to release.
987 @return The value in the slot (before removal).
988 */
989 SEL_ROOT *release_key(int index) {
990 SEL_ROOT *ret = keys[index];
991 if (keys[index]) {
992 assert(keys[index]->use_count > 0);
993 --keys[index]->use_count;
994 }
995 keys[index] = nullptr;
996 return ret;
997 }
998
999 /**
1000 Convenience function for changing an element in keys[], including
1001 updating the use_count.
1002
1003 @param index Which index slot to change.
1004 @param key The new contents of the index slot. Is allowed to be nullptr.
1005 */
1006 void set_key(int index, SEL_ROOT *key) {
1007 release_key(index);
1008 keys[index] = key;
1009 if (key) ++key->use_count;
1010 }
1011};
1012
1013#ifndef NDEBUG
1014void print_sel_tree(RANGE_OPT_PARAM *param, SEL_TREE *tree, Key_map *tree_map,
1015 const char *msg);
1016#endif
1017
1018/*
1019 Get the SEL_ARG tree 'tree' for the keypart covering 'field', if
1020 any. 'tree' must be a unique conjunction to ALL predicates in earlier
1021 keyparts of 'keypart_tree'.
1022
1023 E.g., if 'keypart_tree' is for a composite index (kp1,kp2) and kp2
1024 covers 'field', all these conditions satisfies the requirement:
1025
1026 1. "(kp1=2 OR kp1=3) AND kp2=10" => returns "kp2=10"
1027 2. "(kp1=2 AND kp2=10) OR (kp1=3 AND kp2=10)" => returns "kp2=10"
1028 3. "(kp1=2 AND (kp2=10 OR kp2=11)) OR (kp1=3 AND (kp2=10 OR kp2=11))"
1029 => returns "kp2=10 OR kp2=11"
1030
1031 whereas these do not
1032 1. "(kp1=2 AND kp2=10) OR kp1=3"
1033 2. "(kp1=2 AND kp2=10) OR (kp1=3 AND kp2=11)"
1034 3. "(kp1=2 AND kp2=10) OR (kp1=3 AND (kp2=10 OR kp2=11))"
1035
1036 This function effectively tests requirement WA2.
1037
1038 @param[in] key_part_num Key part number we want the SEL_ARG tree for
1039 @param[in] keypart_tree The SEL_ARG* tree for the index
1040 @param[out] cur_range The SEL_ARG tree, if any, for the keypart
1041
1042 @retval true 'keypart_tree' contained a predicate for key part that
1043 is not conjunction to all predicates on earlier keyparts
1044 @retval false otherwise
1045*/
1046bool get_sel_root_for_keypart(uint key_part_num, SEL_ROOT *keypart_tree,
1047 SEL_ROOT **cur_range);
1048
1049/*
1050 Find the SEL_ROOT tree that corresponds to the chosen index.
1051
1052 SYNOPSIS
1053 get_index_range_tree()
1054 index [in] The ID of the index being looked for
1055 range_tree[in] Tree of ranges being searched
1056 param [in] RANGE_OPT_PARAM from test_quick_select
1057
1058 DESCRIPTION
1059
1060 A SEL_TREE contains range trees for all usable indexes. This procedure
1061 finds the SEL_ROOT tree for 'index'. The members of a SEL_TREE are
1062 ordered in the same way as the members of RANGE_OPT_PARAM::key, thus we
1063 first find the corresponding index in the array RANGE_OPT_PARAM::key.
1064 This index is returned through the variable param_idx, to be used later
1065 as argument of check_quick_select().
1066
1067 RETURN
1068 Pointer to the SEL_ROOT tree that corresponds to index.
1069*/
1070
1071inline SEL_ROOT *get_index_range_tree(uint index, SEL_TREE *range_tree,
1072 RANGE_OPT_PARAM *param) {
1073 uint idx = 0; /* Index nr in param->key_parts */
1074 while (idx < param->keys) {
1075 if (index == param->real_keynr[idx]) break;
1076 idx++;
1077 }
1078 return (range_tree->keys[idx]);
1079}
1080
1081/**
1082 Print the ranges in a SEL_TREE to debug log.
1083
1084 @param tree_name Descriptive name of the tree
1085 @param tree The SEL_TREE that will be printed to debug log
1086 @param param RANGE_OPT_PARAM from test_quick_select
1087*/
1088inline void dbug_print_tree([[maybe_unused]] const char *tree_name,
1089 [[maybe_unused]] SEL_TREE *tree,
1090 [[maybe_unused]] const RANGE_OPT_PARAM *param) {
1091#ifndef NDEBUG
1092 if (_db_enabled_()) print_tree(nullptr, tree_name, tree, param, true);
1093#endif
1094}
1095
1096#endif // SQL_RANGE_OPTIMIZER_TREE_H_
Definition: sql_bitmap.h:154
Used to store optimizer cost estimates.
Definition: handler.h:3864
Definition: field.h:575
bool is_nullable() const
Definition: field.h:1291
virtual int key_cmp(const uchar *a, const uchar *b) const
Definition: field.h:1196
Definition: key.h:113
Definition: sql_list.h:467
A typesafe replacement for DYNAMIC_ARRAY.
Definition: mem_root_array.h:426
Definition: range_opt_param.h:29
uint * real_keynr
Definition: range_opt_param.h:69
Definition: tree.h:465
void set_next_key_part(SEL_ROOT *next_key_part_arg)
Convenience function for changing next_key_part, including updating the use_count.
Definition: tree.h:549
SEL_ARG * first()
This gives the first SEL_ARG in the interval list, and the minimal element in the red-black tree.
Definition: tree.cc:386
void copy_max_to_min(SEL_ARG *arg)
Definition: tree.h:664
bool copy_min(SEL_ARG *arg)
Definition: tree.h:635
SEL_ARG * last()
Definition: tree.cc:397
SEL_ARG * rb_insert(SEL_ARG *leaf)
Definition: tree.cc:1886
void set_gis_index_read_function(const enum ha_rkey_function rkey_func)
Set spatial index range scan parameters.
Definition: tree.h:676
bool is_same(const SEL_ARG *arg) const
returns true if a range predicate is equal.
Definition: tree.h:575
bool maybe_flag
maybe_flag signals that this range is AND-ed with some unknown range (a MAYBE_KEY node).
Definition: tree.h:485
SEL_ROOT * release_next_key_part()
Convenience function for removing the next_key_part.
Definition: tree.h:533
enum ha_rkey_function rkey_func_flag
The rtree index interval to scan, undefined unless SEL_ARG::min_flag == GEOM_FLAG.
Definition: tree.h:499
bool is_ascending
true - ASC order, false - DESC
Definition: tree.h:557
SEL_ARG * clone(RANGE_OPT_PARAM *param, SEL_ARG *new_parent, SEL_ARG **next)
Definition: tree.cc:345
void copy_min_to_min(SEL_ARG *arg)
Definition: tree.h:656
SEL_ROOT * next_key_part
Definition: tree.h:523
uchar * min_value
Definition: tree.h:509
void copy_min_to_max(SEL_ARG *arg)
Definition: tree.h:660
uint8 part
Definition: tree.h:491
Field * field
Definition: tree.h:508
SEL_ARG * prev
Definition: tree.h:517
void make_root()
Definition: tree.h:795
SEL_ARG * clone_and(SEL_ARG *arg, MEM_ROOT *mem_root)
Definition: tree.h:596
int store_min_value(uint length, uchar **min_key, uint min_key_flag)
Definition: tree.h:684
uint get_min_flag()
Return correct min_flag.
Definition: tree.h:847
bool maybe_null() const
Definition: tree.h:493
SEL_ARG * parent
Definition: tree.h:518
leaf_color
Definition: tree.h:555
@ RED
Definition: tree.h:555
@ BLACK
Definition: tree.h:555
bool is_null_interval()
Definition: tree.h:583
int cmp_max_to_max(const SEL_ARG *arg) const
Definition: tree.h:590
uchar * max_value
Definition: tree.h:509
void maybe_smaller()
Definition: tree.h:581
SEL_ARG * right
Definition: tree.h:516
~SEL_ARG()
Note that almost all SEL_ARGs are created on the MEM_ROOT, so this destructor will only rarely be cal...
Definition: tree.h:569
void store_min_max_values(uint length, uchar **min_key, uint min_flag, uchar **max_key, uint max_flag, int *min_part, int *max_part)
Helper function for storing min/max values of SEL_ARG taking into account key part's order.
Definition: tree.h:733
enum SEL_ARG::leaf_color color
int store_max_value(uint length, uchar **max_key, uint max_key_flag)
Definition: tree.h:700
SEL_ARG()=default
uint8 max_flag
Definition: tree.h:467
SEL_ARG * left
Definition: tree.h:516
void store_next_min_max_keys(KEY_PART *key, uchar **cur_min_key, uint *cur_min_flag, uchar **cur_max_key, uint *cur_max_flag, int *min_part, int *max_part)
Helper function for storing min/max keys of next SEL_ARG taking into account key part's order.
Definition: tree.h:757
SEL_ARG * next
Definition: tree.h:517
int cmp_max_to_min(const SEL_ARG *arg) const
Definition: tree.h:593
int cmp_min_to_max(const SEL_ARG *arg) const
Definition: tree.h:587
bool copy_max(SEL_ARG *arg)
Definition: tree.h:645
uint get_max_flag()
Return correct max_flag.
Definition: tree.h:857
uint8 min_flag
Definition: tree.h:467
bool is_singlepoint() const
Definition: tree.h:821
void merge_flags(SEL_ARG *arg)
Definition: tree.h:580
SEL_ARG ** parent_ptr()
Definition: tree.h:801
SEL_ARG * clone_last(SEL_ARG *arg, MEM_ROOT *mem_root)
Definition: tree.h:626
friend int test_rb_tree(SEL_ARG *element, SEL_ARG *parent)
Definition: tree.cc:2007
friend SEL_ARG * rb_delete_fixup(SEL_ARG *root, SEL_ARG *key, SEL_ARG *par)
Definition: tree.cc:1939
SEL_ARG * clone_first(SEL_ARG *arg, MEM_ROOT *mem_root)
Definition: tree.h:619
int cmp_min_to_min(const SEL_ARG *arg) const
Definition: tree.h:584
A graph of (possible multiple) key ranges, represented as a red-black binary tree.
Definition: tree.h:68
Type
Used to indicate if the range predicate for an index is always true/false, depends on values from oth...
Definition: tree.h:75
@ KEY_RANGE
There is a range condition that can be used on this index.
@ MAYBE_KEY
There is a range predicate that refers to another table.
@ IMPOSSIBLE
The range predicate for this index is always false.
uint16 elements
Number of nodes in the RB-tree, not including sentinels.
Definition: tree.h:218
bool test_use_count(const SEL_ROOT *root) const
Check if SEL_ROOT::use_count value is correct.
Definition: tree.cc:2102
SEL_ROOT(SEL_ARG *root)
Constructs a tree of type KEY_RANGE, using the given root.
Definition: tree.cc:460
~SEL_ROOT()
Note that almost all SEL_ROOTs are created on the MEM_ROOT, so this destructor will only rarely be ca...
Definition: tree.h:110
int store_min_key(KEY_PART *key, uchar **range_key, uint *range_key_flag, uint last_part, bool start_key)
Returns a number of keypart values appended to the key buffer for min key and max key.
Definition: tree.cc:87
SEL_ROOT * clone_tree(RANGE_OPT_PARAM *param) const
Create a new tree that's a duplicate of this one.
Definition: tree.cc:475
SEL_ARG * find_range(const SEL_ARG *key) const
Find best key with min <= given key.
Definition: tree.cc:1767
void free_tree()
Signal to the tree that the caller will shortly be dropping it on the floor; if others are still usin...
Definition: tree.cc:151
SEL_ARG * root
The root node of the tree.
Definition: tree.h:203
bool simple_key() const
Returns true iff this is a single-element, single-field predicate.
Definition: tree.h:867
void insert(SEL_ARG *key)
Insert the given node into the tree, and update the root.
Definition: tree.cc:1717
bool is_always() const
Returns true iff we have a single node that has no max nor min.
Definition: tree.h:862
void tree_delete(SEL_ARG *key)
Delete the given node from the tree, and update the root.
Definition: tree.cc:1794
int store_max_key(KEY_PART *key, uchar **range_key, uint *range_key_flag, uint last_part, bool start_key)
Definition: tree.cc:124
enum SEL_ROOT::Type type
ulong use_count
Number of references to this SEL_ARG tree.
Definition: tree.h:213
Definition: tree.h:871
enum SEL_TREE::Type type
Key_map keys_map
Definition: tree.h:962
uint n_ror_scans
Definition: tree.h:978
bool inexact
Whether this SEL_TREE is an inexact (too broad) representation of the predicates it is based on; that...
Definition: tree.h:920
List< SEL_IMERGE > merges
Definition: tree.h:974
SEL_TREE(MEM_ROOT *root, size_t num_keys)
Definition: tree.h:924
SEL_ROOT * release_key(int index)
Convenience function for removing an element in keys[].
Definition: tree.h:989
Key_map ror_scans_map
Definition: tree.h:977
Type
Starting an effort to document this field:
Definition: tree.h:889
@ IMPOSSIBLE
Definition: tree.h:889
@ ALWAYS
Definition: tree.h:889
void set_key(int index, SEL_ROOT *key)
Convenience function for changing an element in keys[], including updating the use_count.
Definition: tree.h:1006
SEL_TREE(enum Type type_arg, MEM_ROOT *root, size_t num_keys)
Definition: tree.h:922
Mem_root_array< SEL_ROOT * > keys
Definition: tree.h:961
static MEM_ROOT mem_root
Definition: client_plugin.cc:114
static uint16 key1[1001]
Definition: hp_test2.cc:50
static uint keys
Definition: hp_test2.cc:49
void print_tree(String *out, const char *tree_name, SEL_TREE *tree, const RANGE_OPT_PARAM *param, const bool print_full)
Definition: range_optimizer.cc:1691
This file follows Google coding style, except for the name MEM_ROOT (which is kept for historical rea...
This file includes constants used by all storage engines.
ha_rkey_function
Definition: my_base.h:78
@ HA_READ_MBR_EQUAL
Definition: my_base.h:91
@ HA_READ_INVALID
Definition: my_base.h:93
@ HA_READ_MBR_CONTAIN
Definition: my_base.h:87
@ NEAR_MIN
Definition: my_base.h:1083
@ NO_MIN_RANGE
from -inf
Definition: my_base.h:1080
@ NO_MAX_RANGE
to +inf
Definition: my_base.h:1081
@ NEAR_MAX
Definition: my_base.h:1085
@ GEOM_FLAG
This flag means that the index is an rtree index, and the interval is specified using HA_READ_MBR_XXX...
Definition: my_base.h:1107
int _db_enabled_()
Definition: dbug.cc:1278
Some integer typedefs for easier portability.
uint8_t uint8
Definition: my_inttypes.h:63
unsigned char uchar
Definition: my_inttypes.h:52
uint16_t uint16
Definition: my_inttypes.h:65
bool length(const dd::Spatial_reference_system *srs, const Geometry *g1, double *length, bool *null) noexcept
Computes the length of linestrings and multilinestrings.
Definition: length.cc:76
SEL_ARG * null_element
Definition: range_optimizer.cc:157
required string key
Definition: replication_asynchronous_connection_failover.proto:60
File containing constants that can be used throughout the server.
constexpr const unsigned int MAX_KEY
Definition: sql_const.h:46
Definition: range_optimizer.h:55
The MEM_ROOT is a simple arena, where allocations are carved out of larger blocks.
Definition: my_alloc.h:83
Definition: rowid_ordered_retrieval_plan.h:44
void dbug_print_tree(const char *tree_name, SEL_TREE *tree, const RANGE_OPT_PARAM *param)
Print the ranges in a SEL_TREE to debug log.
Definition: tree.h:1088
SEL_ROOT * key_and(RANGE_OPT_PARAM *param, SEL_ROOT *key1, SEL_ROOT *key2)
Definition: tree.cc:886
bool sel_trees_can_be_ored(SEL_TREE *tree1, SEL_TREE *tree2, RANGE_OPT_PARAM *param)
Definition: tree.cc:591
SEL_ROOT * get_index_range_tree(uint index, SEL_TREE *range_tree, RANGE_OPT_PARAM *param)
Definition: tree.h:1071
void print_sel_tree(RANGE_OPT_PARAM *param, SEL_TREE *tree, Key_map *tree_map, const char *msg)
Definition: tree.cc:2177
uint invert_min_flag(uint min_flag)
A helper function to invert min flags to max flags for DESC key parts.
Definition: tree.h:228
SEL_ROOT * key_or(RANGE_OPT_PARAM *param, SEL_ROOT *key1, SEL_ROOT *key2)
Combine two range expression under a common OR.
Definition: tree.cc:1079
SEL_TREE * tree_or(RANGE_OPT_PARAM *param, bool remove_jump_scans, SEL_TREE *tree1, SEL_TREE *tree2)
Definition: tree.cc:683
uint invert_max_flag(uint max_flag)
A helper function to invert max flags to min flags for DESC key parts.
Definition: tree.h:240
int sel_cmp(Field *f, uchar *a, uchar *b, uint8 a_flag, uint8 b_flag)
Definition: tree.cc:409
bool get_sel_root_for_keypart(uint key_part_num, SEL_ROOT *keypart_tree, SEL_ROOT **cur_range)
Definition: tree.cc:2136
SEL_TREE * tree_and(RANGE_OPT_PARAM *param, SEL_TREE *tree1, SEL_TREE *tree2)
Definition: tree.cc:502