Skip to content

Commit

Permalink
cleanup: Select_limit_counters rename set_unlimited to clear
Browse files Browse the repository at this point in the history
The function was originally introduced by eb0804e
MDEV-18553: MDEV-16327 pre-requisits part 1: isolation of LIMIT/OFFSET handling

set_unlimited had an overloaded notion of both clearing the offset value
and the limit value. The code is used for SQL_CALC_ROWS option to
disable the limit clause after the limit is reached, while at the same
time the calling code suppreses sending of rows.

Proposed solution:
Dedicated clear method for query initialization (to ensure no garbage
remains between executions).
Dedicated set_unlimited that only alters the limit value.
  • Loading branch information
cvicentiu committed Apr 21, 2021
1 parent 3fcc4f6 commit 2d59531
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion sql/sql_lex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2910,7 +2910,7 @@ void st_select_lex_unit::init_query()
{
init_query_common();
set_linkage(GLOBAL_OPTIONS_TYPE);
lim.set_unlimited();
lim.clear();
union_distinct= 0;
prepared= optimized= optimized_2= executed= 0;
bag_set_op_optimized= 0;
Expand Down
18 changes: 16 additions & 2 deletions sql/sql_limit.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,13 @@ class Select_limit_counters
{
offset_limit_cnt= offset;
select_limit_cnt= limit;
if (select_limit_cnt + offset_limit_cnt >=
select_limit_cnt)
/*
Guard against an overflow condition, where limit + offset exceede
ha_rows value range. This case covers unreasonably large parameter
values that do not have any practical use so assuming in this case
that the query does not have a limit is fine.
*/
if (select_limit_cnt + offset_limit_cnt >= select_limit_cnt)
select_limit_cnt+= offset_limit_cnt;
else
select_limit_cnt= HA_POS_ERROR;
Expand All @@ -52,7 +57,16 @@ class Select_limit_counters

bool is_unlimited() const
{ return select_limit_cnt == HA_POS_ERROR; }
/*
Set the limit to allow returning an unlimited number of rows. Useful
for cases when we want to continue execution indefinitely after the limit
is reached (for example for SQL_CALC_ROWS extension).
*/
void set_unlimited()
{ select_limit_cnt= HA_POS_ERROR; }

/* Reset the limit entirely. */
void clear()
{ select_limit_cnt= HA_POS_ERROR; offset_limit_cnt= 0; }

bool check_offset(ha_rows sent) const
Expand Down
4 changes: 2 additions & 2 deletions sql/sql_parse.cc
Original file line number Diff line number Diff line change
Expand Up @@ -7761,8 +7761,8 @@ void mysql_init_multi_delete(LEX *lex)
{
lex->sql_command= SQLCOM_DELETE_MULTI;
mysql_init_select(lex);
lex->first_select_lex()->limit_params.select_limit= 0;
lex->unit.lim.set_unlimited();
lex->first_select_lex()->limit_params.clear();
lex->unit.lim.clear();
lex->first_select_lex()->table_list.
save_and_clear(&lex->auxiliary_table_list);
lex->query_tables= 0;
Expand Down
2 changes: 1 addition & 1 deletion sql/sql_union.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1340,7 +1340,7 @@ bool st_select_lex_unit::prepare(TABLE_LIST *derived_arg,
else
{
sl->join->result= result;
lim.set_unlimited();
lim.clear();
if (!sl->join->procedure &&
result->prepare(sl->join->fields_list, this))
{
Expand Down

0 comments on commit 2d59531

Please sign in to comment.