Skip to content

Commit 2d59531

Browse files
committed
cleanup: Select_limit_counters rename set_unlimited to clear
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.
1 parent 3fcc4f6 commit 2d59531

File tree

4 files changed

+20
-6
lines changed

4 files changed

+20
-6
lines changed

sql/sql_lex.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2910,7 +2910,7 @@ void st_select_lex_unit::init_query()
29102910
{
29112911
init_query_common();
29122912
set_linkage(GLOBAL_OPTIONS_TYPE);
2913-
lim.set_unlimited();
2913+
lim.clear();
29142914
union_distinct= 0;
29152915
prepared= optimized= optimized_2= executed= 0;
29162916
bag_set_op_optimized= 0;

sql/sql_limit.h

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,13 @@ class Select_limit_counters
3737
{
3838
offset_limit_cnt= offset;
3939
select_limit_cnt= limit;
40-
if (select_limit_cnt + offset_limit_cnt >=
41-
select_limit_cnt)
40+
/*
41+
Guard against an overflow condition, where limit + offset exceede
42+
ha_rows value range. This case covers unreasonably large parameter
43+
values that do not have any practical use so assuming in this case
44+
that the query does not have a limit is fine.
45+
*/
46+
if (select_limit_cnt + offset_limit_cnt >= select_limit_cnt)
4247
select_limit_cnt+= offset_limit_cnt;
4348
else
4449
select_limit_cnt= HA_POS_ERROR;
@@ -52,7 +57,16 @@ class Select_limit_counters
5257

5358
bool is_unlimited() const
5459
{ return select_limit_cnt == HA_POS_ERROR; }
60+
/*
61+
Set the limit to allow returning an unlimited number of rows. Useful
62+
for cases when we want to continue execution indefinitely after the limit
63+
is reached (for example for SQL_CALC_ROWS extension).
64+
*/
5565
void set_unlimited()
66+
{ select_limit_cnt= HA_POS_ERROR; }
67+
68+
/* Reset the limit entirely. */
69+
void clear()
5670
{ select_limit_cnt= HA_POS_ERROR; offset_limit_cnt= 0; }
5771

5872
bool check_offset(ha_rows sent) const

sql/sql_parse.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7761,8 +7761,8 @@ void mysql_init_multi_delete(LEX *lex)
77617761
{
77627762
lex->sql_command= SQLCOM_DELETE_MULTI;
77637763
mysql_init_select(lex);
7764-
lex->first_select_lex()->limit_params.select_limit= 0;
7765-
lex->unit.lim.set_unlimited();
7764+
lex->first_select_lex()->limit_params.clear();
7765+
lex->unit.lim.clear();
77667766
lex->first_select_lex()->table_list.
77677767
save_and_clear(&lex->auxiliary_table_list);
77687768
lex->query_tables= 0;

sql/sql_union.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1340,7 +1340,7 @@ bool st_select_lex_unit::prepare(TABLE_LIST *derived_arg,
13401340
else
13411341
{
13421342
sl->join->result= result;
1343-
lim.set_unlimited();
1343+
lim.clear();
13441344
if (!sl->join->procedure &&
13451345
result->prepare(sl->join->fields_list, this))
13461346
{

0 commit comments

Comments
 (0)