summaryrefslogtreecommitdiff
path: root/sql/sql_limit.h
diff options
context:
space:
mode:
authorVicențiu Ciorbaru <vicentiu@mariadb.org>2021-03-28 21:09:51 +0300
committerVicențiu Ciorbaru <vicentiu@mariadb.org>2021-04-21 14:08:58 +0300
commit2d595319bf542dcdeeb058139efa2ef54f645c7b (patch)
tree0b1386cd1340b2a2c175f45f12d64e35e945e1b9 /sql/sql_limit.h
parent3fcc4f6fc24e8bde2f7d3a6aa162d69554bf8e6f (diff)
downloadmariadb-git-2d595319bf542dcdeeb058139efa2ef54f645c7b.tar.gz
cleanup: Select_limit_counters rename set_unlimited to clear
The function was originally introduced by eb0804ef5e7eeb059bb193c3c6787e8a4188d34d 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.
Diffstat (limited to 'sql/sql_limit.h')
-rw-r--r--sql/sql_limit.h18
1 files changed, 16 insertions, 2 deletions
diff --git a/sql/sql_limit.h b/sql/sql_limit.h
index 6f32e5d17e9..60034201a50 100644
--- a/sql/sql_limit.h
+++ b/sql/sql_limit.h
@@ -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;
@@ -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