Commit graph

30 commits

Author SHA1 Message Date
Vicențiu Ciorbaru
21651541ce Implemented avg() window function.
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.
2016-03-16 01:57:59 +02:00
Vicențiu Ciorbaru
350903e952 Remove no longer needed TODO. 2016-03-16 01:14:43 +02:00
Vicențiu Ciorbaru
93f2371020 Implemented a counter within Item_sum_sum
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.
2016-03-14 19:12:27 +02:00
Vicențiu Ciorbaru
a0c06ba1ed Preliminary implementation for the aggregate sum function as a window function
This implementation does not deal with the case where removal of
elements from the window frame causes the item to turn to a null value.
2016-03-14 15:42:00 +02:00
Sergei Petrunia
ce8a0d8e19 MDEV-9676: RANGE-type frames for window functions
- Handle ORDER BY DESC in window definitions.
- Fix an issue in Frame_range_current_row_top
2016-03-14 14:13:59 +03:00
Sergei Petrunia
e859c2dbb8 MDEV-9676: RANGE-type frames for window functions
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.
2016-03-13 03:34:31 +03:00
Sergei Petrunia
879731aa84 Better comments 2016-03-11 23:29:52 +03:00
Sergei Petrunia
1cb5c2c0e0 Use correct frame bounds when window frame was not specified
Also added win_bit.result (result values checked)
2016-03-11 23:00:15 +03:00
Sergei Petrunia
53784d9abc MDEV-9695: Wrong window frame when using RANGE BETWEEN N FOLLOWING AND PRECEDING
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)
2016-03-11 20:23:24 +03:00
Sergei Petrunia
0e9fb982f1 MDEV-9695: Wrong window frame when using RANGE BETWEEN N FOLLOWING AND PRECEDING
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.
2016-03-10 17:46:47 +03:00
Vicențiu Ciorbaru
42ededf4ad Create a default frame bound when no frame is specified. 2016-03-07 12:30:04 +02:00
Vicențiu Ciorbaru
974e65d368 Implement BIT_(AND|OR|XOR) functions as window functions. 2016-03-07 12:04:11 +02:00
Sergei Petrunia
1fa12cdfb7 MDEV-9676: RANGE-type frames for window functions
Support RANGE ... CURRENT ROW as frame's first and second bound.
2016-03-06 23:10:20 +03:00
Vicențiu Ciorbaru
b579a626cf Implement percent_rank window function 2016-03-03 18:48:34 +02:00
Vicențiu Ciorbaru
f638ffef2c Convert if statements to switch case. 2016-03-03 18:48:34 +02:00
Sergei Petrunia
86acf267fe Remove all comments starting with 'psergey' 2016-03-02 13:08:55 +03:00
Sergei Petrunia
dedf87fdf4 Rename window frame start/end to top/bottom. Bikeshed should be green. 2016-03-02 13:02:58 +03:00
Sergei Petrunia
7ee0140149 MDEV-9526: Compute Aggregate functions as window functions
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?
2016-03-01 15:07:57 +03:00
Sergei Petrunia
4104408c0c Re-factoring in window cursors code split Frame_unbounded
... into Frame_unbounded_preceding and Frame_unbounded_following
2016-02-28 01:37:18 +03:00
Igor Babaev
0c6d753708 Fixed a problems in the parser.
Resolved window names.
Checked some constraints for window frames.
Added test cases for window name resolution.
2016-02-19 23:20:09 -08:00
Sergei Petrunia
be15858245 MDEV-9526: Compute Aggregate functions as window functions
- 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.
2016-02-18 01:25:26 +03:00
Sergei Petrunia
c30119adc7 Testcase fix and code cleanup for window functions
- Make queries that use multiple window functions not to leak memory
- Code cleanup in sql_window.cc
2016-02-15 18:46:02 +03:00
Sergei Petrunia
d8a20d4db7 Post-merge fixes. win.test passes but further cleanup is needed. 2016-02-14 21:00:05 +03:00
Sergei Petrunia
a9ed132a0f More testcases, fixed comments 2016-02-14 11:30:40 +03:00
Sergei Petrunia
64ab10ffff Initial implementation of RANK() window function 2016-02-14 11:30:36 +03:00
Sergei Petrunia
30c9450af7 More comments 2016-02-14 11:30:14 +03:00
Sergei Petrunia
346c1a0ad0 Got sort-and-read single-pass window function computation to work 2016-02-14 11:29:53 +03:00
Sergei Petrunia
426cd232a7 Window functions: moving ahead
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.
2016-02-14 11:13:45 +03:00
Sergei Petrunia
c17f1df87b Moved window function computation code from JOIN::exec_inner() into
a separate function, JOIN::process_window_functions().
2016-02-14 11:13:00 +03:00
Igor Babaev
9d9c60fb12 Initial patch for the implementation of window functions (MDEV-6115):
- All parsing problems look like resolved
- Stub performing name resolution of window functions
in simplest queries has been added.
2016-02-12 20:33:56 -08:00