summaryrefslogtreecommitdiff
path: root/sql/sql_window.cc
Commit message (Collapse)AuthorAgeFilesLines
* Merge 10.2 into 10.3Marko Mäkelä2020-07-141-0/+8
|\
| * MDEV-22463: Element_type &Bounds_checked_array<Item *>::operator[](size_t) ↵Varun Gupta2020-07-131-0/+8
| | | | | | | | | | | | | | | | [Element_type = Item *]: Assertion `n < m_size' failed. Allocate space for fields inside the window function (arguments, PARTITION BY and ORDER BY clause) in the ref pointer array. All fields inside the window function are part of the temporary table that is required for the window function computation.
* | Merge 10.2 into 10.3Marko Mäkelä2020-06-051-1/+2
|\ \ | |/
| * MDEV-16230: Server crashes when Analyze format=json is run with a window ↵Varun Gupta2020-06-041-1/+2
| | | | | | | | | | | | | | | | | | function with empty PARTITION BY and ORDER BY clauses Currently when both PARTITION BY and ORDER BY clauses are empty then we create a Item with the first field in the select list and sort with that field. It should be created as an Item_temptable_field instead of Item_field because the print() function continues to work even if the table has been dropped.
* | MDEV-21392 Cleanup redundant overriding in Item_sum_numAlexander Barkov2019-12-251-5/+1
| |
* | MDEV-19698: Cleanup READ_RECORD::recordOleksandr Byelkin2019-06-071-1/+1
| | | | | | | | https://github.com/MariaDB/server/pull/777#issuecomment-496469366
* | Merge branch '10.2' into 10.3Oleksandr Byelkin2019-05-121-0/+27
|\ \ | |/
| * MDEV-14791: Crash with order by expression containing window functionsVarun Gupta2019-05-041-0/+27
| | | | | | | | | | | | | | | | | | | | | | 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.
* | Merge 10.2 into 10.3Marko Mäkelä2019-04-251-0/+16
|\ \ | |/
| * MDEV-15837: Assertion `item1->type() == Item::FIELD_ITEM && item2->type() == ↵Varun Gupta2019-04-241-0/+16
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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()
* | 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.