- Hook window function computation into the right location.
- Add a testcase which shows that HAVING is now checked before
the window function computation step.
We can call setup_partition_border_check() from
JOIN::make_aggr_tables_info(), provided that call is made after
appropriate set_items_ref_array() call.
Added class Window_funcs_computation, with setup() method to setup
execution, and exec() to run window function computation.
setup() is currently trivial. In the future, it is expected to optimize
the number of sorting operations and passes that are done over the temp.
table.
- Make Item_XXX::cleanup() clean List<Cached_item> orderby_fields.
(Items survive across PS re-executions. Cached_item don't, because
they keep pointers to fix_field'ed items, etc)
- Move List<Cached_item> out into Group_bound_tracker.
Item_func_or_sum.
Implemented method update_used_tables for class Item_findow_func.
Added the flag Item::with_window_func.
Made sure that window functions could be used only in SELECT list
and ORDER BY clause.
Added test cases that checked different illegal placements of
window functions.
with window functions. Added the test case for it.
Also allowed to use aliases for set functions in partition and order lists
that are specified in window functions.
of the type SQL_I_List<ORDER> rather then the objects of this type.
It allows to replace easily one instance of such a list for another.
Besides it will facilitate to compare two lists if they originate from the
same window specification.
In fact any direct assignment for objects of the type SQL_I_List<ORDER>
was not valid.
It is based on the sum() function, thus much of the logic is shared.
Considering that there are 2 counters stored within the function, one
that handles the null value, while the other that handles the divisor
for the avg computation, it is possible to remove the counter from the
Item_sum_avg. I have not removed it in this patch as we may choose to
refactor the whole code into a separate class.
This remains to be dicussed.
The counter keeps track of the number of items added to the sum
function. It is increased when we add a value to the sum function and
decreased when it is removed.
Add support for "RANGE n PRECEDING|FOLLOWING" frame bounds.
- n is currently limited to whatever Item and Item_sum_plus/minus
can handle (i.e. no DATETIME intervals).
- Didn't check NULL value handling yet.
Part#2: Fix a couple more issues in rows-type frames.
This also has a code cleanup:
- introduce a separate Frame_rows_current_row_(top,bottom). This is
is a special case which doesn't need its cursor or partition bound check
- Split Frame_n_rows into
= Frame_n_rows_preceding (this one is now much simpler)
= Frame_n_rows_following (simpler and works but may need some work still)
Part#1: Frame_n_rows::next_partition() should not assume that the
current table->record[0] points to the first row in the partition.
Since cursor supports move_to() operation, we dont need this.
Introduce explicitly-defined cursors.
- Rowid_seq_cursor just reads the rowid sequence
- Table_read_cursor also reads rows for the rowids
- Also, we need a kind of cursor that stops at partition boundary?
- Add temporary code: clone_read_record() clones READ_RECORD structure,
as long as it is used for reading filesort() result that fits into
memory.
- Add frame bounds for ROWS-type frames. ROWS n PRECEDING|FOLLOWING,
ROWS UNBOUNDED PRECEDING|FOLLOWING, CURRENT ROW are supported.
- Add Item_sum_count::remove() which allows "streaming" computation
of COUNT() over a moving frame.
Disable the code that attempts to group window functions together
by their PARTITION BY / ORDER BY clauses, because
1. It doesn't work: when I issue a query with just one window function,
and no indexes on the table, filesort is not invoked at all.
2. It is not possible to check that it works currently.
Add my own code that does invoke filesort() for each window function.
- Hopefully the sort criteria is right
- Debugging shows that filesort operates on {sort_key, rowid} pairs (OK)
- We can read the filesort rowid result in order.