1
0
mirror of https://github.com/MariaDB/server.git synced 2025-08-08 11:22:35 +03:00

EXPLAIN UNION using same routing which used for execution which allow return correct bug messages (Bug #3639)

EXPLAIN of hidden SELECT of UNION


mysql-test/r/derived.result:
  explain of hidden select
mysql-test/r/subselect.result:
  explain of hidden select
mysql-test/r/union.result:
  explain of hidden select
  correct error messages on explain
mysql-test/t/subselect.test:
  show eliminated costants in WHERE clause
mysql-test/t/union.test:
  correct error messages on EXPLAIN with union
sql/item.cc:
  fixed name constructing for global ORDER BY items
sql/sql_class.h:
  select ID can be negative (for hidden SELECTs)
  removed unused field
sql/sql_lex.cc:
  new flag of UNION EXPLAIN
sql/sql_lex.h:
  new flag of UNION EXPLAIN
  select ID can be negative (for hidden SELECTs)
sql/sql_select.cc:
  EXPLAIN UNION using same routing which used for execution
  explain for hidden SELECT of UNION
sql/sql_union.cc:
  EXPLAIN UNION using same routing which used for execution
This commit is contained in:
unknown
2004-05-06 20:40:21 +03:00
parent cd57fc8bda
commit 1a4f499ca8
11 changed files with 179 additions and 74 deletions

View File

@@ -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));
/*
@@ -114,6 +114,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)
@@ -121,7 +123,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;
@@ -134,8 +155,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
{
@@ -269,11 +291,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())
{
@@ -292,7 +314,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;
@@ -304,7 +326,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;
@@ -373,7 +395,7 @@ int st_select_lex_unit::exec()
if (!thd->is_fatal_error) // Check if EOM
{
ulong options_tmp= thd->options;
ulong options_tmp= thd->options | fake_select_lex->options;
thd->lex->current_select= fake_select_lex;
offset_limit_cnt= global_parameters->offset_limit;
select_limit_cnt= global_parameters->select_limit +