Commit f6697593 authored by unknown's avatar unknown

range.test:

  Added tests for != predicate.
sql_select.cc:
  Fixing bugs in Item_equal code:
  added a parameter in substitute_for_equal_field;
  modified eliminate_item_equal.
sql_list.h:
  Cleanup


sql/sql_list.h:
  Cleanup
sql/sql_select.cc:
  Fixing bugs in Item_equal code:
  added a parameter in substitute_for_equal_field;
  modified eliminate_item_equal.
mysql-test/t/range.test:
  Added tests for != predicate.
parent 09fc5d1f
...@@ -323,8 +323,12 @@ insert into t2(id, uid, name) select id, uid, name from t1; ...@@ -323,8 +323,12 @@ insert into t2(id, uid, name) select id, uid, name from t1;
select count(*) from t1; select count(*) from t1;
select count(*) from t2; select count(*) from t2;
analyze table t1,t2;
explain select * from t1, t2 where t1.uid=t2.uid AND t1.uid > 0; explain select * from t1, t2 where t1.uid=t2.uid AND t1.uid > 0;
explain select * from t1, t2 where t1.uid=t2.uid AND t2.uid > 0;
explain select * from t1, t2 where t1.uid=t2.uid AND t1.uid != 0; explain select * from t1, t2 where t1.uid=t2.uid AND t1.uid != 0;
explain select * from t1, t2 where t1.uid=t2.uid AND t2.uid != 0;
select * from t1, t2 where t1.uid=t2.uid AND t1.uid > 0; select * from t1, t2 where t1.uid=t2.uid AND t1.uid > 0;
select * from t1, t2 where t1.uid=t2.uid AND t1.uid != 0; select * from t1, t2 where t1.uid=t2.uid AND t1.uid != 0;
......
...@@ -271,8 +271,8 @@ public: ...@@ -271,8 +271,8 @@ public:
inline T* head() {return (T*) base_list::head(); } inline T* head() {return (T*) base_list::head(); }
inline T** head_ref() {return (T**) base_list::head_ref(); } inline T** head_ref() {return (T**) base_list::head_ref(); }
inline T* pop() {return (T*) base_list::pop(); } inline T* pop() {return (T*) base_list::pop(); }
inline void concat(List<T> *list) { return base_list::concat(list); } inline void concat(List<T> *list) { base_list::concat(list); }
inline void disjoin(List<T> *list) { return base_list::disjoin(list); } inline void disjoin(List<T> *list) { base_list::disjoin(list); }
void delete_elements(void) void delete_elements(void)
{ {
list_node *element,*next; list_node *element,*next;
...@@ -283,7 +283,6 @@ public: ...@@ -283,7 +283,6 @@ public:
} }
empty(); empty();
} }
inline void concat(List<T> *list) { base_list::concat(list); }
}; };
......
...@@ -77,6 +77,7 @@ static Item *flatten_condition(COND *cond); ...@@ -77,6 +77,7 @@ static Item *flatten_condition(COND *cond);
static COND *build_all_equal_items(COND *cond, static COND *build_all_equal_items(COND *cond,
COND_EQUAL *inherited); COND_EQUAL *inherited);
static COND* substitute_for_best_equal_field(COND *cond, static COND* substitute_for_best_equal_field(COND *cond,
COND_EQUAL *cond_equal,
void *table_join_idx); void *table_join_idx);
static COND *optimize_cond(COND *conds,Item::cond_result *cond_value); static COND *optimize_cond(COND *conds,Item::cond_result *cond_value);
static COND *remove_eq_conds(COND *cond,Item::cond_result *cond_value); static COND *remove_eq_conds(COND *cond,Item::cond_result *cond_value);
...@@ -690,7 +691,7 @@ JOIN::optimize() ...@@ -690,7 +691,7 @@ JOIN::optimize()
*/ */
if (conds) if (conds)
{ {
conds= substitute_for_best_equal_field(conds, map2table); conds= substitute_for_best_equal_field(conds, cond_equal, map2table);
conds->update_used_tables(); conds->update_used_tables();
} }
{ {
...@@ -700,6 +701,7 @@ JOIN::optimize() ...@@ -700,6 +701,7 @@ JOIN::optimize()
if (tables->on_expr) if (tables->on_expr)
{ {
tables->on_expr= substitute_for_best_equal_field(tables->on_expr, tables->on_expr= substitute_for_best_equal_field(tables->on_expr,
cond_equal,
map2table); map2table);
tables->on_expr->update_used_tables(); tables->on_expr->update_used_tables();
map2table[tables->table->tablenr]->on_expr= tables->on_expr; map2table[tables->table->tablenr]->on_expr= tables->on_expr;
...@@ -4703,11 +4705,8 @@ static Item *eliminate_item_equal(COND *cond, COND_EQUAL *cond_equal, ...@@ -4703,11 +4705,8 @@ static Item *eliminate_item_equal(COND *cond, COND_EQUAL *cond_equal,
Item_field *item= item_field; Item_field *item= item_field;
if (upper) if (upper)
{ {
if (item_const) if (item_const && upper->get_const())
{
if (upper->get_const())
item= 0; item= 0;
}
else else
{ {
Item_equal_iterator li(*item_equal); Item_equal_iterator li(*item_equal);
...@@ -4745,6 +4744,7 @@ static Item *eliminate_item_equal(COND *cond, COND_EQUAL *cond_equal, ...@@ -4745,6 +4744,7 @@ static Item *eliminate_item_equal(COND *cond, COND_EQUAL *cond_equal,
SYNOPSIS SYNOPSIS
substitute_for_best_equal_field() substitute_for_best_equal_field()
cond condition to process cond condition to process
cond_equal multiple equalities to take into consideration
table_join_idx index to tables determining field preference table_join_idx index to tables determining field preference
DESCRIPTION DESCRIPTION
...@@ -4770,6 +4770,7 @@ static Item *eliminate_item_equal(COND *cond, COND_EQUAL *cond_equal, ...@@ -4770,6 +4770,7 @@ static Item *eliminate_item_equal(COND *cond, COND_EQUAL *cond_equal,
*/ */
static COND* substitute_for_best_equal_field(COND *cond, static COND* substitute_for_best_equal_field(COND *cond,
COND_EQUAL *cond_equal,
void *table_join_idx) void *table_join_idx)
{ {
Item_equal *item_equal; Item_equal *item_equal;
...@@ -4777,7 +4778,6 @@ static COND* substitute_for_best_equal_field(COND *cond, ...@@ -4777,7 +4778,6 @@ static COND* substitute_for_best_equal_field(COND *cond,
if (cond->type() == Item::COND_ITEM) if (cond->type() == Item::COND_ITEM)
{ {
List<Item> *cond_list= ((Item_cond*) cond)->argument_list(); List<Item> *cond_list= ((Item_cond*) cond)->argument_list();
COND_EQUAL *cond_equal= 0;
bool and_level= ((Item_cond*) cond)->functype() == bool and_level= ((Item_cond*) cond)->functype() ==
Item_func::COND_AND_FUNC; Item_func::COND_AND_FUNC;
...@@ -4797,7 +4797,7 @@ static COND* substitute_for_best_equal_field(COND *cond, ...@@ -4797,7 +4797,7 @@ static COND* substitute_for_best_equal_field(COND *cond,
Item *item; Item *item;
while ((item= li++)) while ((item= li++))
{ {
Item *new_item =substitute_for_best_equal_field(item, Item *new_item =substitute_for_best_equal_field(item, cond_equal,
table_join_idx); table_join_idx);
if (new_item != item) if (new_item != item)
li.replace(new_item); li.replace(new_item);
...@@ -4817,7 +4817,9 @@ static COND* substitute_for_best_equal_field(COND *cond, ...@@ -4817,7 +4817,9 @@ static COND* substitute_for_best_equal_field(COND *cond,
{ {
item_equal= (Item_equal *) cond; item_equal= (Item_equal *) cond;
item_equal->sort(table_join_idx); item_equal->sort(table_join_idx);
return eliminate_item_equal(0, 0, item_equal); if (cond_equal && cond_equal->current_level.head() == item_equal)
cond_equal= 0;
return eliminate_item_equal(0, cond_equal, item_equal);
} }
else else
cond->walk(&Item::replace_equal_field_processor, 0); cond->walk(&Item::replace_equal_field_processor, 0);
......
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