Commit 3e3f9009 authored by unknown's avatar unknown

MWL#89

Post-review fixes. Intermediate commit to address
review points 1.1, 1.2, 1.3, 1.4, 1.5, and 3.1, 3.2, 3.3.
parent 816940f6
...@@ -386,6 +386,8 @@ Item::Item(): ...@@ -386,6 +386,8 @@ Item::Item():
decimals= 0; max_length= 0; decimals= 0; max_length= 0;
with_subselect= 0; with_subselect= 0;
cmp_context= IMPOSSIBLE_RESULT; cmp_context= IMPOSSIBLE_RESULT;
/* Initially this item is not attached to any JOIN_TAB. */
join_tab_idx= MAX_TABLES;
/* Put item in free list so that we can free all items at end */ /* Put item in free list so that we can free all items at end */
THD *thd= current_thd; THD *thd= current_thd;
...@@ -414,6 +416,7 @@ Item::Item(): ...@@ -414,6 +416,7 @@ Item::Item():
tables. tables.
*/ */
Item::Item(THD *thd, Item *item): Item::Item(THD *thd, Item *item):
join_tab_idx(item->join_tab_idx),
is_expensive_cache(-1), is_expensive_cache(-1),
rsize(0), rsize(0),
str_value(item->str_value), str_value(item->str_value),
...@@ -470,6 +473,7 @@ void Item::cleanup() ...@@ -470,6 +473,7 @@ void Item::cleanup()
DBUG_ENTER("Item::cleanup"); DBUG_ENTER("Item::cleanup");
fixed=0; fixed=0;
marker= 0; marker= 0;
join_tab_idx= MAX_TABLES;
if (orig_name) if (orig_name)
name= orig_name; name= orig_name;
DBUG_VOID_RETURN; DBUG_VOID_RETURN;
......
...@@ -491,6 +491,17 @@ typedef void (*Cond_traverser) (const Item *item, void *arg); ...@@ -491,6 +491,17 @@ typedef void (*Cond_traverser) (const Item *item, void *arg);
class Item { class Item {
Item(const Item &); /* Prevent use of these */ Item(const Item &); /* Prevent use of these */
void operator=(Item &); void operator=(Item &);
/**
The index in the JOIN::join_tab array of the JOIN_TAB this Item is attached
to. Items are attached (or 'pushed') to JOIN_TABs during optimization by the
make_cond_for_table procedure. During query execution, this item is
evaluated when the join loop reaches the corresponding JOIN_TAB.
If the value of join_tab_idx >= MAX_TABLES, this means that there is no
corresponding JOIN_TAB.
*/
uint join_tab_idx;
public: public:
static void *operator new(size_t size) throw () static void *operator new(size_t size) throw ()
{ return sql_alloc(size); } { return sql_alloc(size); }
...@@ -1179,6 +1190,16 @@ class Item { ...@@ -1179,6 +1190,16 @@ class Item {
Item* set_expr_cache(THD *thd, List<Item*> &depends_on); Item* set_expr_cache(THD *thd, List<Item*> &depends_on);
virtual Item *get_cached_item() { return NULL; } virtual Item *get_cached_item() { return NULL; }
/**
Set the join tab index to the minimal (left-most) JOIN_TAB to which this
Item is attached.
*/
virtual void set_join_tab_idx(uint join_tab_idx_arg)
{
if (join_tab_idx_arg < join_tab_idx)
join_tab_idx= join_tab_idx_arg;
}
virtual uint get_join_tab_idx() { return join_tab_idx; }
}; };
......
...@@ -268,6 +268,8 @@ class Item_in_optimizer: public Item_bool_func ...@@ -268,6 +268,8 @@ class Item_in_optimizer: public Item_bool_func
virtual Item *expr_cache_insert_transformer(uchar *thd_arg); virtual Item *expr_cache_insert_transformer(uchar *thd_arg);
bool is_expensive_processor(uchar *arg); bool is_expensive_processor(uchar *arg);
bool is_expensive(); bool is_expensive();
void set_join_tab_idx(uint join_tab_idx_arg)
{ args[1]->set_join_tab_idx(join_tab_idx_arg); }
}; };
class Comp_creator class Comp_creator
......
This diff is collapsed.
...@@ -119,7 +119,6 @@ class Item_subselect :public Item_result_field ...@@ -119,7 +119,6 @@ class Item_subselect :public Item_result_field
/* TRUE <=> The underlying SELECT is correlated w.r.t some ancestor select */ /* TRUE <=> The underlying SELECT is correlated w.r.t some ancestor select */
bool is_correlated; bool is_correlated;
enum trans_res {RES_OK, RES_REDUCE, RES_ERROR};
enum subs_type {UNKNOWN_SUBS, SINGLEROW_SUBS, enum subs_type {UNKNOWN_SUBS, SINGLEROW_SUBS,
EXISTS_SUBS, IN_SUBS, ALL_SUBS, ANY_SUBS}; EXISTS_SUBS, IN_SUBS, ALL_SUBS, ANY_SUBS};
...@@ -148,7 +147,7 @@ class Item_subselect :public Item_result_field ...@@ -148,7 +147,7 @@ class Item_subselect :public Item_result_field
eliminated= FALSE; eliminated= FALSE;
null_value= 1; null_value= 1;
} }
virtual trans_res select_transformer(JOIN *join); virtual bool select_transformer(JOIN *join);
bool assigned() { return value_assigned; } bool assigned() { return value_assigned; }
void assigned(bool a) { value_assigned= a; } void assigned(bool a) { value_assigned= a; }
enum Type type() const; enum Type type() const;
...@@ -259,7 +258,7 @@ class Item_singlerow_subselect :public Item_subselect ...@@ -259,7 +258,7 @@ class Item_singlerow_subselect :public Item_subselect
subs_type substype() { return SINGLEROW_SUBS; } subs_type substype() { return SINGLEROW_SUBS; }
void reset(); void reset();
trans_res select_transformer(JOIN *join); bool select_transformer(JOIN *join);
void store(uint i, Item* item); void store(uint i, Item* item);
double val_real(); double val_real();
longlong val_int (); longlong val_int ();
...@@ -399,16 +398,16 @@ class Item_in_subselect :public Item_exists_subselect ...@@ -399,16 +398,16 @@ class Item_in_subselect :public Item_exists_subselect
protected: protected:
bool init_cond_guards(); bool init_cond_guards();
trans_res select_in_like_transformer(JOIN *join); bool select_in_like_transformer(JOIN *join);
trans_res single_value_transformer(JOIN *join); bool single_value_transformer(JOIN *join);
trans_res row_value_transformer(JOIN * join); bool row_value_transformer(JOIN * join);
bool fix_having(Item *having, st_select_lex *select_lex); bool fix_having(Item *having, st_select_lex *select_lex);
trans_res create_single_in_to_exists_cond(JOIN * join, bool create_single_in_to_exists_cond(JOIN * join,
Item **where_item, Item **where_item,
Item **having_item); Item **having_item);
trans_res create_row_in_to_exists_cond(JOIN * join, bool create_row_in_to_exists_cond(JOIN * join,
Item **where_item, Item **where_item,
Item **having_item); Item **having_item);
public: public:
Item *left_expr; Item *left_expr;
/* Priority of this predicate in the convert-to-semi-join-nest process. */ /* Priority of this predicate in the convert-to-semi-join-nest process. */
...@@ -473,7 +472,7 @@ class Item_in_subselect :public Item_exists_subselect ...@@ -473,7 +472,7 @@ class Item_in_subselect :public Item_exists_subselect
null_value= 0; null_value= 0;
was_null= 0; was_null= 0;
} }
trans_res select_transformer(JOIN *join); bool select_transformer(JOIN *join);
bool create_in_to_exists_cond(JOIN *join_arg); bool create_in_to_exists_cond(JOIN *join_arg);
bool inject_in_to_exists_cond(JOIN *join_arg); bool inject_in_to_exists_cond(JOIN *join_arg);
...@@ -523,7 +522,7 @@ class Item_allany_subselect :public Item_in_subselect ...@@ -523,7 +522,7 @@ class Item_allany_subselect :public Item_in_subselect
// only ALL subquery has upper not // only ALL subquery has upper not
subs_type substype() { return all?ALL_SUBS:ANY_SUBS; } subs_type substype() { return all?ALL_SUBS:ANY_SUBS; }
trans_res select_transformer(JOIN *join); bool select_transformer(JOIN *join);
void create_comp_func(bool invert) { func= func_creator(invert); } void create_comp_func(bool invert) { func= func_creator(invert); }
virtual void print(String *str, enum_query_type query_type); virtual void print(String *str, enum_query_type query_type);
}; };
......
This diff is collapsed.
This diff is collapsed.
...@@ -1374,6 +1374,31 @@ class JOIN :public Sql_alloc ...@@ -1374,6 +1374,31 @@ class JOIN :public Sql_alloc
JOIN& operator=(const JOIN &rhs); /**< not implemented */ JOIN& operator=(const JOIN &rhs); /**< not implemented */
protected: protected:
/**
???
*/
class Query_plan_state {
public:
DYNAMIC_ARRAY keyuse; /* Copy of the JOIN::keyuse array. */
POSITION best_positions[MAX_TABLES+1]; /* Copy of JOIN::best_positions */
/* Copies of the JOIN_TAB::keyuse pointers for each JOIN_TAB. */
KEYUSE *join_tab_keyuse[MAX_TABLES];
/* Copies of JOIN_TAB::checked_keys for each JOIN_TAB. */
key_map join_tab_checked_keys[MAX_TABLES];
public:
Query_plan_state()
{
keyuse.elements= 0;
keyuse.buffer= NULL;
}
Query_plan_state(JOIN *join);
~Query_plan_state()
{
delete_dynamic(&keyuse);
}
};
/* Results of reoptimizing a JOIN via JOIN::reoptimize(). */ /* Results of reoptimizing a JOIN via JOIN::reoptimize(). */
enum enum_reopt_result { enum enum_reopt_result {
REOPT_NEW_PLAN, /* there is a new reoptimized plan */ REOPT_NEW_PLAN, /* there is a new reoptimized plan */
...@@ -1383,13 +1408,10 @@ class JOIN :public Sql_alloc ...@@ -1383,13 +1408,10 @@ class JOIN :public Sql_alloc
}; };
/* Support for plan reoptimization with rewritten conditions. */ /* Support for plan reoptimization with rewritten conditions. */
enum_reopt_result reoptimize(Item *added_where, table_map join_tables); enum_reopt_result reoptimize(Item *added_where, table_map join_tables,
int save_query_plan(DYNAMIC_ARRAY *save_keyuse, POSITION *save_positions, Query_plan_state *save_to);
KEYUSE **save_join_tab_keyuse, void save_query_plan(Query_plan_state *save_to);
key_map *save_join_tab_checked_keys); void restore_query_plan(Query_plan_state *restore_from);
void restore_query_plan(DYNAMIC_ARRAY *save_keyuse, POSITION *save_positions,
KEYUSE **save_join_tab_keyuse,
key_map *save_join_tab_checked_keys);
/* Choose a subquery plan for a table-less subquery. */ /* Choose a subquery plan for a table-less subquery. */
bool choose_tableless_subquery_plan(); bool choose_tableless_subquery_plan();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment