27
27
#ifndef DRIZZLED_JOIN_H
28
28
#define DRIZZLED_JOIN_H
30
#include <drizzled/optimizer/position.h>
31
#include "drizzled/sql_select.h"
37
class JOIN :public memory::SqlAlloc
30
class JOIN :public Sql_alloc
39
32
JOIN(const JOIN &rhs); /**< not implemented */
40
33
JOIN& operator=(const JOIN &rhs); /**< not implemented */
43
* Contains a partial query execution plan which is extended during
44
* cost-based optimization.
46
optimizer::Position positions[MAX_TABLES+1];
49
* Contains the optimal query execution plan after cost-based optimization
52
optimizer::Position best_positions[MAX_TABLES+1];
55
35
JoinTable *join_tab;
56
36
JoinTable **best_ref;
109
89
bool simple_group;
111
91
Is set only in case if we have a GROUP BY clause
112
and no ORDER BY after constant elimination of 'order'.
92
and no order_st BY after constant elimination of 'order'.
115
/** Is set if we have a GROUP BY and we have ORDER BY on a constant. */
95
/** Is set if we have a GROUP BY and we have order_st BY on a constant. */
116
96
bool skip_sort_order;
117
97
bool union_part; /**< this subselect is part of union */
118
98
bool optimized; /**< flag to avoid double optimization in EXPLAIN */
147
127
Select_Lex_Unit *unit;
148
128
/** select that processed */
149
129
Select_Lex *select_lex;
150
optimizer::SqlSelect *select; /**< created in optimization phase */
130
SQL_SELECT *select; /**< created in optimisation phase */
131
Array<Item_in_subselect> sj_subselects;
133
POSITION positions[MAX_TABLES+1];
134
POSITION best_positions[MAX_TABLES+1];
153
137
Bitmap of nested joins embedding the position at the end of the current
154
138
partial join (valid only during join optimizer run).
156
std::bitset<64> cur_embedding_map;
140
nested_join_map cur_embedding_map;
159
* The cost for the final query execution plan chosen after optimization
160
* has completed. The QEP is stored in the best_positions variable.
162
142
double best_read;
163
143
List<Cached_item> group_fields;
164
144
List<Cached_item> group_fields_cache;
462
443
return (unit == &session->lex->unit && (unit->fake_select_lex == 0 ||
463
444
select_lex == unit->fake_select_lex));
467
* Copy the partial query plan into the optimal query plan.
469
* @param[in] size the size of the plan which is to be copied
471
void copyPartialPlanIntoOptimalPlan(uint32_t size)
473
memcpy(best_positions, positions,
474
sizeof(optimizer::Position) * size);
477
void cache_const_exprs();
480
* @param[in] index the index of the position to retrieve
481
* @return a reference to the specified position in the optimal
484
optimizer::Position &getPosFromOptimalPlan(uint32_t index)
486
return best_positions[index];
490
* @param[in] index the index of the position to retrieve
491
* @return a reference to the specified position in the partial
494
optimizer::Position &getPosFromPartialPlan(uint32_t index)
496
return positions[index];
500
* @param[in] index the index of the position to set
501
* @param[in] in_pos the value to set the position to
503
void setPosInPartialPlan(uint32_t index, optimizer::Position &in_pos)
505
positions[index]= in_pos;
509
* @return a pointer to the first position in the partial query plan
511
optimizer::Position *getFirstPosInPartialPlan()
517
* @param[in] index the index of the operator to retrieve from the partial
519
* @return a pointer to the position in the partial query plan
521
optimizer::Position *getSpecificPosInPartialPlan(int32_t index)
523
return positions + index;
528
448
enum_nested_loop_state evaluate_join_record(JOIN *join, JoinTable *join_tab, int error);
533
453
enum_nested_loop_state end_update(JOIN *join, JoinTable *join_tab, bool end_of_records);
534
454
enum_nested_loop_state end_unique_update(JOIN *join, JoinTable *join_tab, bool end_of_records);
536
} /* namespace drizzled */
538
456
#endif /* DRIZZLED_JOIN_H */