Commit graph

64859 commits

Author SHA1 Message Date
Sergei Petrunia
0a34dc1e97 Code cleanup after merge of 260dd47 into 10.2-window-functions
length is now calculated in Filesort::make_sortorder.
2016-04-06 19:58:02 +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
Vicențiu Ciorbaru
7c9cfa07ad Fix ntile to work with --ps-protocol 2016-04-06 12:17:04 +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
960b221c0b Convert ntile to work with expressions as parameters. 2016-04-04 22:04:18 +03: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
a5d300814c Remove no longer used Window_context class. 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
162ea7c0cf Fix a problem in code for percent_rank().
The problem popped up when running win_percent_cume.test
with --ps-protocol.
2016-04-01 15:29:45 -07: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
Sergei Petrunia
2078392cc9 Make EXPLAIN FORMAT=JSON be able to show the key that's used for sorting.
This will be useful for window functions development.
2016-03-30 18:39:10 +03:00
Sergei Petrunia
9b5951c383 Fix the merge error in 2bd4dc38 (Merge branch '10.2' into bb-10.2-mdev9543) 2016-03-30 16:00:46 +03: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
e88758330c Make window functions computation step show up in EXPLAIN FORMAT=JSON output 2016-03-28 18:38:42 +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
24cd633fd8 Remove JOIN_TAB::used_window_func, it is not used anymore 2016-03-28 00:55:57 +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
c95e789e63 Remove out-of date code
gbh != NULL is handled in a separate branch above,
we don't get into this part of code when gbh!=NULL
2016-03-27 12:07:02 +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
Igor Babaev
8d1f8e8846 Merge branch 'bb-10.2-mdev9543' of github.com:MariaDB/server into bb-10.2-mdev9543 2016-03-23 16:10:47 -07:00
Igor Babaev
82cb35be11 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-23 16:09:58 -07: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
Sergei Golubchik
21ee0ca457 after merge fixes 2016-03-23 22:45:48 +01:00
Sergei Golubchik
f67a2211ec Merge branch '10.1' into 10.2 2016-03-23 22:36:46 +01:00
Sergei Golubchik
a75d269464 thread cache: cleanup DBUG state when caching a thread
this fixes 40 failures in mysql-test
2016-03-23 22:12:00 +01:00
Alexey Botchkov
2783fc7d14 MDEV-717 LP:1003679 - Wrong binlog order on concurrent DROP schema and CREATE function.
The cause of the issue is when DROP DATABASE takes
        metadata lock and is in progress through it's
        execution, a concurrently running CREATE FUNCTION checks
        for the existence of database which it succeeds and then it
        waits on the metadata lock.  Once DROP DATABASE writes to
        BINLOG and finally releases the metadata lock on schema
        object, the CREATE FUNCTION waiting on metadata lock
        gets in it's code path and succeeds and writes to binlog.
2016-03-23 12:16:39 +04:00
Alexander Barkov
e4435b5ec3 MDEV-9604 crash in Item::save_in_field with empty enum value
1. Fixing Field_time::get_equal_const_item() to pass TIME_FUZZY_DATES
   and TIME_INVALID_DATES to get_time_with_conversion().
   This is needed to make the recursively called Item::get_date() return
   non-NULL values on garbage input. This makes Field_time::get_equal_const_item()
   work consistently with how Item::val_time_packed() works.

