a fix for --ps-protocol (bug #6089: FOUND_ROWS returns wrong values when no table/view is used)
sql/sql_union.cc: a fix for --ps-protocol (bug #6089: FOUND_ROWS returns wrong values when no table/view is used) Don't touch options as itit's not needed.
This commit is contained in:
parent
26f75ffc83
commit
737f7292b4
@ -482,3 +482,15 @@ execute stmt;
|
|||||||
pnum
|
pnum
|
||||||
deallocate prepare stmt;
|
deallocate prepare stmt;
|
||||||
drop table t1, t2;
|
drop table t1, t2;
|
||||||
|
prepare stmt from "SELECT SQL_CALC_FOUND_ROWS 'foo' UNION SELECT 'bar' LIMIT 0";
|
||||||
|
execute stmt;
|
||||||
|
foo
|
||||||
|
SELECT FOUND_ROWS();
|
||||||
|
FOUND_ROWS()
|
||||||
|
2
|
||||||
|
execute stmt;
|
||||||
|
foo
|
||||||
|
SELECT FOUND_ROWS();
|
||||||
|
FOUND_ROWS()
|
||||||
|
2
|
||||||
|
deallocate prepare stmt;
|
||||||
|
@ -485,3 +485,14 @@ execute stmt;
|
|||||||
deallocate prepare stmt;
|
deallocate prepare stmt;
|
||||||
drop table t1, t2;
|
drop table t1, t2;
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Bug #6089: FOUND_ROWS returns wrong values when no table/view is used
|
||||||
|
#
|
||||||
|
|
||||||
|
prepare stmt from "SELECT SQL_CALC_FOUND_ROWS 'foo' UNION SELECT 'bar' LIMIT 0";
|
||||||
|
execute stmt;
|
||||||
|
SELECT FOUND_ROWS();
|
||||||
|
execute stmt;
|
||||||
|
SELECT FOUND_ROWS();
|
||||||
|
deallocate prepare stmt;
|
||||||
|
@ -215,8 +215,6 @@ int st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result,
|
|||||||
select_limit_cnt= sl->select_limit+sl->offset_limit;
|
select_limit_cnt= sl->select_limit+sl->offset_limit;
|
||||||
if (select_limit_cnt < sl->select_limit)
|
if (select_limit_cnt < sl->select_limit)
|
||||||
select_limit_cnt= HA_POS_ERROR; // no limit
|
select_limit_cnt= HA_POS_ERROR; // no limit
|
||||||
if (select_limit_cnt == HA_POS_ERROR || sl->braces)
|
|
||||||
sl->options&= ~OPTION_FOUND_ROWS;
|
|
||||||
|
|
||||||
can_skip_order_by= is_union &&
|
can_skip_order_by= is_union &&
|
||||||
(!sl->braces || select_limit_cnt == HA_POS_ERROR);
|
(!sl->braces || select_limit_cnt == HA_POS_ERROR);
|
||||||
@ -342,7 +340,7 @@ int st_select_lex_unit::prepare(THD *thd_arg, select_result *sel_result,
|
|||||||
if (arena->is_stmt_prepare())
|
if (arena->is_stmt_prepare())
|
||||||
{
|
{
|
||||||
/* prepare fake select to initialize it correctly */
|
/* prepare fake select to initialize it correctly */
|
||||||
ulong options_tmp= init_prepare_fake_select_lex(thd);
|
(void) init_prepare_fake_select_lex(thd);
|
||||||
if (!(fake_select_lex->join= new JOIN(thd, item_list, thd->options,
|
if (!(fake_select_lex->join= new JOIN(thd, item_list, thd->options,
|
||||||
result)))
|
result)))
|
||||||
{
|
{
|
||||||
@ -448,20 +446,13 @@ int st_select_lex_unit::exec()
|
|||||||
select_limit_cnt= HA_POS_ERROR; // no limit
|
select_limit_cnt= HA_POS_ERROR; // no limit
|
||||||
|
|
||||||
/*
|
/*
|
||||||
When using braces, SQL_CALC_FOUND_ROWS affects the whole query.
|
When using braces, SQL_CALC_FOUND_ROWS affects the whole query:
|
||||||
We don't calculate found_rows() per union part
|
we don't calculate found_rows() per union part.
|
||||||
|
Otherwise, SQL_CALC_FOUND_ROWS should be done on all sub parts.
|
||||||
*/
|
*/
|
||||||
if (select_limit_cnt == HA_POS_ERROR || sl->braces)
|
sl->join->select_options=
|
||||||
sl->options&= ~OPTION_FOUND_ROWS;
|
(select_limit_cnt == HA_POS_ERROR || sl->braces) ?
|
||||||
else
|
sl->options & ~OPTION_FOUND_ROWS : sl->options | found_rows_for_union;
|
||||||
{
|
|
||||||
/*
|
|
||||||
We are doing an union without braces. In this case
|
|
||||||
SQL_CALC_FOUND_ROWS should be done on all sub parts
|
|
||||||
*/
|
|
||||||
sl->options|= found_rows_for_union;
|
|
||||||
}
|
|
||||||
sl->join->select_options=sl->options;
|
|
||||||
res= sl->join->optimize();
|
res= sl->join->optimize();
|
||||||
}
|
}
|
||||||
if (!res)
|
if (!res)
|
||||||
@ -493,7 +484,8 @@ int st_select_lex_unit::exec()
|
|||||||
}
|
}
|
||||||
/* Needed for the following test and for records_at_start in next loop */
|
/* Needed for the following test and for records_at_start in next loop */
|
||||||
table->file->info(HA_STATUS_VARIABLE);
|
table->file->info(HA_STATUS_VARIABLE);
|
||||||
if (found_rows_for_union & sl->options)
|
if (found_rows_for_union && !sl->braces &&
|
||||||
|
select_limit_cnt != HA_POS_ERROR)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
This is a union without braces. Remember the number of rows that
|
This is a union without braces. Remember the number of rows that
|
||||||
|
Loading…
x
Reference in New Issue
Block a user