summaryrefslogtreecommitdiff
path: root/sql/item_windowfunc.cc
Commit message (Collapse)AuthorAgeFilesLines
* MDEV-16489 when lead() returns null on a datetime field, the result is ↵Alexander Barkov2018-06-201-1/+1
| | | | treated as the literal string '[NULL]'
* Merge commit '6b8802e8dd5467556a024d807a1df23940b00895' into bb-10.3-fix_len_decbb-10.3-fix_len_decOleksandr Byelkin2018-06-191-2/+4
|\
| * MDEV-11071: Assertion `thd->transaction.stmt.is_empty()' failed in ↵Oleksandr Byelkin2018-06-151-2/+4
| | | | | | | | | | | | Locked_tables_list::unlock_locked_table fix_length_and_dec now return result (error/OK)
* | Merge 10.2 into 10.3Marko Mäkelä2018-06-181-3/+3
|\ \ | |/
| * MDEV-15870 Using aggregate and window function in unexpected places can ↵Alexander Barkov2018-06-131-3/+3
| | | | | | | | crash the server
* | MDEV-16385 ROW SP variable is allowed in unexpected contextAlexander Barkov2018-06-051-3/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The problem described in the bug report happened because the code did not test check_cols(1) after fix_fields() in a few places. Additionally, fix_fields() could be called multiple times for SP variables, because they are all fixed at a early stage in append_for_log(). Solution: 1. Adding a few helper methods - fix_fields_if_needed() - fix_fields_if_needed_for_scalar() - fix_fields_if_needed_for_bool() - fix_fields_if_needed_for_order_by() and using it in many cases instead of fix_fields() where the "fixed" status is not definitely known to be "false". 2. Adding DBUG_ASSERT(!fixed) into Item_splocal*::fix_fields() to catch double execution. 3. Adding tests. As a good side effect, the patch removes a lot of duplicate code (~60 lines): if (!item->fixed && item->fix_fields(..) && item->check_cols(1)) return true;
* | Merge bb-10.2-ext into 10.3Marko Mäkelä2018-02-151-0/+16
|\ \
| * | MDEV-15293 CAST(AS TIME) returns bad results for ↵Alexander Barkov2018-02-131-0/+11
| | | | | | | | | | | | LAST_VALUE(),NAME_CONST(),SP variable
| * | Merge remote-tracking branch 'origin/10.2' into bb-10.2-extAlexander Barkov2018-02-081-0/+5
| |\ \ | | |/
| | * fix Item_window_func::print() not to crash before fix_fields()Sergei Golubchik2018-02-061-0/+5
| | | | | | | | | | | | | | | | | | | | | because dbug_print_item() can be invoked any time in gdb, also before fix_fields. this fixes a crash of main.win in debug builds
* | | Merge bb-10.2-ext into 10.3Marko Mäkelä2017-11-301-2/+2
|\ \ \ | |/ /
| * | MDEV-14517 Cleanup for Item::with_subselect and Item::has_subquery()Alexander Barkov2017-11-281-2/+2
| | |
* | | Updates the tests for the percentile functionsVarun Gupta2017-11-011-4/+4
| | |
* | | Date-time fields are disabled currently for the result type of percentile ↵Varun Gupta2017-11-011-3/+2
| | | | | | | | | | | | function
* | | Tests added for percentile and median functionsVarun Gupta2017-11-011-1/+1
| | |
* | | Added fix_fields for percentile function to check the type of argument and ↵Varun Gupta2017-11-011-11/+43
| | | | | | | | | | | | to ensure that only numeric arguments are allowed
* | | Added the error ER_WRONG_TYPE_FOR_PERCENTILE_CONT, which ensures that the ↵Varun Gupta2017-11-011-7/+4
| | | | | | | | | | | | result type for percentile_cont is always numerical
* | | Added the error ER_NOT_SINGLE_ELEMENT_ORDER_LIST for th percentile ↵Varun Gupta2017-11-011-8/+1
| | | | | | | | | | | | | | | | | | functions, these ensure that for the percentile function we have the order list with exactly one element
* | | Ensured that the the element in the order by clause should have a numerical ↵Varun Gupta2017-11-011-0/+18
| | | | | | | | | | | | time, if not throw an error
* | | Percentile class implemented, most of the functions have the same ↵Varun Gupta2017-11-011-0/+21
| | | | | | | | | | | | functionalite as the percentile cont class
* | | Implemented the implementation of percentile functions using Item_cache ↵Varun Gupta2017-11-011-7/+7
| | | | | | | | | | | | instead of Cache_Item
* | | Setting handler to have the return type as that of the element by which we ↵Varun Gupta2017-11-011-0/+5
| | | | | | | | | | | | are ordering the partition
* | | Added value field to Item_sum_percentile_discVarun Gupta2017-11-011-0/+16
| | | | | | | | | | | | Check for single element in the order_list is added
* | | Enusure that my_global.h is included firstMichael Widenius2017-08-241-2/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - 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
* | | Added copyright message to some filesMichael Widenius2017-08-241-0/+16
|/ /
* | Merge 10.2 into bb-10.2-extMarko Mäkelä2017-06-191-1/+1
|\ \ | |/
| * Fixed the bug mdev-13064.Igor Babaev2017-06-161-1/+1
| | | | | | | | | | | | | | | | This is another attempt to fix the bug mdev-12992. This patch introduces st_select_lex::context_analysis_place for the place in SELECT where context analysis is currently performed. It's similar to st_select_lex::parsing_place, but it is used at the preparation stage.
* | MDEV-12719 Determine Item::result_type() from Item::type_handler()Alexander Barkov2017-05-071-2/+2
| |
* | Cleanup: changing set_handler_by_field_type(field_type()) to ↵Alexander Barkov2017-05-061-2/+2
| | | | | | | | | | | | set_handler(type_handler()). This gives better performance, as excludes handler-by-type lookup.
* | Changing field::field_name and Item::name to LEX_CSTRINGMonty2017-04-231-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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)
* | Merge remote-tracking branch 'origin/10.2' into bb-10.2-extAlexander Barkov2017-02-271-12/+1
|\ \ | |/
| * MDEV-11746: Wrong result upon using FIRST_VALUE with a window frameVicențiu Ciorbaru2017-02-141-12/+0
| | | | | | | | | | Reimplement FIRST_VALUE to act as NTH_VALUE with 0 offset. The previous implementation was flawed when the window frame would remove values.
| * Fixed bug mdev-11745.Igor Babaev2017-02-091-0/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Due to this bug many queries that contained a window function with MIN/MAX aggregation returned wrong results. Calculation of a MIN/MAX aggregate function uses cache objects and a comparator object that are created and set up in Item_sum_hybrid::fix_fields () by a call of Item_sum_hybrid::setup_hybrid(). The latter binds the objects to the first argument of the MIN/MAX function. Meanwhile window function perform aggregation over fields of a temporary table. So binding must be done rather to these fields. The earliest moment when setup the objects used in MIN/max functions can be done is after all calls of the method split_sum_func(). This patch introduces this late setup, but only for aggregate functions used in window functions. Probably it makes sense to use this late setup for all MIN/MAX objects.
* | MDEV-11357 Split Item_cache::get_cache() into virtual methods in Type_handlerAlexander Barkov2016-12-161-1/+1
|/ | | | | | | | | | | | | | | | This patch: - Adds a new virtual method Type_handler::Item_get_cache - Splits moves Item_cache::get_cache() into the new method, every "case XXX_RESULT" to the corresponding Type_handler_xxx::Item_get_cache. - Adds Item::get_cache as a convenience wrapper, to make the caller code shorter. - Changes the last argument of Arg_comparator::cache_converted_constant() from Item_result to "const Type_handler *". - Removes subselect_engine::cmp_type, subselect_engine::res_type, subselect_engine::res_field_type and derives subselect_engine from Type_handler_hybrid_field_type instead. - Makes Type_handler_varchar public, as it's now needed as the default data type handler for subselect_engine.
* Fixed bug mdev-10868.Igor Babaev2016-09-301-0/+7
| | | | | | | | 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.
* Implement LEAD and LAG and NTH_VALUE functionsVicențiu Ciorbaru2016-09-241-7/+211
| | | | | | | | | | | | | | Refactour out (into a copy for now) the logic of Item_sum_hybrid, to allow for multiple arguments. It does not contain the comparator members. The result is the class Item_sum_hybrid_simple. LEAD and LAG make use of this Item to store previous rows in a chache. It also helps in specifying the field type. Currently LEAD/LAG do not support default values. NTH_VALUE behaves identical to LEAD and LAG, except that the starting position cursor is placed on the top of the frame instead of the current row.
* Implement first_value and last_value as window functionsVicențiu Ciorbaru2016-09-241-0/+23
| | | | | Currently the implementation doesn't support removal, thus the computation is performed by running over the window frame again.
* MDEV-10059: Compute window functions with same sorting criteria simultaneouslyVicențiu Ciorbaru2016-09-091-32/+11
| | | | | | Perform only one table scan for each window function present. We do this by keeping keeping cursors for each window function frame bound and running them for each function for every row.
* Merge branch '10.2' into 10.2-mdev9864Galina Shalygina2016-05-081-0/+242