summaryrefslogtreecommitdiff
path: root/sql/sql_limit.h
diff options
context:
space:
mode:
authorVicențiu Ciorbaru <vicentiu@mariadb.org>2021-03-28 21:41:50 +0300
committerVicențiu Ciorbaru <vicentiu@mariadb.org>2021-04-21 14:09:14 +0300
commit299b93532036152ef47d6fa140199e2fc01dfecb (patch)
treededa241b116124f0e7363410e454072a5cc7f68b /sql/sql_limit.h
parent2d595319bf542dcdeeb058139efa2ef54f645c7b (diff)
downloadmariadb-git-299b93532036152ef47d6fa140199e2fc01dfecb.tar.gz
MDEV-23908: Implement SELECT ... OFFSET ... FETCH ...
This commit implements the standard SQL extension OFFSET start { ROW | ROWS } [FETCH { FIRST | NEXT } [ count ] { ROW | ROWS } { ONLY | WITH TIES }] To achieve this a reserved keyword OFFSET is introduced. The general logic for WITH TIES implies: 1. The number of rows a query returns is no longer known during optimize phase. Adjust optimizations to no longer consider this. 2. During end_send make use of an "order Cached_item"to compare if the ORDER BY columns changed. Keep returning rows until there is a change. This happens only after we reached the row limit. 3. Within end_send_group, the order by clause was eliminated. It is still possible to keep the optimization of using end_send_group for producing the final result set.
Diffstat (limited to 'sql/sql_limit.h')
-rw-r--r--sql/sql_limit.h16
1 files changed, 11 insertions, 5 deletions
diff --git a/sql/sql_limit.h b/sql/sql_limit.h
index 60034201a50..b51ebf72493 100644
--- a/sql/sql_limit.h
+++ b/sql/sql_limit.h
@@ -23,20 +23,23 @@
class Select_limit_counters
{
ha_rows select_limit_cnt, offset_limit_cnt;
+ bool with_ties;
public:
Select_limit_counters():
- select_limit_cnt(0), offset_limit_cnt(0)
+ select_limit_cnt(0), offset_limit_cnt(0), with_ties(false)
{};
- Select_limit_counters(Select_limit_counters &orig):
+ Select_limit_counters(const Select_limit_counters &orig):
select_limit_cnt(orig.select_limit_cnt),
- offset_limit_cnt(orig.offset_limit_cnt)
+ offset_limit_cnt(orig.offset_limit_cnt),
+ with_ties(orig.with_ties)
{};
- void set_limit(ha_rows limit, ha_rows offset)
+ void set_limit(ha_rows limit, ha_rows offset, bool with_ties_arg)
{
offset_limit_cnt= offset;
select_limit_cnt= limit;
+ with_ties= with_ties_arg;
/*
Guard against an overflow condition, where limit + offset exceede
ha_rows value range. This case covers unreasonably large parameter
@@ -53,6 +56,7 @@ class Select_limit_counters
{
offset_limit_cnt= 0;
select_limit_cnt= 1;
+ with_ties= false;
}
bool is_unlimited() const
@@ -67,7 +71,7 @@ class Select_limit_counters
/* Reset the limit entirely. */
void clear()
- { select_limit_cnt= HA_POS_ERROR; offset_limit_cnt= 0; }
+ { select_limit_cnt= HA_POS_ERROR; offset_limit_cnt= 0; with_ties= false;}
bool check_offset(ha_rows sent) const
{
@@ -79,6 +83,8 @@ class Select_limit_counters
{ return select_limit_cnt; }
ha_rows get_offset_limit() const
{ return offset_limit_cnt; }
+ bool is_with_ties() const
+ { return with_ties; }
};
#endif // INCLUDES_MARIADB_SQL_LIMIT_H