Commit graph

64593 commits

Author SHA1 Message Date
Vicențiu Ciorbaru
aa74fef25e Fix 2 more bugs in item_windowfunc.
1. Item_windowfunc must check the nullness of the field if it returns the
   value from the result_field.
2. The decimal value must come from the window_func instead of the
   result_field when not fetching values from the result_field.

Added a more extensive test case that highlights if these bugs occur.
The 2 select statements check behaviour for decimal and real typed
fields respectively.
2016-03-16 01:42:45 +02:00
Vicențiu Ciorbaru
350903e952 Remove no longer needed TODO. 2016-03-16 01:14:43 +02:00
Vicențiu Ciorbaru
333ac13be5 Make sure to return the result value when calling Item_windowfunc::val_real()
This caused Item_windowfunc to return garbage.
2016-03-16 01:09:53 +02:00
Sergei Petrunia
833304313d Continuation of "Implemented a counter within Item_sum_sum" a few commits before
Query result had 0 where it should have had NULLs:
- Make Item_window_func::val* functions honor NULL-handling conventions:
  1. set null_value to indicate whether we've returned a NULL value
  2. val_str and val_decimal should return NULL pointer when they're
     returning SQL NULL value.

Fix assertion failure when sending results to network.
- The assert was due to window func returing SQL NULL despite having
  maybe_null=false
- Fixed by settting Item_window_func::maybe_null correctly in fix_fields
2016-03-16 01:26:39 +03:00
Sergei Petrunia
21a0291c1d MDEV-8646: Re-engineer the code for post-join operations
Make query pushdown work in the post-refactored code.
This fixes sequence.group_by test.
2016-03-15 16:03:51 +03: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
1cc6fd1f00 Remove comments that may be confusing 2016-03-02 14:01:43 +03: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
Sergei Petrunia
d290a66553 MDEV-9634: Window function produces incorrect value
- Item_sum_count::remove() should check if the argument's value is NULL.
- Window Function item must have its Item_window_func::split_sum_func
  called,
- and it must call split_sum_func for aggregate's arguments (see the
  comment near Item_window_func::split_sum_func for explanation why)
2016-02-26 02:08:45 +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
Vicențiu Ciorbaru
0c223a96c1 Fix review comments. 2016-02-16 00:43:57 +02:00
Vicențiu Ciorbaru
9a673e0a88 Implement DENSE_RANK function. 2016-02-16 00:22:12 +02: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
687a51f8b5 Forgot to add sql_select.cc to the previous commit 2016-02-15 18:40:04 +03:00
Sergei Petrunia
970307f54a Cleanup: remove JOIN::table_access_tabs, top_table_access_tabs_count.
These do not have any meaning after MDEV-8646. Their only valid values are
- table_access_tabs= join_tab;
- top_table_access_tabs_count= top_join_tab_count;
2016-02-15 17:16:30 +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
6399187ebc Added comments 2016-02-14 11:14:34 +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
Sergei Petrunia
373cd9f587 Make the temp.table have columns for window function values. 2016-02-14 11:10:04 +03:00
Vicențiu Ciorbaru
9a2d895f33 Force need_tmp to true if we have window functions. 2016-02-14 11:10:04 +03:00
Sergei Petrunia
cb83e6c816 Fix buildbot failure
Debug printout should not attempt to print Ref_ptr_array value as %p.
2016-02-14 00:16:01 +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
Igor Babaev
2cfc450bf7 This is the consolidated patch for mdev-8646:
"Re-factor the code for post-join operations".

The patch mainly contains the code ported from mysql-5.6 and
created for two essential architectural changes:
1. WL#5558: Resolve ORDER BY execution method at the optimization stage
2. WL#6071: Inline tmp tables into the nested loops algorithm

The first task was implemented for mysql-5.6 by Ole John Aske.
It allows to make all decisions on ORDER BY operation at the optimization
stage.

The second task implemented for mysql-5.6 by Evgeny Potemkin adds JOIN_TAB
nodes for post-join operations that require temporary tables. It allows
to execute these operations within the nested loops algorithm that used to
be used before this task only for join queries. Besides these task moves
all planning on the execution of these operations from the execution phase
to the optimization phase.

Some other re-factoring changes of mysql-5.6 were pulled in, mainly because
it was easier to pull them in than roll them back. In particular all
changes concerning Ref_ptr_array were incorporated.

The port required some changes in the MariaDB code that concerned the
functionality of EXPLAIN and ANALYZE. This was done mainly by Sergey
Petrunia.
2016-02-09 12:35:59 -08:00
Alexander Barkov
7b50447aa6 MDEV-9407 Illegal mix of collation when using GROUP_CONCAT in a VIEW
MDEV-9408 CREATE TABLE SELECT MAX(int_column) creates different columns for table vs view

There were three almost identical pieces of the code:
- Field *Item_func::tmp_table_field();
- Field *Item_sum::create_tmp_field();
- Field *create_tmp_field_from_item();
with a difference in very small details (hence the bugs):
Only Item_func::tmp_table_field() was correct, the other two were not.
Removing the two incorrect pieces of the redundant code.
Joining these three functions/methods into a single virtual method
Item::create_tmp_field().
Additionally, moving Item::make_string_field() and
Item::tmp_table_field_from_field_type() from the public into the
protected section of the class declaration, as they are now not
needed outside of Item.
2016-01-16 18:45:26 +04:00
Alexander Barkov
5b9ee3f2ae MDEV-9220 Split filesort.cc:make_sortkey() and filesort.cc::sortlength() into virtual methods in Type_handler 2016-01-12 17:03:29 +04:00
Alexander Barkov
454589b67f MDEV-9393 Split Copy_field::get_copy_func() into virtual methods in Field
Also fixes:
MDEV-9391 InnoDB does not produce warnings when doing WHERE int_column=varchar_column
MDEV-9337 ALTER from DECIMAL and INT to DATETIME returns a wrong result
MDEV-9340 Copying from INT/DOUBLE to ENUM is inconsistent
MDEV-9392 Copying from DECIMAL to YEAR is not consistent about warnings
2016-01-11 17:20:16 +04:00
Alexander Barkov
2ba7ed77aa Merge remote-tracking branch 'origin/10.1' into 10.2 2015-12-29 19:37:11 +04:00
Alexander Barkov
1bb66ea88c Merge remote-tracking branch 'origin/10.0' into 10.1 2015-12-29 18:44:13 +04:00
Alexander Barkov
4d3bc26152 Merge remote-tracking branch 'origin/5.5' into 10.0 2015-12-29 18:41:37 +04:00