summaryrefslogtreecommitdiff
path: root/sql/sql_window.cc
Commit message (Collapse)AuthorAgeFilesLines
* Merge 10.2 into 10.3Marko Mäkelä2018-11-061-5/+12
|\ | | | | | | | | | | | | | | | | 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.
| * MDEV-12779 Oracle/DB2 Compatibility Implicit Ordering for ROW_NUMBER OVERVicențiu Ciorbaru2018-11-011-5/+12
| | | | | | | | | | | | | | | | | | | | | | | | 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.
* | MDEV-17137: Syntax errors with VIEW using MEDIANVarun Gupta2018-10-161-3/+16
| | | | | | | | | | | | | | 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
* | Merge 10.2 into 10.3Marko Mäkelä2018-05-121-1/+1
|\ \ | |/
| * MDEV-15853: Assertion `tab->filesort_result == 0' failedVarun Gupta2018-05-111-1/+1
| | | | | | | | | | | | | | 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.
* | Add likely/unlikely to speed up executionMonty2018-05-071-1/+1
| | | | | | | | | | | | | | | | | | 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()
* | Merge bb-10.2-ext into 10.3Marko Mäkelä2018-01-041-8/+1
|\ \
| * \ Merge remote-tracking branch 'origin/10.2' into bb-10.2-extMonty2018-01-011-7/+0
| |\ \ | | |/ | | | | | | | | | | | | | | | | | | | | | | | | 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
| | * MDEV-13683: crash in Item_window_func::update_used_tablesVicențiu Ciorbaru2017-12-281-7/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
| | * Fix several truncation and formatting warnings.Vladislav Vaintroub2017-10-031-1/+1
| | |
* | | Handle failures from mallocMichael Widenius2017-11-171-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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
* | | Updates the tests for the percentile functionsVarun Gupta2017-11-011-1/+1
| | |
* | | Changes made according to the review given, mostly fixing coding style errorsVarun Gupta2017-11-011-19/+18
| | |
* | | Remove has_error as a member from Item_sum and use THD::is_error() insteadVicențiu Ciorbaru2017-11-011-6/+4
| | | | | | | | | | | | | | | Additionally, allow a query with window functions to be killed by the user during its execution.
* | | made changes according to the review, mostly removing unused code and fixing ↵Varun Gupta2017-11-011-12/+8
| | | | | | | | | | | | code to follow the coding conventions
* | | Added the errorVarun Gupta2017-11-011-2/+10
| | | | | | | | | | | | | | | | | | 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
* | | Ensured that the the element in the order by clause should have a numerical ↵Varun Gupta2017-11-011-0/+6
| | | | | | | | | | | | time, if not throw an error
* | | Percentile class implemented, most of the functions have the same ↵Varun Gupta2017-11-011-0/+1
| | | | | | | | | | | | functionalite as the percentile cont class
* | | Implemented the implementation of percentile functions using Item_cache ↵Varun Gupta2017-11-011-52/+38
| | | | | | | | | | | | instead of Cache_Item
* | | Added a class Frame_unbounded_following_set_count_special, which is required ↵Varun Gupta2017-11-011-8/+77
| | | | | | | | | | | | | | | | | | to ignore all the null values while calculating the number of rows in the partition
* | | Setting handler to have the return type as that of the element by which we ↵Varun Gupta2017-11-011-0/+4
| | | | | | | | | | | | are ordering the partition
* | | MDEV-12985: support percentile and median window functionsVarun Gupta2017-11-011-0/+16
| | | | | | | | | | | | Finalised the synatax and have started implementing the class for the PERCENTILE_DISC
* | | Merge bb-10.2-ext into 10.3Marko Mäkelä2017-10-041-1/+1
|\ \ \ | |/ /
| * | Merge remote-tracking branch 'origin/10.2' into bb-10.2-extAlexander Barkov2017-10-021-1/+1
| |\ \ | | |/
| | * MDEV-13384 - misc Windows warnings fixedVladislav Vaintroub2017-09-281-1/+1
| | |
* | | simplify READ_RECORD usage NFCEugene Kosov2017-08-311-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | READ_RECORD read_record; ... // this // read_record.read_record(&read_record); // becomes just read_record.read_record();
* | | Merge branch 'bb-10.2-ext' into 10.3Sergei Golubchik2017-08-261-9/+8
|\ \ \ | |/ /
| * | More thorough correction of the patch that complemented the patch for mdev-10855Igor Babaev2017-08-241-8/+7
| | |
| * | Corrected the patch that complemented the patch for mdev-10855Igor Babaev2017-08-231-1/+1
| | |
* | | Enusure that my_global.h is included firstMichael Widenius2017-08-241-1/+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-2/+16
|/ /
* | Corrected the function compare_order_elements() to make itIgor Babaev2017-08-191-1/+2
| | | | | | | | platform independent.
* | This patch complements the patch for mdev-10855.Igor Babaev2017-08-191-0/+78
| | | | | | | | | | | | | | | | 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.
* | Merge remote-tracking branch 'origin/10.2' into bb-10.2-extAlexander Barkov2017-05-051-6/+1
|\ \ | |/
| * Fixed the bug mdev-11990.Igor Babaev2017-05-031-6/+1
| | | | | | | | | | | | | | | | 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.
* | Changing field::field_name and Item::name to LEX_CSTRINGMonty2017-04-231-5/+5
|/ | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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)
* MDEV-11868: min ( distinct ) over ( ) returns wrong valueVicențiu Ciorbaru2017-02-151-1/+11
| | | | | | The bug was not visible in current HEAD. Introduced test case to catch regressions. Also improve error messages regarding distinct usage in window functions.
* MDEV-10092: Server crashes in in ha_heap::rnd_pos / Table_read_cursor::get_nextVicențiu Ciorbaru2017-02-151-24/+35
| | | | | | | | | | | | | | | | | 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.
* MDEV-10859: Wrong result of aggregate window function in query with HAVING ↵Vicențiu Ciorbaru2017-02-151-0/+6
| | | | | | | | | | | | | | | 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.
* MDEV-11746: Wrong result upon using FIRST_VALUE with a window frameVicențiu Ciorbaru2017-02-141-5/+16
| | | | | | | 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.
* MDEV-11746: Wrong result upon using FIRST_VALUE with a window frameVicențiu Ciorbaru2017-02-141-8/+16
| | | | | 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-11138.Igor Babaev2017-02-041-0/+5
| | | | | Supported usage of expressions with window functions in SELECTs without tables.
* Post-review addition to the fix for mdev-10868.Igor Babaev2016-09-301-1/+6
|
* Fixed bug mdev-10868.Igor Babaev2016-09-301-0/+78
| | | | | | | | 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.
* Window functions can have an empty over clauseVicențiu Ciorbaru2016-09-241-2/+2
| | | | Make sure we select one window function if we have an empty over clause.
* Make sure to call Rowid_seq_cursor::next to not face infinite recursionVicențiu Ciorbaru2016-09-241-1/+1
|
* MDEV-9736: Window functions: multiple cursors to read filesort resultSergei Petrunia2016-09-241-43/+109
| | | | | | | | | | Add support for having multiple IO_CACHEs with type=READ_CACHE to share the file they are reading from. Each IO_CACHE keeps its own in-memory buffer. When doing a read or seek operation on the file, it notifies other IO_CACHEs that the file position has been changed. Make Rowid_seq_cursor use cloned IO_CACHE when reading filesort result.
* Clean up nth_valueVicențiu Ciorbaru2016-09-241-2/+6
| | | | Implement nth_value correctly and add a test case for it.
* Implement LEAD and LAG and NTH_VALUE functionsVicențiu Ciorbaru2016-09-241-42/+120
| | | | | | | | | | | | | | 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.
* MDEV-9935: Window functions: assertion failure with empty OVER () clauseVicențiu Ciorbaru2016-09-241-2/+24
| | | | | | Make window functions work with an empty over clause by forcing a sort on the first column of the current join_tab. This is a temporary fix until we get window functions to work with big tables.