Commit graph

140 commits

Author SHA1 Message Date
Alexander Barkov
ee9a19fb05 MDEV-21392 Cleanup redundant overriding in Item_sum_num 2019-12-25 12:23:24 +04:00
Oleksandr Byelkin
490dcfd5d7 MDEV-19698: Cleanup READ_RECORD::record
https://github.com/MariaDB/server/pull/777#issuecomment-496469366
2019-06-07 11:44:56 +02:00
Oleksandr Byelkin
c51f85f882 Merge branch '10.2' into 10.3 2019-05-12 17:20:23 +02:00
Varun Gupta
a6ea799651 MDEV-14791: Crash with order by expression containing window functions
The issue here is that for a window function in the ORDER BY clause, we were not
creating an extra field in the temporary table for the window function
(which is contained in an expression).
So a call to split_sum_func is added to handle this case

Also we need to update all items that contain a window function
in the temp table during window function computation as filesort would need
these values to be updated to calculate the ORDER BY clause of the select.
2019-05-04 13:07:55 +05:30
Marko Mäkelä
acf6f92aa9 Merge 10.2 into 10.3 2019-04-25 09:05:52 +03:00
Varun Gupta
1f1a61cfc4 MDEV-15837: Assertion `item1->type() == Item::FIELD_ITEM && item2->type() == Item::FIELD_ITEM'
failed in compare_order_elements function

The issue here is the function compare_order_lists() is called for the order by list of the window functions
so that those window function that can be computed together are adjacent.
So in the function compare_order_list we iterate over all the elements in the order list of the two functions and
compare the items in their order by clause.
The function compare_order_elements() is called for each item in the
order by clause. This function assumes that all the items that are in the order by list would be of the type
Item::FIELD_ITEM.

The case we have is that we have constants in the order by clause. We should ignore the constant and only compare
items of the type Item::FIELD_ITEM in compare_order_elements()
2019-04-24 12:58:04 +05:30
Marko Mäkelä
df563e0c03 Merge 10.2 into 10.3
main.derived_cond_pushdown: Move all 10.3 tests to the end,
trim trailing white space, and add an "End of 10.3 tests" marker.
Add --sorted_result to tests where the ordering is not deterministic.

main.win_percentile: Add --sorted_result to tests where the
ordering is no longer deterministic.
2018-11-06 09:40:39 +02:00
Vicențiu Ciorbaru
1c6b982e02 MDEV-12779 Oracle/DB2 Compatibility Implicit Ordering for ROW_NUMBER OVER
Users expect window functions to produce a certain ordering of rows in
the final result set. Although the standard does not require this, we
already have the filesort result done for when we computed the window
function. If there is no ORDER BY attached to the query, just keep it
till the SELECT is completely evaluated and use that to print the
result.

Update test cases as many did not take care to guarantee a stable
result.
2018-11-01 21:15:55 +02:00
Varun Gupta
97a37edc97 MDEV-17137: Syntax errors with VIEW using MEDIAN
The syntax error happened because we had not implemented a different print for
percentile functions. The syntax is a bit different when we use percentile functions
as window functions in comparision to normal window functions.
Implemented a seperate print function for percentile functions
2018-10-16 08:11:26 -07:00
Marko Mäkelä
15419a5583 Merge 10.2 into 10.3 2018-05-12 22:14:59 +03:00
Varun Gupta
16319409bf MDEV-15853: Assertion `tab->filesort_result == 0' failed
The issue here is that the window function execution is not called for the correct join tab, when we have GROUP BY
where we create extra temporary tables then we need to call window function execution for the last join tab. For doing
so the current code does not take into account the JOIN::aggr_tables.
Fixed by introducing a new function JOIN::total_join_tab_cnt that takes in account the temporary tables also.
2018-05-11 03:23:17 +05:30
Monty
30ebc3ee9e Add likely/unlikely to speed up execution
Added to:
- if (error)
- Lex
- sql_yacc.yy and sql_yacc_ora.yy
- In header files to alloc() calls
- Added thd argument to thd_net_is_killed()
2018-05-07 00:07:32 +03:00
Marko Mäkelä
145ae15a33 Merge bb-10.2-ext into 10.3 2018-01-04 09:22:59 +02:00
Monty
fbab79c9b8 Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext
Conflicts:
	cmake/make_dist.cmake.in
	mysql-test/r/func_json.result
	mysql-test/r/ps.result
	mysql-test/t/func_json.test
	mysql-test/t/ps.test
	sql/item_cmpfunc.h
2018-01-01 19:39:59 +02:00
Vicențiu Ciorbaru
6c4cf79d94 MDEV-13683: crash in Item_window_func::update_used_tables
Window definitions are resolved during fix fields. Updating used tables
for window functions must be done after all window functions have had a
chance to be resolved.

There was an additional problem with the implementation: expressions that
contained window functions never updated the expression's used tables.
To fix both these issues, make sure to call "update_used_tables" on all
items that contain window functions after we have passed through all
items.
2017-12-28 20:04:23 +02:00
Michael Widenius
87933d5261 Handle failures from malloc
Most "new" failures fixed in the following files:
- sql_select.cc
- item.cc
- item_func.cc
- opt_subselect.cc

Other things:
- Allocate udf_handler strings in mem_root
  - Required changes in sql_string.h
- Add mem_root as argument to some new [] calls
- Mark udf_handler strings as thread specific
- Removed some comment blocks with code
2017-11-17 07:30:05 +02:00
Varun Gupta
ab5503c8c5 Updates the tests for the percentile functions 2017-11-01 23:17:15 +05:30
Varun Gupta
b5c104d00a Changes made according to the review given, mostly fixing coding style errors 2017-11-01 23:16:59 +05:30
Vicențiu Ciorbaru
24e219b179 Remove has_error as a member from Item_sum and use THD::is_error() instead
Additionally, allow a query with window functions to be killed by the user during
its execution.
2017-11-01 23:13:02 +05:30
Varun Gupta
f8e135c7df made changes according to the review, mostly removing unused code and fixing code to follow the coding conventions 2017-11-01 23:13:02 +05:30
Varun Gupta
03ed22326a Added the error
1)ER_ARGUMENT_OUT_OF_RANGE: This error is thrown if the argument of the percentile function is not in the range [0,1]
  2)ER_ARGUMENT_NOT_CONSTANT: This error is thrown if the argument of the percnetile function is not constant in the
    entire partition of the window function
2017-11-01 23:13:01 +05:30
Varun Gupta
3393005e95 Ensured that the the element in the order by clause should have a numerical time, if not throw an error 2017-11-01 23:13:01 +05:30
Varun Gupta
275ce39f05 Percentile class implemented, most of the functions have the same functionalite as the percentile cont class 2017-11-01 23:13:01 +05:30
Varun Gupta
01d2b6e9d9 Implemented the implementation of percentile functions using Item_cache instead of Cache_Item 2017-11-01 23:13:01 +05:30
Varun Gupta
c85552f42b Added a class Frame_unbounded_following_set_count_special, which is required to ignore
all the null values while calculating the number of rows in the partition
2017-11-01 23:13:01 +05:30
Varun Gupta
31f1541f1e Setting handler to have the return type as that of the element by which we are ordering the partition 2017-11-01 23:13:01 +05:30
Varun Gupta
280945bf29 MDEV-12985: support percentile and median window functions
Finalised the synatax and have started implementing the class for the PERCENTILE_DISC
2017-11-01 23:13:01 +05:30
Marko Mäkelä
2c1067166d Merge bb-10.2-ext into 10.3 2017-10-04 08:24:06 +03:00
Vladislav Vaintroub
8d413c32dc Fix several truncation and formatting warnings. 2017-10-03 19:43:43 +00:00
Alexander Barkov
8ae8cd6348 Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext 2017-10-02 22:35:13 +04:00
Vladislav Vaintroub
7354dc6773 MDEV-13384 - misc Windows warnings fixed 2017-09-28 17:20:46 +00:00
Eugene Kosov
5dd8e1bf2d simplify READ_RECORD usage NFC
READ_RECORD read_record;
...
// this
// read_record.read_record(&read_record);
// becomes just
read_record.read_record();
2017-08-31 13:46:30 +04:00
Sergei Golubchik
bb8e99fdc3 Merge branch 'bb-10.2-ext' into 10.3 2017-08-26 00:34:43 +02:00
Igor Babaev
f2033df6ac More thorough correction of the patch that complemented the patch for mdev-10855 2017-08-24 20:49:07 -07:00
Igor Babaev
0336655918 Corrected the patch that complemented the patch for mdev-10855 2017-08-23 19:59:49 -07:00
Michael Widenius
4aaa38d26e Enusure that my_global.h is included first
- Added sql/mariadb.h file that should be included first by files in sql
  directory, if sql_plugin.h is not used (sql_plugin.h adds SHOW variables
  that must be done before my_global.h is included)
