summaryrefslogtreecommitdiff
path: root/sql/sql_select.cc
diff options
context:
space:
mode:
authorunknown <monty@mysql.com>2004-11-03 12:39:38 +0200
committerunknown <monty@mysql.com>2004-11-03 12:39:38 +0200
commitf5a47f156b6778a0f6751556e56a0afe25d6be13 (patch)
tree85bce6df7d0ce9d809ff3fc13fa4486590463d00 /sql/sql_select.cc
parentf095274fe8c3d3394d6c0ce0a68f4bea04311999 (diff)
downloadmariadb-git-f5a47f156b6778a0f6751556e56a0afe25d6be13.tar.gz
Fixes after merge with 4.1
FOUND is not a reserved keyword anymore Added Item_field::set_no_const_sub() to be able to mark fields that can't be substituted Added 'simple_select' method to be able to quickly determinate if a select_result is a normal SELECT Note that the 5.0 tree is not yet up to date: Sanja will have to fix multi-update-locks for this merge to be complete BUILD/SETUP.sh: Portability fix client/mysqltest.c: Portability fix mysql-test/r/drop.result: updated results mysql-test/r/func_str.result: New warnings (after merge) mysql-test/r/insert.result: Updated tests mysql-test/r/join_nested.result: Updated results (because of new column types in 5.0) mysql-test/r/lock_multi.result: Temporarly wrong results until Sanja fixes multi-update-lock in 5.0 mysql-test/r/multi_update.result: Temporary fix until Sanja fixes multi-update locking mysql-test/r/ps_1general.result: Update of results after merge mysql-test/r/ps_2myisam.result: Update of results after merge mysql-test/r/ps_3innodb.result: Update of results after merge mysql-test/r/ps_4heap.result: Update of results after merge mysql-test/r/ps_5merge.result: Update of results after merge mysql-test/r/ps_6bdb.result: Update of results after merge mysql-test/r/query_cache.result: Update of results after merge mysql-test/r/range.result: New results for new tests mysql-test/r/rpl_auto_increment.result: Update with new 4.0 information mysql-test/r/rpl_charset.result: After merge fixes mysql-test/r/subselect.result: After merge fixes mysql-test/r/view.result: Temporary fix until multi-update-locking is fixed mysql-test/t/drop.test: Safety fix mysql-test/t/multi_update.test: Temporary fix until multi-update-locking is fixed mysql-test/t/rpl_charset.test: More comments mysql-test/t/sp-error.test: Updated comments mysql-test/t/view.test: Temporary fix until multi-update-locking is fixed scripts/mysql_fix_privilege_tables.sh: Better error message sql-common/client.c: More debugging sql/ha_ndbcluster.cc: After merge fixes sql/handler.cc: After merge fixes sql/item.cc: Simple optimization of creating item After merge fixed Added Item_field::set_no_const_sub() to be able to mark fields that can't be substituted The problem is that if you compare a string field to a binary string, you can't replace the field with a string constant as the binary comparison may then fail (The original field value may be in a different case) sql/item.h: Added Item::set_no_const_sub() to be able to mark fields that can't be substituted sql/item_cmpfunc.cc: Mark fields compared as binary to not be substituted. sql/item_func.cc: After merge fix sql/log_event.cc: After merge fix sql/mysql_priv.h: After merge fix sql/opt_range.cc: After merge fix sql/protocol.cc: Made flags uint instead of int (as it's used as a bit mask) sql/protocol.h: Made flags uint instead of int (as it's used as a bit mask) sql/protocol_cursor.cc: Made flags uint instead of int (as it's used as a bit mask) Indentation cleanups sql/sp.cc: After merge fixes Removed compiler warnings sql/sp_head.cc: After merge fixes sql/sql_base.cc: After merge fixes Removed 'send_error' from 'insert_fields()' as the error is sent higher up sql/sql_class.cc: Give assert if set_n_backup_item_arena is used twice sql/sql_class.h: Give assert if set_n_backup_item_arena is used twice After merge fixes Added 'simple_select' method to be able to quickly determinate if a select_result is a normal SELECT sql/sql_handler.cc: After merge fixes sql/sql_parse.cc: After merge fixes sql/sql_prepare.cc: After merge fixes sql/sql_select.cc: After merge fixes Moved 'build_equal_items' to optimize_cond() (logical place) sql/sql_table.cc: After merge fixes sql/sql_trigger.cc: After merge fixes sql/sql_update.cc: After merge fixes (This should be fixed by Sanja to have lower granuality locking of tables in multi-update) sql/sql_view.cc: After merge fixes sql/sql_yacc.yy: After merge fixes Don't have FOUND as a reserved keyword
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r--sql/sql_select.cc71
1 files changed, 41 insertions, 30 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index f4fbd03768d..2e1429feb3e 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -91,7 +91,7 @@ static int return_zero_rows(JOIN *join, select_result *res,TABLE_LIST *tables,
uint select_options, const char *info,
Item *having, Procedure *proc,
SELECT_LEX_UNIT *unit);
-static COND *build_equal_items(COND *cond,
+static COND *build_equal_items(THD *thd, COND *cond,
COND_EQUAL *inherited,
List<TABLE_LIST> *join_list,
COND_EQUAL **cond_equal_ref);
@@ -101,6 +101,7 @@ static COND* substitute_for_best_equal_field(COND *cond,
static COND *simplify_joins(JOIN *join, List<TABLE_LIST> *join_list,
COND *conds, bool top);
static COND *optimize_cond(JOIN *join, COND *conds,
+ List<TABLE_LIST> *join_list,
Item::cond_result *cond_value);
static bool resolve_nested_join (TABLE_LIST *table);
static COND *remove_eq_conds(THD *thd, COND *cond,
@@ -228,14 +229,11 @@ int handle_select(THD *thd, LEX *lex, select_result *result)
select_lex->options | thd->options,
result, unit, select_lex);
}
-
- /* Don't set res if it's -1 as we may want this later */
DBUG_PRINT("info",("res: %d report_error: %d", res,
thd->net.report_error));
- if (thd->net.report_error || res<0)
+ if (thd->net.report_error || res < 0)
{
- if (res > 0)
- result->send_error(0, NullS);
+ result->send_error(0, NullS);
result->abort();
res= 1; // Error sent to client
}
@@ -556,17 +554,7 @@ JOIN::optimize()
thd->restore_backup_item_arena(arena, &backup);
}
- /*
- Build all multiple equality predicates and eliminate equality
- predicates that can be inferred from these multiple equalities.
- For each reference of a field included into a multiple equality
- that occurs in a function set a pointer to the multiple equality
- predicate. Substitute a constant instead of this field if the
- multiple equality contains a constant.
- */
- conds= build_equal_items(conds, NULL, join_list, &cond_equal);
-
- conds= optimize_cond(this, conds,&cond_value);
+ conds= optimize_cond(this, conds, join_list, &cond_value);
if (thd->net.report_error)
{
error= 1;
@@ -684,6 +672,7 @@ JOIN::optimize()
{
conds= substitute_for_best_equal_field(conds, cond_equal, map2table);
conds->update_used_tables();
+ DBUG_EXECUTE("where", print_where(conds, "after substitute_best_equal"););
}
/*
Permorm the the optimization on fields evaluation mentioned above
@@ -1723,11 +1712,10 @@ int
Cursor::open(JOIN *join_arg)
{
join= join_arg;
-
THD *thd= join->thd;
-
/* First non-constant table */
JOIN_TAB *join_tab= join->join_tab + join->const_tables;
+ DBUG_ENTER("Cursor::open");
/*
Send fields description to the client; server_status is sent
@@ -1749,7 +1737,9 @@ Cursor::open(JOIN *join_arg)
join->fetch_limit= join->unit->offset_limit_cnt;
/* Disable JOIN CACHE as it is not working with cursors yet */
- for (JOIN_TAB *tab= join_tab; tab != join->join_tab + join->tables - 1; ++tab)
+ for (JOIN_TAB *tab= join_tab;
+ tab != join->join_tab + join->tables - 1;
+ tab++)
{
if (tab->next_select == sub_select_cache)
tab->next_select= sub_select;
@@ -1763,7 +1753,7 @@ Cursor::open(JOIN *join_arg)
*/
DBUG_ASSERT(join_tab->table->null_row == 0);
- return join_tab->read_first_record(join_tab);
+ DBUG_RETURN(join_tab->read_first_record(join_tab));
}
@@ -6028,7 +6018,7 @@ template class List_iterator<Item_func_match>;
find_item_equal()
cond_equal multiple equalities to search in
field field to look for
- inherited_fl :out set up to TRUE iff multiple equality is found
+ inherited_fl :out set up to TRUE if multiple equality is found
on upper levels (not on current level of cond_equal)
DESCRIPTION
@@ -6446,12 +6436,14 @@ static COND *build_equal_items_for_cond(COND *cond,
return cond;
}
+
/*
Build multiple equalities for a condition and all on expressions that
inherit these multiple equalities
SYNOPSIS
build_equal_items()
+ thd Thread handler
cond condition to build the multiple equalities for
inherited path to all inherited multiple equality items
join_list list of join tables to which the condition refers to
@@ -6503,7 +6495,7 @@ static COND *build_equal_items_for_cond(COND *cond,
pointer to the transformed condition containing multiple equalities
*/
-static COND *build_equal_items(COND *cond,
+static COND *build_equal_items(THD *thd, COND *cond,
COND_EQUAL *inherited,
List<TABLE_LIST> *join_list,
COND_EQUAL **cond_equal_ref)
@@ -6540,12 +6532,13 @@ static COND *build_equal_items(COND *cond,
{
if (table->on_expr)
{
+ Item *expr;
List<TABLE_LIST> *join_list= table->nested_join ?
&table->nested_join->join_list : NULL;
- table->on_expr= build_equal_items(table->on_expr,
- inherited,
- join_list,
- &table->cond_equal);
+ expr= build_equal_items(thd, table->on_expr, inherited, join_list,
+ &table->cond_equal);
+ if (expr != table->on_expr)
+ thd->change_item_tree(&table->on_expr, expr);
}
}
}
@@ -6553,6 +6546,7 @@ static COND *build_equal_items(COND *cond,
return cond;
}
+
/*
Compare field items by table order in the execution plan
@@ -6797,6 +6791,7 @@ static COND* substitute_for_best_equal_field(COND *cond,
return cond;
}
+
/*
change field = field to field = const for each found field = const in the
and_level
@@ -7089,6 +7084,7 @@ simplify_joins(JOIN *join, List<TABLE_LIST> *join_list, COND *conds, bool top)
*/
if (table->on_expr)
{
+ Item *expr;
/*
If an on expression E is attached to the table,
check all null rejected predicates in this expression.
@@ -7097,8 +7093,9 @@ simplify_joins(JOIN *join, List<TABLE_LIST> *join_list, COND *conds, bool top)
the outer join is converted to an inner join and
the corresponding on expression is added to E.
*/
- table->on_expr= simplify_joins(join, &nested_join->join_list,
- table->on_expr, FALSE);
+ expr= simplify_joins(join, &nested_join->join_list,
+ table->on_expr, FALSE);
+ table->on_expr= expr;
}
nested_join->used_tables= (table_map) 0;
nested_join->not_null_tables=(table_map) 0;
@@ -7207,8 +7204,10 @@ simplify_joins(JOIN *join, List<TABLE_LIST> *join_list, COND *conds, bool top)
DBUG_RETURN(conds);
}
+
static COND *
-optimize_cond(JOIN *join, COND *conds, Item::cond_result *cond_value)
+optimize_cond(JOIN *join, COND *conds, List<TABLE_LIST> *join_list,
+ Item::cond_result *cond_value)
{
THD *thd= join->thd;
SELECT_LEX *select= thd->lex->current_select;
@@ -7221,7 +7220,19 @@ optimize_cond(JOIN *join, COND *conds, Item::cond_result *cond_value)
}
else
{
+ /*
+ Build all multiple equality predicates and eliminate equality
+ predicates that can be inferred from these multiple equalities.
+ For each reference of a field included into a multiple equality
+ that occurs in a function set a pointer to the multiple equality
+ predicate. Substitute a constant instead of this field if the
+ multiple equality contains a constant.
+ */
DBUG_EXECUTE("where", print_where(conds, "original"););
+ conds= build_equal_items(join->thd, conds, NULL, join_list,
+ &join->cond_equal);
+ DBUG_EXECUTE("where",print_where(conds,"after equal_items"););
+
/* change field = field to field = const for each found field = const */
propagate_cond_constants(thd, (I_List<COND_CMP> *) 0, conds, conds);
/*