Drizzled Public API Documentation

sel_imerge.h
1 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2  * vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3  *
4  * Copyright (C) 2008-2009 Sun Microsystems, Inc.
5  *
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.
9  *
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.
14  *
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
18  */
19 
20 #pragma once
21 
22 #include <drizzled/memory/sql_alloc.h>
23 
24 namespace drizzled {
25 namespace optimizer {
26 
27 /*
28  SEL_IMERGE is a list of possible ways to do index merge, i.e. it is
29  a condition in the following form:
30  (t_1||t_2||...||t_N) && (next)
31 
32  where all t_i are optimizer::SEL_TREEs, next is another SEL_IMERGE and no pair
33  (t_i,t_j) contains SEL_ARGS for the same index.
34 
35  optimizer::SEL_TREE contained in SEL_IMERGE always has merges=NULL.
36 
37  This class relies on memory manager to do the cleanup.
38 */
40 {
41  enum { PREALLOCED_TREES= 10};
42 public:
43  SEL_TREE *trees_prealloced[PREALLOCED_TREES];
44  SEL_TREE **trees; /* trees used to do index_merge */
45  SEL_TREE **trees_next; /* last of these trees */
46  SEL_TREE **trees_end; /* end of allocated space */
47 
48  SEL_ARG ***best_keys; /* best keys to read in optimizer::SEL_TREEs */
49 
50  SEL_IMERGE();
51 
52  /*
53  Add optimizer::SEL_TREE to this index_merge without any checks,
54 
55  NOTES
56  This function implements the following:
57  (x_1||...||x_N) || t = (x_1||...||x_N||t), where x_i, t are optimizer::SEL_TREEs
58 
59  RETURN
60  0 - OK
61  -1 - Out of memory.
62  */
63  void or_sel_tree(RangeParameter *param, SEL_TREE *tree);
64 
65  /*
66  Perform OR operation on this SEL_IMERGE and supplied optimizer::SEL_TREE new_tree,
67  combining new_tree with one of the trees in this SEL_IMERGE if they both
68  have SEL_ARGs for the same key.
69 
70  SYNOPSIS
71  or_sel_tree_with_checks()
72  param Parameter from SqlSelect::test_quick_select
73  new_tree optimizer::SEL_TREE with type KEY or KEY_SMALLER.
74 
75  NOTES
76  This does the following:
77  (t_1||...||t_k)||new_tree =
78  either
79  = (t_1||...||t_k||new_tree)
80  or
81  = (t_1||....||(t_j|| new_tree)||...||t_k),
82 
83  where t_i, y are optimizer::SEL_TREEs.
84  new_tree is combined with the first t_j it has a SEL_ARG on common
85  key with. As a consequence of this, choice of keys to do index_merge
86  read may depend on the order of conditions in WHERE part of the query.
87 
88  RETURN
89  0 OK
90  1 One of the trees was combined with new_tree to optimizer::SEL_TREE::ALWAYS,
91  and (*this) should be discarded.
92  -1 An error occurred.
93  */
94  int or_sel_tree_with_checks(RangeParameter&, SEL_TREE&);
95 
96  /*
97  Perform OR operation on this index_merge and supplied index_merge list.
98 
99  RETURN
100  0 - OK
101  1 - One of conditions in result is always true and this SEL_IMERGE
102  should be discarded.
103  -1 - An error occurred
104  */
105  int or_sel_imerge_with_checks(RangeParameter&, SEL_IMERGE&);
106 
107 };
108 
109 
110 } /* namespace optimizer */
111 
112 } /* namespace drizzled */
113