1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2009 Sun Microsystems
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_KEY_FIELD_H
21
#define DRIZZLED_OPTIMIZER_KEY_FIELD_H
23
#include <drizzled/server_includes.h>
24
#include <drizzled/sql_select.h>
34
* Class used when finding key fields
47
null_rejecting(false),
52
Item *val; /**< May be empty if diff constant */
54
uint32_t optimize; /**< KEY_OPTIMIZE_* */
57
If true, the condition this class represents will not be satisfied
61
bool *cond_guard; /**< @see KeyUse::cond_guard */
64
void add_key_fields(JOIN *join,
65
KeyField **key_fields,
68
table_map usable_tables,
69
std::vector<SargableParam> &sargables);
71
void add_key_part(DYNAMIC_ARRAY *keyuse_array, KeyField *key_field);
74
* Add to KeyField array all 'ref' access candidates within nested join.
76
* This function populates KeyField array with entries generated from the
77
* ON condition of the given nested join, and does the same for nested joins
78
* contained within this nested join.
80
* @param[in] nested_join_table Nested join pseudo-table to process
81
* @param[in,out] end End of the key field array
82
* @param[in,out] and_level And-level
83
* @param[in,out] sargables std::vector of found sargable candidates
87
* We can add accesses to the tables that are direct children of this nested
88
* join (1), and are not inner tables w.r.t their neighbours (2).
90
* Example for #1 (outer brackets pair denotes nested join this function is
93
* ... LEFT JOIN (t1 LEFT JOIN (t2 ... ) ) ON cond
97
* ... LEFT JOIN (t1 LEFT JOIN t2 ) ON cond
99
* In examples 1-2 for condition cond, we can add 'ref' access candidates to
103
* ... LEFT JOIN (t1, t2 LEFT JOIN t3 ON inner_cond) ON cond
105
* Here we can add 'ref' access candidates for t1 and t2, but not for t3.
107
void add_key_fields_for_nj(JOIN *join,
108
TableList *nested_join_table,
111
std::vector<SargableParam> &sargables);
114
* Merge new key definitions to old ones, remove those not used in both.
116
* This is called for OR between different levels.
118
* To be able to do 'ref_or_null' we merge a comparison of a column
119
* and 'column IS NULL' to one test. This is useful for sub select queries
120
* that are internally transformed to something like:.
123
* SELECT * FROM t1 WHERE t1.key=outer_ref_field or t1.key IS NULL
126
* KeyField::null_rejecting is processed as follows: @n
127
* result has null_rejecting=true if it is set for both ORed references.
129
* - (t2.key = t1.field OR t2.key = t1.field) -> null_rejecting=true
130
* - (t2.key = t1.field OR t2.key <=> t1.field) -> null_rejecting=false
133
* The result of this is that we're missing some 'ref' accesses.
134
* OptimizerTeam: Fix this
136
KeyField *merge_key_fields(KeyField *start,
137
KeyField *new_fields,
142
* Add a possible key to array of possible keys if it's usable as a key
144
* @param key_fields Pointer to add key, if usable
145
* @param and_level And level, to be stored in KeyField
146
* @param cond Condition predicate
147
* @param field Field used in comparision
148
* @param eq_func True if we used =, <=> or IS NULL
149
* @param value Value used for comparison with field
150
* @param usable_tables Tables which can be used for key optimization
151
* @param sargables IN/OUT std::vector of found sargable candidates
154
* If we are doing a NOT NULL comparison on a NOT NULL field in a outer join
155
* table, we store this to be able to do not exists optimization later.
158
* *key_fields is incremented if we stored a key in the array
160
void add_key_field(KeyField **key_fields,
167
table_map usable_tables,
168
std::vector<SargableParam> &sargables);
171
* Add possible keys to array of possible keys originated from a simple
174
* @param key_fields Pointer to add key, if usable
175
* @param and_level And level, to be stored in KeyField
176
* @param cond Condition predicate
177
* @param field Field used in comparision
178
* @param eq_func True if we used =, <=> or IS NULL
179
* @param value Value used for comparison with field
180
* Is NULL for BETWEEN and IN
181
* @param usable_tables Tables which can be used for key optimization
182
* @param sargables IN/OUT std::vector of found sargable candidates
185
* If field items f1 and f2 belong to the same multiple equality and
186
* a key is added for f1, the the same key is added for f2.
189
* *key_fields is incremented if we stored a key in the array
191
void add_key_equal_fields(KeyField **key_fields,
194
Item_field *field_item,
198
table_map usable_tables,
199
std::vector<SargableParam> &sargables);
201
} /* end namespace optimizer */
203
} /* end namespace drizzled */
205
#endif /* DRIZZLED_OPTIMIZER_KEY_FIELD_H */