Commit graph

70 commits

Author SHA1 Message Date
Monty
4dc5075860 Fixed compiler warnings and test failures found by buildbot
Fixed ccfilter to detect errors where the column is included in the error message
2016-06-24 02:25:14 +03:00
Monty
fabeab7819 Cleanups
- Avoid some realloc() during startup
- Ensure that file_key_management_plugin frees it's memory early, even if
  it's linked statically.
- Fixed compiler warnings from unused variables and missing destructors
- Fixed wrong indentation
2016-04-28 16:36:02 +03:00
Sergei Petrunia
a81e711a06 MDEV-9925: Wrong result with aggregate function as a window function
Make Frame_range_current_row_bottom to take into account partition bounds.

Other partition bounds that could potentially hit the end of partition are
Frame_range_n_bottom, Frame_n_rows_following, Frame_unbounded_following,
and they all had end-of-partition protection.

To simplify the code, factored out end-of-partition checks into
class Partition_read_cursor.
2016-04-15 20:40:01 +03:00
Igor Babaev
5ff4b21e02 Fixed bug mdev-9897.
This bug revealed a serious problem: if the same partition list
was used in two window specifications then the temporary table created
to calculate window functions contained fields for two identical
partitions. This problem was fixed as well.
2016-04-14 00:47:28 -07:00
Sergei Petrunia
0f62eee2f8 Fix compiler warning 2016-04-11 23:59:51 +02:00
Sergei Petrunia
da7c5e3b85 MDEV-9895: Assertion `n_rows > 0' failed in Frame_cursor* get_frame_cursor
n=0 in "ROWS 0 PRECEDING" is valid, add handling for it:
- Adjust the assert
- Bottom bound of 'ROW 0 PRECEDING' is actually looking at the current
  row, that is, it needs to process partition's first row directly in
  Frame_n_rows_preceding::next_partition().
- Added testcases
2016-04-10 16:24:04 +02:00
Sergei Petrunia
2905b2feb6 Window functions: return error if aggregate is not supported as window functions 2016-04-10 11:28:33 +02:00
Sergei Petrunia
306de8a927 MDEV-9877: Window functions: wrong sort criteria is used
" The sort order for the sub-sequence of window functions starting
from the element marked by SORTORDER_CHANGE_FLAG up to the next
element marked by SORTORDER_CHANGE_FLAG must be taken from the
last element of the sub-sequence (not from the first one)."
2016-04-06 23:02:31 +03:00
Sergei Petrunia
2efabf81f1 MDEV-9847: Window functions: crash with big_tables=1
- Move filesort's sort_positions argument into class Filesort.
- Make window function code construct Filesort with sort_positions=true.
2016-04-06 20:34:23 +03:00
Sergei Petrunia
5b85d0a75b Window functions: Better class names
As discussed on the call:
- s/Window_funcs_computation_step/Window_funcs_computation/g
- s/Window_func_sort/Window_funcs_sort/g
2016-04-06 18:24:11 +03:00
Sergei Petrunia
9bd194b1b7 MDEV-9848: Window functions: reuse sorting and/or scanning
- Rename Window_funcs_computation to Window_funcs_computation_step
- Introduce Window_func_sort which invokes filesort and then
  invokes computation of all window functions that use this ordering.
- Expose Window functions' sort operations in EXPLAIN|ANALYZE FORMAT=JSON
2016-04-05 19:10:44 +03:00
Igor Babaev
e30bd913ae Fixed a problem with setting wrong flags for ordering in the code
of compare_window_funcs_by_window_specs().
2016-04-04 15:24:27 -07:00
Vicențiu Ciorbaru
be3902fceb Implement ntile window function.
The current implementation does not allow for a dynamic expression
within the sum function's parameter.
2016-04-04 22:04:18 +03:00
Vicențiu Ciorbaru
629f9feabe Fix post review comments regarding the usage of List<>. 2016-04-04 22:04:18 +03:00
Igor Babaev
0b89c61413 Fixed a problem with --ps-protocol.
Window names has to be resolved only once.
2016-04-01 14:05:51 -07:00
Igor Babaev
2e4bd4407e The implementation of the template bubble_sort assumed
that the call-back comparison function returns a positive
number when arg1 < arg2, and a negative number when arg1 > arg2.
This is not in line with other implementation of sorting
algorithm.
Changed bubble_sort: now a negative result from the comparison
function means that arg1 < arg2, and positive result means
that arg1 > arg2.
Changed accordingly all call-back functions that are used as
parameters in the call of bubble_sort.

Added a test case to check the proper sorting of window functions.
2016-04-01 12:00:54 -07:00
Igor Babaev
c9ff5cfbfd Fixed a crash in compare_window_frames().
The function did not take into account the case when only one of
of the pointers to the compared frames is NULL.
2016-03-30 12:43:57 -07:00
Igor Babaev
3450c2da02 Added sorting window function to minimize the number of scans
of the temporary table needed to compute them.
2016-03-30 02:07:48 -07:00
Vicențiu Ciorbaru
de35787a83 Merge branch 'cume_dist' into bb-10.2-mdev9543 2016-03-28 22:52:18 +03:00
Vicențiu Ciorbaru
3544fe0144 Implemented cume_dist function.
Also fixed a bug in row_counts detection, when partition changes.
2016-03-28 22:51:42 +03:00
Vicențiu Ciorbaru
d40d68f236 Convert percent_rank to work with cursors
The percent_rank function now is compatible with the cursor algorithm.
We no longer need a special implementation for it to work.
2016-03-28 22:51:42 +03:00
Vicențiu Ciorbaru
bf18dac08f Lay the groundwork for variable number of cursors.
Instead of relying solely on top bound and bottom bound cursors,
now we create a list of cursors that are iterated over.
2016-03-28 22:51:42 +03:00
Sergei Petrunia
4fe6fbbb63 Merge branch 'bb-10.2-mdev9543' of github.com:MariaDB/server into bb-10.2-mdev9543 2016-03-28 22:19:55 +03:00
Sergei Petrunia
2bd4dc38e0 Merge branch '10.2' into bb-10.2-mdev9543 2016-03-28 22:18:38 +03:00
Sergei Petrunia
d146c2cedc MDEV-9787: Window functions: HAVING and GROUP BY
- Hook window function computation into the right location.
- Add a testcase which shows that HAVING is now checked before
  the window function computation step.
2016-03-28 20:53:09 +03:00
Sergei Petrunia
44fdb56c97 MDEV-8646: Re-engineer the code for post-join operations
- Make EXPLAIN code use the post-join operations
- Remove Sort_and_group_tracker that was used for that purpose
2016-03-28 12:02:56 +03:00
Sergei Petrunia
75965892e3 Get rid of Window_func_runner::first_run
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.
2016-03-27 16:50:04 +03:00
Sergei Petrunia
cc59df65b2 Fix a typo 2016-03-27 12:15:11 +03:00
Sergei Petrunia
0786b0d2cd Make window function computation a part of the query plan
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.
2016-03-27 11:47:19 +03:00
Sergei Petrunia
6ad9ac212c Encapsulate use of List<Cached_item> in a Group_bound_tracker. 2016-03-24 03:23:14 +03:00
Sergei Petrunia
c7a60de78c Code cleanup 2016-03-24 03:08:43 +03:00
Sergei Petrunia
39d3cdbf22 Encapsulate the switching between different return values in Item_window_func 2016-03-24 02:57:03 +03:00
Sergei Petrunia
722f1b2dcc Move the deprecated comments out of the way 2016-03-24 02:42:38 +03:00
Sergei Petrunia
d8b8b5affa Fix a PS re-execution problem and code cleanup
- 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.
2016-03-24 02:09:17 +03:00
Igor Babaev
602e15a0cb Changed the base class for Item_window_func from Item_result_field to
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.
2016-03-21 20:00:05 -07:00
Sergei Petrunia
13f9535f2d MDEV-9724: Window functions: Frame Exclusion support
Produce a "not supported" error if one attempts to exclude rows
2016-03-18 11:32:38 +03:00
Sergei Petrunia
b0154190fb Remove the wrong check, win_spec->order_list may be empty but it is not NULL. 2016-03-17 21:50:07 +03:00
Sergei Petrunia
ee9297f656 MDEV-9740: Window functions: catch invalid window frame specs
Catch errors in window frame definitions
2016-03-17 16:55:44 +03:00
Igor Babaev
c3ab9712b0 Fixed the bug mdev-9719 concerning execution of prepared statements
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.
2016-03-16 23:35:28 -07:00
Igor Babaev
5eee8bbe87 The class Window_spec now has pointers to the partition and order lists
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.
2016-03-16 00:50:14 -07:00
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