- Removed a lot of include my_global.h from include files
- Removed include's of some files that my_global.h automatically includes
- Removed duplicated include's of my_sys.h
- Replaced include my_config.h with my_global.h
2017-08-24 01:05:44 +02:00
Michael Widenius
b0da8897b0 Added copyright message to some files 2017-08-24 01:05:17 +02:00
Igor Babaev
a1e444e1cc Corrected the function compare_order_elements() to make it
platform independent.
2017-08-19 20:59:24 -07:00
Igor Babaev
d7b45e01b4 This patch complements the patch for mdev-10855.
It allows to push conditions into derived with window functions not
only in the cases when the window specifications of these window
functions use the same partition, but also in the cases when the window
functions use partitions that share only some fields. In these
cases only the conditions over the common fields are pushed.
2017-08-19 15:02:29 -07:00
Alexander Barkov
ac53b49b1b Merge remote-tracking branch 'origin/10.2' into bb-10.2-ext 2017-05-05 16:12:54 +04:00
Igor Babaev
ce8ee7d90b Fixed the bug mdev-11990.
The usage of windows functions when all tables were optimized away
by min/max optimization were not supported. As result a result,
the queries that used window functions with min/max aggregation
over the whole table returned wrong result sets.
The patch fixed this problem.
2017-05-03 13:50:35 -07:00
Monty
5a759d31f7 Changing field::field_name and Item::name to LEX_CSTRING
Benefits of this patch:
- Removed a lot of calls to strlen(), especially for field_string
- Strings generated by parser are now const strings, less chance of
  accidently changing a string
- Removed a lot of calls with LEX_STRING as parameter (changed to pointer)
- More uniform code
- Item::name_length was not kept up to date. Now fixed
- Several bugs found and fixed (Access to null pointers,
  access of freed memory, wrong arguments to printf like functions)
- Removed a lot of casts from (const char*) to (char*)

Changes:
- This caused some ABI changes
  - lex_string_set now uses LEX_CSTRING
  - Some fucntions are now taking const char* instead of char*
- Create_field::change and after changed to LEX_CSTRING
- handler::connect_string, comment and engine_name() changed to LEX_CSTRING
- Checked printf() related calls to find bugs. Found and fixed several
  errors in old code.
- A lot of changes from LEX_STRING to LEX_CSTRING, especially related to
  parsing and events.
- Some changes from LEX_STRING and LEX_STRING & to LEX_CSTRING*
- Some changes for char* to const char*
- Added printf argument checking for my_snprintf()
- Introduced null_clex_str, star_clex_string, temp_lex_str to simplify
  code
- Added item_empty_name and item_used_name to be able to distingush between
  items that was given an empty name and items that was not given a name
  This is used in sql_yacc.yy to know when to give an item a name.
