summaryrefslogtreecommitdiff
path: root/sql/sql_union.cc
diff options
context:
space:
mode:
authorbell@sanja.is.com.ua <>2004-05-14 13:33:02 +0300
committerbell@sanja.is.com.ua <>2004-05-14 13:33:02 +0300
commit71a374dc1384db2c5e48a059bcdd3624ddcc4564 (patch)
tree073417895d29c0f914a61109875c76ce21b4369c /sql/sql_union.cc
parenta71771788e31f7b5c624bc1915bdd7f95ed257b6 (diff)
parent8885ce0dd77f499a5672fb7f38278bdc9dcf3393 (diff)
downloadmariadb-git-71a374dc1384db2c5e48a059bcdd3624ddcc4564.tar.gz
Merge
Diffstat (limited to 'sql/sql_union.cc')
-rw-r--r--sql/sql_union.cc34
1 files changed, 28 insertions, 6 deletions
diff --git a/sql/sql_union.cc b/sql/sql_union.cc
index 63638b618d9..fe009f89e76 100644
--- a/sql/sql_union.cc
+++ b/sql/sql_union.cc
@@ -41,7 +41,7 @@ int mysql_union(THD *thd, LEX *lex, select_result *result,
***************************************************************************/
select_union::select_union(TABLE *table_par)
- :table(table_par), not_describe(0)
+ :table(table_par)
{
bzero((char*) &info,sizeof(info));
/*
@@ -149,6 +149,8 @@ int st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result,
select_result *tmp_result;
DBUG_ENTER("st_select_lex_unit::prepare");
+ describe= test(additional_options & SELECT_DESCRIBE);
+
/*
result object should be reassigned even if preparing already done for
max/min subquery (ALL/ANY optimization)
@@ -156,7 +158,26 @@ int st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result,
result= sel_result;
if (prepared)
+ {
+ if (describe)
+ {
+ /* fast reinit for EXPLAIN */
+ for (sl= first_select_in_union(); sl; sl= sl->next_select())
+ {
+ sl->join->result= result;
+ select_limit_cnt= HA_POS_ERROR;
+ offset_limit_cnt= 0;
+ if (!sl->join->procedure &&
+ result->prepare(sl->join->fields_list, this))
+ {
+ DBUG_RETURN(1);
+ }
+ sl->join->select_options|= SELECT_DESCRIBE;
+ sl->join->reinit();
+ }
+ }
DBUG_RETURN(0);
+ }
prepared= 1;
res= 0;
@@ -169,8 +190,9 @@ int st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result,
{
if (!(tmp_result= union_result= new select_union(0)))
goto err;
- union_result->not_describe= 1;
union_result->tmp_table_param.init();
+ if (describe)
+ tmp_result= sel_result;
}
else
{
@@ -327,11 +349,11 @@ int st_select_lex_unit::exec()
ulonglong add_rows=0;
DBUG_ENTER("st_select_lex_unit::exec");
- if (executed && !uncacheable)
+ if (executed && !uncacheable && !describe)
DBUG_RETURN(0);
executed= 1;
- if (uncacheable || !item || !item->assigned())
+ if (uncacheable || !item || !item->assigned() || describe)
{
if (optimized && item && item->assigned())
{
@@ -350,7 +372,7 @@ int st_select_lex_unit::exec()
res= sl->join->reinit();
else
{
- if (sl != global_parameters)
+ if (sl != global_parameters && !describe)
{
offset_limit_cnt= sl->offset_limit;
select_limit_cnt= sl->select_limit+sl->offset_limit;
@@ -362,7 +384,7 @@ int st_select_lex_unit::exec()
We can't use LIMIT at this stage if we are using ORDER BY for the
whole query
*/
- if (sl->order_list.first)
+ if (sl->order_list.first || describe)
select_limit_cnt= HA_POS_ERROR;
else
select_limit_cnt= sl->select_limit+sl->offset_limit;