summaryrefslogtreecommitdiff
path: root/sql/item_windowfunc.h
diff options
context:
space:
mode:
authorSergei Petrunia <psergey@askmonty.org>2016-04-08 03:21:25 +0300
committerSergei Petrunia <psergey@askmonty.org>2016-04-08 03:21:25 +0300
commitcb002d34790d46442917575ccecfd9eca412dab8 (patch)
treeefc36bc9446a9e2fcc3aca34458370936d79fb4f /sql/item_windowfunc.h
parent59e5f5b47e1f12a1426319a905dbc8cc55219c0d (diff)
downloadmariadb-git-cb002d34790d46442917575ccecfd9eca412dab8.tar.gz
Window functions: make "ORDER BY window_func" work
- When window functions are present, JOIN::simple_order should be set to FALSE. (Otherwise, the optimizer may attempt to do a "pre-sorting" on the first join_tab. Which can work in some cases, but generally isn't) - filesort tries to only read table fields that it requires. Window function requires its temp.table field. In order to pass this info to filesort, added an implementation of Item_window_func:: register_field_in_read_map.
Diffstat (limited to 'sql/item_windowfunc.h')
-rw-r--r--sql/item_windowfunc.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/sql/item_windowfunc.h b/sql/item_windowfunc.h
index f239f7f2ccf..ad72bd7040c 100644
--- a/sql/item_windowfunc.h
+++ b/sql/item_windowfunc.h
@@ -511,6 +511,25 @@ public:
void update_used_tables();
+ /*
+ This is used by filesort to mark the columns it needs to read (because they
+ participate in the sort criteria and/or row retrieval. Window functions can
+ only be used in sort criteria).
+
+ Sorting by window function value is only done after the window functions
+ have been computed. In that case, window function will need to read its
+ temp.table field. In order to allow that, mark that field in the read_set.
+ */
+ bool register_field_in_read_map(uchar *arg)
+ {
+ TABLE *table= (TABLE*) arg;
+ if (result_field && (result_field->table == table || !table))
+ {
+ bitmap_set_bit(result_field->table->read_set, result_field->field_index);
+ }
+ return 0;
+ }
+
bool is_frame_prohibited() const
{
switch (window_func()->sum_func()) {