summaryrefslogtreecommitdiff
path: root/sql/item_cmpfunc.cc
Commit message (Collapse)AuthorAgeFilesLines
* Merge branch '10.8' into 10.9Oleksandr Byelkin2023-01-311-26/+57
|\
| * Merge branch '10.6' into 10.7Oleksandr Byelkin2023-01-311-26/+57
| |\
| | * Merge branch '10.5' into 10.6Oleksandr Byelkin2023-01-311-26/+57
| | |\
| | | * Merge branch '10.4' into 10.5Oleksandr Byelkin2023-01-271-26/+57
| | | |\
| | | | * MDEV-29294 Assertion `functype() == ((Item_cond *) new_item)->functype()' ↵Oleg Smirnov2023-01-201-26/+57
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | failed in Item_cond::remove_eq_conds on SELECT Item_singlerow_subselect may be converted to Item_cond during optimization. So there is a possibility of constructing nested Item_cond_and or Item_cond_or which is not allowed (such conditions must be flattened). This commit checks if such kind of optimization has been applied and flattens the condition if needed
* | | | | Merge 10.8 into 10.9Marko Mäkelä2023-01-131-46/+16
|\ \ \ \ \ | |/ / / /
| * | | | Merge 10.6 into 10.7Marko Mäkelä2023-01-131-46/+16
| |\ \ \ \ | | |/ / /
| | * | | Merge 10.5 into 10.6Marko Mäkelä2023-01-131-46/+16
| | |\ \ \ | | | |/ /
| | | * | Merge 10.4 into 10.5Marko Mäkelä2023-01-131-17/+16
| | | |\ \ | | | | |/
| | | | * Merge branch '10.3' into 10.4Sergei Golubchik2023-01-101-11/+2
| | | | |\
| | | | | * MDEV-29988: (revert) Major performance regression with 10.6.11Dmitry Shulga2023-01-021-11/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Reverted changed in server code introduced by the commit bd9274faa469cc164099c7497c18a0e0a9b1184b. Tests from this commit are retained.
| | | | * | MDEV-17869 AddressSanitizer: use-after-poison in ↵Sergei Golubchik2023-01-091-6/+14
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Item_change_list::rollback_item_tree_changes it's incorrect to use change_item_tree() to replace arguments of top-level AND/OR, because they (arguments) are stored in a List, so a pointer to an argument is in the list_node, and individual list_node's of top-level AND/OR can be deleted in Item_cond::build_equal_items(). In that case rollback_item_tree_changes() will modify the deleted object. Luckily, it's not needed to use change_item_tree() for top-level AND/OR, because the whole top-level item is copied and preserved in prep_where and prep_on, and restored from there. So, just don't. Additionally to the test case in the commit it fixes * ASAN failure of main.opt_tvc --ps * ASAN failure of main.having_cond_pushdown --ps
* | | | | | Merge branch '10.8' into 10.9Oleksandr Byelkin2022-11-011-2/+91
|\ \ \ \ \ \ | |/ / / / /
| * | | | | Merge branch '10.6' into 10.7Oleksandr Byelkin2022-10-291-2/+91
| |\ \ \ \ \ | | |/ / / /
| | * | | | followup: fix ASAN failure of main.having_cond_pushdown --psSergei Golubchik2022-10-291-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | also call top_level_transform() recursively for (a OR b) AND (c OR d)
| | * | | | MDEV-29895 prepared view crash server (unit.conc_view)Sergei Golubchik2022-10-291-0/+29
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | it's incorrect to use change_item_tree() to replace arguments of top-level AND/OR, because they (arguments) are stored in a List, so a pointer to an argument is in the list_node, and individual list_node's of top-level AND/OR can be deleted in Item_cond::build_equal_items(). In that case rollback_item_tree_changes() will modify the deleted object. Luckily, it's not needed to use change_item_tree() for top-level AND/OR, because the whole top-level item is copied and preserved in prep_where and prep_on, and restored from there. So, just don't.
| | * | | | MDEV-29662 Replace same values in 'IN' list with an equalityOleg Smirnov2022-10-261-0/+51
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | If all elements in the list of 'IN' or 'NOT IN' clause are equal and there are no NULLs then clause - "a IN (e1,..,en)" can be converted to "a = e1" - "a NOT IN (e1,..,en)" can be converted to "a <> e1". This means an object of Item_func_in can be replaced with an object of Item_func_eq for IN (e1,..,en) clause and Item_func_ne for NOT IN (e1,...,en). Such a replacement allows the optimizer to choose a better execution plan
| | * | | | Merge 10.5 into 10.6Marko Mäkelä2022-10-251-2/+11
| | |\ \ \ \ | | | |/ / / | | | | | | | | | | | | | | | | | | | | | | | | To prevent ASAN heap-use-after-poison in the MDEV-16549 part of ./mtr --repeat=6 main.derived the initialization of Name_resolution_context was cleaned up.
| | | * | | Merge 10.4 into 10.5Marko Mäkelä2022-10-251-2/+11
| | | |\ \ \ | | | | |/ /
| | | | * | Merge 10.3 into 10.4Marko Mäkelä2022-10-251-2/+11
| | | | |\ \ | | | | | |/
| | | | | * MDEV-16128: Server crash in Item_func::print_op on 2nd execution of PSDmitry Shulga2022-10-171-2/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | For some queries that involve tables with different but convertible character sets for columns taking part in the query, repeatable execution of such queries in PS mode or as part of a stored routine would result in server abnormal termination. For example, CREATE TABLE t1 (a2 varchar(10)); CREATE TABLE t2 (u1 varchar(10) CHARACTER SET utf8); CREATE TABLE t3 (u2 varchar(10) CHARACTER SET utf8); PREPARE stmt FROM "SELECT t1.* FROM (t1 JOIN t2 ON (t2.u1 = t1.a2)) WHERE (EXISTS (SELECT 1 FROM t3 WHERE t3.u2 = t1.a2))"; EXECUTE stmt; EXECUTE stmt; <== Running this prepared statement the second time results in server crash. The reason of server crash is that an instance of the class Item_func_conv_charset, that created for conversion of a column from one character set to another, is allocated on execution memory root but pointer to this instance is stored in an item placed on prepared statement memory root. Below is calls trace to the place where an instance of the class Item_func_conv_charset is created. setup_conds Item_func::fix_fields Item_bool_rowready_func2::fix_length_and_dec Item_func::setup_args_and_comparator Item_func_or_sum::agg_arg_charsets_for_comparison Item_func_or_sum::agg_arg_charsets Item_func_or_sum::agg_item_set_converter Item::safe_charset_converter And the following trace shows the place where a pointer to the instance of the class Item_func_conv_charset is passed to the class Item_func_eq, that is created on a memory root of the prepared statement. Prepared_statement::execute mysql_execute_command execute_sqlcom_select handle_select mysql_select JOIN::optimize JOIN::optimize_inner convert_join_subqueries_to_semijoins convert_subq_to_sj To fix the issue, switch to the Prepared Statement memory root before calling the method Item_func::setup_args_and_comparator in order to place any created Items on permanent memory root. It may seem that such approach would result in a memory leakage in case the parameter marker '?' is used in the query as in the following example PREPARE stmt FROM "SELECT t1.* FROM (t1 JOIN t2 ON (t2.u1 = t1.a2)) WHERE (EXISTS (SELECT 1 FROM t3 WHERE t3.u2 = ?))"; EXECUTE stmt USING convert('A' using latin1); but it wouldn't since for such case any of the parameter markers is treated as a constant and no subquery to semijoin optimization is performed.
* | | | | | Merge branch '10.8' into 10.9Oleksandr Byelkin2022-08-091-1/+14
|\ \ \ \ \ \ | |/ / / / /
| * | | | | Merge branch '10.6' into 10.7Oleksandr Byelkin2022-08-081-1/+14
| |\ \ \ \ \ | | |/ / / /
| | * | | | Merge branch '10.5' into 10.6Oleksandr Byelkin2022-08-041-1/+12
| | |\ \ \ \ | | | |/ / /
| | | * | | Merge branch '10.4' into 10.5Oleksandr Byelkin2022-08-041-1/+12
| | | |\ \ \ | | | | |/ /
| | | | * | Merge branch '10.3' into 10.4Oleksandr Byelkin2022-08-031-1/+12
| | | | |\ \ | | | | | |/
| | | | | * MDEV-23809: Server crash in JOIN_CACHE::free or ...Sergei Petrunia2022-08-031-1/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The problem was caused by use of COLLATION(AVG('x')). This is an item whose value is a constant. Name Resolution code called convert_const_to_int() which removed AVG('x'). However, the item representing COLLATION(...) still had with_sum_func=1. This inconsistent state confused the code that handles grouping and DISTINCT: JOIN::get_best_combination() decided to use one temporary table and allocated one JOIN_TAB for it, but then JOIN::make_aggr_tables_info() attempted to use two and made writes beyond the end of the JOIN::join_tab array. The fix: - Do not replace constant expressions which contain aggregate functions. - Add JOIN::dbug_join_tab_array_size to catch attempts to use more JOIN_TAB objects than we've allocated.
| | * | | | Merge branch '10.5' into bb-10.6-releaseOleksandr Byelkin2022-08-031-0/+2
| | |\ \ \ \ | | | |/ / /
| | | * | | Merge branch '10.4' into 10.5Oleksandr Byelkin2022-08-031-0/+2
| | | |\ \ \ | | | | |/ /
| | | | * | Merge branch '10.3' into 10.4Oleksandr Byelkin2022-08-021-0/+2
| | | | |\ \ | | | | | |/
| | | | | * MDEV-29188 Crash in JSON_EXTRACTOleksandr Byelkin2022-07-291-0/+4
| | | | | | | | | | | | | | | | | | | | | | | | If we have null_value set then decimal/string value/result shoud be 0 pointer.
* | | | | | Merge branch '10.8' into 10.9mariadb-10.9.1Sergei Golubchik2022-05-191-1/+11
|\ \ \ \ \ \ | |/ / / / /
| * | | | | Merge branch '10.6' into 10.7Sergei Golubchik2022-05-111-1/+11
| |\ \ \ \ \ | | |/ / / /
| | * | | | Merge branch '10.5' into 10.6Sergei Golubchik2022-05-101-1/+11
| | |\ \ \ \ | | | |/ / /
| | | * | | Merge branch '10.4' into 10.5Sergei Golubchik2022-05-091-1/+11
| | | |\ \ \ | | | | |/ /
| | | | * | MDEV-26402: A SEGV in Item_field::used_tables/update_depend_map_for_order...Sergei Petrunia2022-04-221-1/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When doing condition pushdown from HAVING into WHERE, Item_equal::create_pushable_equalities() calls item->set_extraction_flag(IMMUTABLE_FL) for constant items. Then, Item::cleanup_excluding_immutables_processor() checks for this flag to see if it should call item->cleanup() or leave the item as-is. The failure happens when a constant item has a non-constant one inside it, like: (tbl.col=0 AND impossible_cond) item->walk(cleanup_excluding_immutables_processor) works in a bottom-up way so it 1. will call Item_func_eq(tbl.col=0)->cleanup() 2. will not call Item_cond_and->cleanup (as the AND is constant) This creates an item tree where a fixed Item has an un-fixed Item inside it which eventually causes an assertion failure. Fixed by introducing this rule: instead of just calling item->set_extraction_flag(IMMUTABLE_FL); we call Item::walk() to set the flag for all sub-items of the item.
* | | | | | MDEV-23479: Add a THD* argument to Item_func_or_sum::fix_length_and_dec()Rucha Deodhar2022-03-301-26/+21
|/ / / / / | | | | | | | | | | | | | | | | | | | | Fix: Added THD *thd argument in Item_func_or_sum::fix_length_and_dec() and in fix_length_and_dec() for all derived classes of Item_func_or_sum.
* | | | | Merge 10.6 into 10.7Marko Mäkelä2022-03-301-3/+4
|\ \ \ \ \ | |/ / / /
| * | | | Merge 10.5 into 10.6Marko Mäkelä2022-03-291-3/+4
| |\ \ \ \ | | |/ / /
| | * | | Merge 10.4 into 10.5Marko Mäkelä2022-03-291-3/+4
| | |\ \ \ | | | |/ /
| | | * | Merge 10.3 into 10.4Marko Mäkelä2022-03-291-3/+4
| | | |\ \ | | | | |/
| | | | * MDEV-27937 Assertion failure when executing prepared statement with ? in IN listIgor Babaev2022-03-251-3/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This bug affected queries with IN predicates that contain parameter markers in the value list. Such queries are executed via prepared statements. The problem appeared only if the number of elements in the value list was greater than the set value of the system variable in_predicate_conversion_threshold. The patch unconditionally prohibits conversion of an IN predicate to the equivalent IN predicand if the value list of the IN predicate contains parameters markers. Approved by Oleksandr Byelkin <sanja@mariadb.com>
* | | | | Merge 10.6 into 10.7Marko Mäkelä2021-11-091-2/+2
|\ \ \ \ \ | |/ / / /
| * | | | Merge 10.5 into 10.6Marko Mäkelä2021-11-091-2/+2
| |\ \ \ \ | | |/ / /
| | * | | Merge 10.4 into 10.5Marko Mäkelä2021-11-091-2/+2
| | |\ \ \ | | | |/ /
| | | * | Merge 10.3 into 10.4Marko Mäkelä2021-11-091-2/+2
| | | |\ \ | | | | |/
| | | | * Merge 10.2 into 10.3Marko Mäkelä2021-11-091-2/+2
| | | | |\
| | | | | * MDEV-25610 Assertion `escape != -1' failed in Item_func_like::val_intbb-10.2-bar-MDEV-25610Alexander Barkov2021-11-081-2/+2
| | | | | |
* | | | | | Make marking/testing of top level item uniformMonty2021-07-191-22/+23
|/ / / / / | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There where several different implementations of is_top_level_item(), with different variable names and tests. In some cases the code used 'is_top_level_item()' as a test, in other cases it accessed the variable directrly. This patch makes all usage of 'top_level_item' uniform. The new implementation stores the 'is_tol_level_item()' flag as part of base_flags. This saves 7 bytes in all items that previously stored the flag in it's own bool. I had to keep 'top_level_item()' virtual to ensure that Item_bool_const item's will not be updated. 'is_top_level_item()' is not virtual anymore.
* | | | | Merge 10.5 into 10.6Marko Mäkelä2021-06-211-2/+5
|\ \ \ \ \ | |/ / / /