summaryrefslogtreecommitdiff
path: root/sql/sql_window.cc
Commit message (Collapse)AuthorAgeFilesLines
* Merge 10.11 into 11.0Marko Mäkelä2023-02-161-2/+2
|\
| * Merge 10.8 into 10.9Marko Mäkelä2023-02-161-2/+2
| |\
| | * Merge 10.5 into 10.6Marko Mäkelä2023-02-101-2/+2
| | |\
| | | * Merge 10.4 into 10.5Marko Mäkelä2023-02-101-2/+2
| | | |\
| | | | * Apply clang-tidy to remove empty constructors / destructorsVicențiu Ciorbaru2023-02-091-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch is the result of running run-clang-tidy -fix -header-filter=.* -checks='-*,modernize-use-equals-default' . Code style changes have been done on top. The result of this change leads to the following improvements: 1. Binary size reduction. * For a -DBUILD_CONFIG=mysql_release build, the binary size is reduced by ~400kb. * A raw -DCMAKE_BUILD_TYPE=Release reduces the binary size by ~1.4kb. 2. Compiler can better understand the intent of the code, thus it leads to more optimization possibilities. Additionally it enabled detecting unused variables that had an empty default constructor but not marked so explicitly. Particular change required following this patch in sql/opt_range.cc result_keys, an unused template class Bitmap now correctly issues unused variable warnings. Setting Bitmap template class constructor to default allows the compiler to identify that there are no side-effects when instantiating the class. Previously the compiler could not issue the warning as it assumed Bitmap class (being a template) would not be performing a NO-OP for its default constructor. This prevented the "unused variable warning".
* | | | | Improve comments in the optimizerMonty2023-01-301-0/+10
|/ / / /
* | | | Merge branch '10.8' into 10.9mariadb-10.9.1Sergei Golubchik2022-05-191-12/+56
|\ \ \ \ | |/ / /
| * | | Merge branch '10.5' into 10.6Sergei Golubchik2022-05-101-12/+56
| |\ \ \ | | |/ /
| | * | Merge branch '10.4' into 10.5Sergei Golubchik2022-05-091-12/+56
| | |\ \ | | | |/
| | | * Merge branch '10.2' into 10.3Sergei Golubchik2022-05-071-12/+56
| | | |\
| | | | * MDEV-19398: Assertion `item1->type() == Item::FIELD_ITEM ...Sergei Petrunia2022-05-041-10/+55
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Window Functions code tries to minimize the number of times it needs to sort the select's resultset by finding "compatible" OVER (PARTITION BY ... ORDER BY ...) clauses. This employs compare_order_elements(). That function assumed that the order expressions are Item_field-derived objects (that refer to a temp.table). But this is not always the case: one can construct queries order expressions are arbitrary item expressions. Add handling for such expressions: sort them according to the window specification they appeared in. This means we cannot detect that two compatible PARTITION BY clauses that use expressions can share the sorting step. But at least we won't crash.
* | | | | MDEV-28124 Server crashes in Explain_aggr_filesort::print_json_membersOleg Smirnov2022-04-291-2/+4
|/ / / / | | | | | | | | | | | | | | | | | | | | | | | | SHOW EXPLAIN/ANALYZE FORMAT=JSON tries to access items that have already been freed by a call to free_items() during THD::cleanup_after_query(). The solution is to disallow APC calls including SHOW EXPLAIN/ANALYZE just before the call to free_items().
* | | | Merge branch '10.5' into 10.6Oleksandr Byelkin2021-08-021-0/+12
|\ \ \ \ | |/ / /
| * | | Merge branch '10.4' into 10.5Oleksandr Byelkin2021-07-311-0/+12
| |\ \ \ | | |/ /
| | * | Merge branch '10.2' into 10.3Sergei Golubchik2021-07-211-0/+12
| | |\ \ | | | |/
| | | * MDEV-25565 Crash on 2-nd execution of SP/PS for query calculating window ↵Igor Babaev2021-07-201-0/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | functions from view A crash of the server happened when executing a stored procedure whose the only query calculated window functions over a mergeable view specified as a select from non-mergeable view. The crash could be reproduced if the window specifications of the window functions were identical and both contained PARTITION lists and ORDER BY lists. A crash also happened on the second execution of the prepared statement created for such query. If to use derived tables or CTE instead of views the problem still manifests itself crashing the server. When optimizing the window specifications of a window function the server can substitute the partition lists and the order lists for the corresponding lists from another window specification in the case when the lists are identical. This substitution is not permanent and should be rolled back before the second execution. It was not done and this ultimately led to a crash when resolving the column names at the second execution of SP/PS.
* | | | Replace item->marker= # with Item->marker= DEFINEMonty2021-05-261-15/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Better, easier to read code (no used of 'random' constants). - All defines are now unique, so it is easier to find bugs if somethings goes wrong. Other things: - Created sub function of common code in Aggregator_distinct::setup() and Item_func_group_concat::setup() that set item->marker - More documentation - Folded a few long lines. - Allmost all changes in item.cc, sql_lex.cc and sql_window.cc are done with 'replace'.
* | | | Remove calls to current_thd() in Item functionsMichael Widenius2021-05-191-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | - Added THD argument to functions that calls current_thd() or new without a mem_root argument: make_same(), set_comparator_func(), set_cmp_func(), set_cmp_func*(), set_aggregator() and prepare_sum_aggregators() - Changed "new Class" to "new (thd->mem_root) Class" Almost all changes mechanical, no logic changes.
* | | | Change bitfields in Item to an uint16Michael Widenius2021-05-191-5/+5
|/ / / | | | | | | | | | | | | | | | | | | | | | The reason for the change is that neither clang or gcc can do efficient code when several bit fields are change at the same time or when copying one or more bits between identical bit fields. Updated bits explicitely with & and | is MUCH more efficient than what current compilers can do.
* | | Merge 10.4 into 10.5Marko Mäkelä2020-07-151-0/+8
|\ \ \ | |/ /
| * | 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.4 into 10.5Marko Mäkelä2020-06-051-1/+2
|\ \ \ | |/ /
| * | 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-21915 Server crashes in copy_fields,Item_func_group_concat::add …Alexey Botchkov2020-04-291-0/+8
| | | | | | | | | | | | | | | | | | | | | …while using json_arrayagg() as a window function. We don't support JSON_ARRAYAGG and JSON_OBJECTAGG in window functions yet.
* | | perfschema memory related instrumentation changesSergei Golubchik2020-03-101-3/+3
|/ /
* | 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