- select table_name."*' is not anymore same as table_name.*
- removed not used function Item::rename()
- Added comparision of item->name_length before some calls to
  my_strcasecmp() to speed up comparison
- Moved Item_sp_variable::make_field() from item.h to item.cc
- Some minimal code changes to avoid copying to const char *
- Fixed wrong error message in wsrep_mysql_parse()
- Fixed wrong code in find_field_in_natural_join() where real_item() was
  set when it shouldn't
- ER_ERROR_ON_RENAME was used with extra arguments.
- Removed some (wrong) ER_OUTOFMEMORY, as alloc_root will already
  give the error.

TODO:
- Check possible unsafe casts in plugin/auth_examples/qa_auth_interface.c
- Change code to not modify LEX_CSTRING for database name
  (as part of lower_case_table_names)
2017-04-23 22:35:46 +03:00
Vicențiu Ciorbaru
d06a44e027 MDEV-11868: min ( distinct ) over ( ) returns wrong value
The bug was not visible in current HEAD. Introduced test case to catch
regressions. Also improve error messages regarding distinct usage in
window functions.
2017-02-15 14:09:27 +02:00
Vicențiu Ciorbaru
d474642254 MDEV-10092: Server crashes in in ha_heap::rnd_pos / Table_read_cursor::get_next
The bug was caused by several issues.
2 problems in seek_io_cache. Due to wrong offsets used, we would end up
seeking way too much (first change), or over the intended seek point
(second change). Fixing it requires correctly detecting available data
in buffer (first change), and not using "IO_SIZE alligned" reads. The
second is needed because _my_b_cache_read adjusts the pos_in_file itself
based on read_pos and read_end. Pretending buffer is empty when we want
to force a read will aleviate this problem.

Secondly, the big-table cursors didn't repect the interface definitions
of always returning the rownumber that Table_read_cursor::fetch() would activate.

At the same time, next(), prev() and move_to() should not perform any
row activation.
2017-02-15 14:09:27 +02:00
Vicențiu Ciorbaru
9fe9fb68ac MDEV-10859: Wrong result of aggregate window function in query with HAVING and no ORDER BY
Window functions need to be computed after applying the HAVING clause.
An optimization that we have for regular, non-window function, cases is
to apply having only during sending of the rows to the client. This
allows rows that should be filtered from the temporary table used to
store aggregation results to be stored there.

This behaviour is undesireable for window functions, as we have to
compute window functions on the result-set after HAVING is applied.
Storing extra rows in the table leads to wrong values as the frame
bounds might capture those -to be filtered afterwards- rows.
2017-02-15 14:09:27 +02:00
Vicențiu Ciorbaru
5bf338435a MDEV-11746: Wrong result upon using FIRST_VALUE with a window frame
The same approach is needed for LAST_VALUE, otherwise the LAST_VALUE sum
functions are not cleared correctly. Now LAST_VALUE behaves as NTH_VALUE
with 0 offset, only that the frame that it is examining is the bottom bound,
not the top bound.
2017-02-14 07:46:58 +02:00
Vicențiu Ciorbaru
57341852b5 MDEV-11746: Wrong result upon using FIRST_VALUE with a window frame
Reimplement FIRST_VALUE to act as NTH_VALUE with 0 offset. The previous
implementation was flawed when the window frame would remove values.
2017-02-14 07:46:58 +02:00
Igor Babaev
e51b015fc3 Fixed bug mdev-11138.
Supported usage of expressions with window functions
in SELECTs without tables.
2017-02-04 21:51:40 -08:00
Igor Babaev
6681a4998e Post-review addition to the fix for mdev-10868. 2016-09-30 17:40:42 -07:00
Igor Babaev
903f34c7a9 Fixed bug mdev-10868.
There was no implementation of the virtual method print()
for the Item_window_func class. As a result for a view
containing window function an invalid view definition could
be written in the frm file. When a query that refers to
this view was executed a syntax error was reported.
2016-09-30 17:40:40 -07:00