summaryrefslogtreecommitdiff
path: root/sql/sql_select.cc
diff options
context:
space:
mode:
authorunknown <bell@laptop.sanja.is.com.ua>2003-10-10 21:49:48 +0300
committerunknown <bell@laptop.sanja.is.com.ua>2003-10-10 21:49:48 +0300
commit8b09f4b074f1b31453fd142b7f3417b33fc0b6f2 (patch)
treee60d9e7ab843bfb80babd2dfe3bbec6a6af13f00 /sql/sql_select.cc
parentbc8f801bf0f239b85ee95ea5410915f0f5424fc1 (diff)
downloadmariadb-git-8b09f4b074f1b31453fd142b7f3417b33fc0b6f2.tar.gz
samall optimisation (any independent query will not save data for rexecution)
saving/restoring join_tab array (to save it of chnging by create_sort_index() before reexecuting) (BUG#1523) mysql-test/r/subselect.result: test of BUG#1523 mysql-test/t/subselect.test: test of BUG#1523 sql/sql_select.cc: samall optimisation (any independent query will not save data for rexecution) layout fix saving/restoring join_tab array (to save it of chnging by create_sort_index() before reexecuting) sql/sql_select.h: field for storing saved join_tab_array
Diffstat (limited to 'sql/sql_select.cc')
-rw-r--r--sql/sql_select.cc30
1 files changed, 27 insertions, 3 deletions
diff --git a/sql/sql_select.cc b/sql/sql_select.cc
index 4bab97d4a46..517339e3823 100644
--- a/sql/sql_select.cc
+++ b/sql/sql_select.cc
@@ -980,8 +980,7 @@ JOIN::optimize()
}
}
- if (select_lex != &thd->lex.select_lex &&
- select_lex->linkage != DERIVED_TABLE_TYPE)
+ if (select_lex->master_unit()->dependent)
{
if (!(tmp_join= (JOIN*)thd->alloc(sizeof(JOIN))))
DBUG_RETURN(-1);
@@ -994,10 +993,10 @@ JOIN::optimize()
DBUG_RETURN(0);
}
+
/*
Restore values in temporary join
*/
-
void JOIN::restore_tmp()
{
memcpy(tmp_join, this, (size_t) sizeof(JOIN));
@@ -1039,12 +1038,29 @@ JOIN::reinit()
if (items0)
set_items_ref_array(items0);
+ if (join_tab_save)
+ memcpy(join_tab, join_tab_save, sizeof(JOIN_TAB) * tables);
+
if (tmp_join)
restore_tmp();
DBUG_RETURN(0);
}
+
+bool
+JOIN::save_join_tab()
+{
+ if (!join_tab_save && select_lex->master_unit()->dependent)
+ {
+ if (!(join_tab_save= (JOIN_TAB*) thd->alloc(sizeof(JOIN_TAB) * tables)))
+ return 1;
+ memcpy(join_tab_save, join_tab, sizeof(JOIN_TAB) * tables);
+ }
+ return 0;
+}
+
+
/*
Exec select
*/
@@ -1246,6 +1262,10 @@ JOIN::exec()
if (curr_join->group_list)
{
thd->proc_info= "Creating sort index";
+ if (curr_join->join_tab == join_tab && save_join_tab())
+ {
+ DBUG_VOID_RETURN;
+ }
if (create_sort_index(thd, curr_join, curr_join->group_list,
HA_POS_ERROR, HA_POS_ERROR) ||
make_group_fields(this, curr_join))
@@ -1427,6 +1447,10 @@ JOIN::exec()
}
}
}
+ if (curr_join->join_tab == join_tab && save_join_tab())
+ {
+ DBUG_VOID_RETURN;
+ }
if (create_sort_index(thd, curr_join,
curr_join->group_list ?
curr_join->group_list : curr_join->order,