2. Fixing Item::get_date() to return TIME'00:00:00' rather than
   DATE'0000-00-00' on empty or garbage input when:
   - TIME_FUZZY_DATES is enabled
   - The caller requested a TIME value (by passing TIME_TIME_ONLY).
   This is needed to avoid conversion of DATE'0000-00-00' to TIME
   in get_time_with_conversion(), which would erroneously try to subtract
   CURRENT_DATE from DATE'0000-00-00' and return TIME'-838:59:59' rather than
   the desired zero value TIME'00:00:00'.

   #1 and #2 fix these type of scripts to return one row with both
   MyISAM and InnoDB, with and without an index on t1.b:

     CREATE TABLE t1 (a ENUM('a'), b TIME, c INT, KEY(b));
     INSERT INTO t1 VALUES ('','00:00:00',0);
     SELECT * FROM t1 WHERE b='';
     SELECT * FROM t1 WHERE a=b;
     SELECT * FROM t1 IGNORE INDEX(b) WHERE b='';
     SELECT * FROM t1 IGNORE INDEX(b) WHERE a=b;

   Additionally, #1 and #2 fix the originally reported in MDEV-9604 crash
   in Item::save_in_field(), because now execution goes through a different
   path, so save_in_field() is called for a Item_time_literal instance
   (which is non-NULL) rather than a Item_cache_str instance (which could
   return NULL without setting null_value).

3. Fixing Field_temporal::get_equal_const_item_datetime() to enable
   equal field propagation for DATETIME and TIMESTAMP in case of
   comparison (e.g. when ANY_SUBST), for symmetry with
   Field_newdate::get_equal_const_item(). This fixes a number of problems
   with empty set returned on comparison to empty/garbage input.
   Now all SELECT queries in this script return one row for MyISAM and InnoDB,
   with and without an index on t1.b:

     CREATE TABLE t1 (a ENUM('a'), b DATETIME, c INT, KEY(b));
     INSERT INTO t1 VALUES ('','0000-00-00 00:00:00',0);
     SELECT * FROM t1 WHERE b='';
     SELECT * FROM t1 WHERE a=b;
     SELECT * FROM t1 IGNORE INDEX(b) WHERE b='';
     SELECT * FROM t1 IGNORE INDEX(b) WHERE a=b;
2016-03-23 08:26:40 +04:00
Monty
fa3edbf40d Increase value of thread_cache_size to 32
Added 5 minute timeout before automaticlally removing threads from thread
cache.

This solves a problem with jemalloc, which is slow with a small
thread cache and also makes thread_cache big enough that most users
doesn't have to touch it
2016-03-22 23:44:52 +02:00
Monty
260dd476b0 Removed TABLE->sort to make it possible to have multiple active calls to
filesort and init_read_record() for the same table.
This will simplify code for WINDOW FUNCTIONS (MDEV-6115)

- Filesort_info renamed to SORT_INFO and moved to filesort.h
- filesort now returns SORT_INFO
- init_read_record() now takes a SORT_INFO parameter.
- unique declaration is moved to uniques.h
- subselect caching of buffers is now more explicit than before
- filesort_buffer is now reusable even if rec_length has changed.
- filsort_free_buffers() and free_io_cache() calls are removed
- Remove one malloc() when using get_addon_fields()

Other things:
- Added --debug-assert-on-not-freed-memory option to make it easier to
  debug some not-freed-memory issues.
2016-03-22 23:44:52 +02:00
Oleksandr Byelkin
d0a47704c5 MDEV-9058: protocol: COM_MULTI command
Fix of status variable name and order.
2016-03-22 21:52:38 +01:00
Vicențiu Ciorbaru
287f2d2947 MDEV-9443: Add REVOKE <role> as a command to PREPARE 2016-03-22 22:21:04 +02:00
Vicențiu Ciorbaru
c4bef7ad3c MDEV-9443: Roles aren't supported in prepared statements
Make role statements work with the PREPARE keyword.
2016-03-22 22:21:04 +02:00
Alexey Botchkov
0a4a78ae8c MDEV-6058 MySQL Bug #11766693: LOG-SLOW-ADMIN-STATEMENTS AND
LOG-SLOW-SLAVE-STATEMENTS NOT DISPLAYED.

        These parameters were moved from the command line options to
        the system variables section. Treatment of the
        opt_log_slow_slave_statements changed to let the
        dynamic change of the variable.
2016-03-22 23:26:39 +04:00
Sergei Golubchik
fd6c588659 Merge branch 'bb-10.1-serg' into 10.1 2016-03-22 19:18:48 +01:00
Vladislav Vaintroub
6950f83d5e fix most annoying warnings on Windows 2016-03-22 18:46:02 +01:00