mirror of
https://github.com/MariaDB/server.git
synced 2025-07-27 18:02:13 +03:00
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.
This commit is contained in:
@ -1177,6 +1177,16 @@ public:
|
||||
uint top_join_tab_count;
|
||||
uint aggr_tables; ///< Number of post-join tmp tables
|
||||
uint send_group_parts;
|
||||
/*
|
||||
This represents the number of items in ORDER BY *after* removing
|
||||
all const items. This is computed before other optimizations take place,
|
||||
such as removal of ORDER BY when it is a prefix of GROUP BY, for example:
|
||||
GROUP BY a, b ORDER BY a
|
||||
|
||||
This is used when deciding to send rows, by examining the correct number
|
||||
of items in the group_fields list when ORDER BY was previously eliminated.
|
||||
*/
|
||||
uint with_ties_order_count;
|
||||
/*
|
||||
True if the query has GROUP BY.
|
||||
(that is, if group_by != NULL. when DISTINCT is converted into GROUP BY, it
|
||||
@ -1306,6 +1316,10 @@ public:
|
||||
*/
|
||||
double join_record_count;
|
||||
List<Item> *fields;
|
||||
|
||||
/* Used only for FETCH ... WITH TIES to identify peers. */
|
||||
List<Cached_item> order_fields;
|
||||
/* Used during GROUP BY operations to identify when a group has changed. */
|
||||
List<Cached_item> group_fields, group_fields_cache;
|
||||
THD *thd;
|
||||
Item_sum **sum_funcs, ***sum_funcs_end;
|
||||
@ -1609,6 +1623,8 @@ public:
|
||||
sjm_lookup_tables= 0;
|
||||
sjm_scan_tables= 0;
|
||||
is_orig_degenerated= false;
|
||||
|
||||
with_ties_order_count= 0;
|
||||
}
|
||||
|
||||
/* True if the plan guarantees that it will be returned zero or one row */
|
||||
|
Reference in New Issue
Block a user