summaryrefslogtreecommitdiff
path: root/sql/item.cc
Commit message (Collapse)AuthorAgeFilesLines
* Merge remote-tracking branch '10.4' into 10.5Oleksandr Byelkin2023-03-311-6/+10
|\
| * MDEV-30706 Different results of selects from view and CTE with same definitionIgor Babaev2023-03-021-6/+10
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | MDEV-30668 Set function aggregated in outer select used in view definition This patch fixes two bugs concerning views whose specifications contain subqueries with set functions aggregated in outer selects. Due to the first bug those such views that have implicit grouping were considered as mergeable. This led to wrong result sets for selects from these views. Due to the second bug the aggregation select was determined incorrectly and this led to bogus error messages. The patch added several test cases for these two bugs and for four other duplicate bugs. The patch also enables view-protocol for many other test cases. Approved by Oleksandr Byelkin <sanja@mariadb.com>
| * Merge branch '10.3' into 10.4Oleksandr Byelkin2023-01-281-1/+1
| |\
* | \ Merge branch '10.4' into 10.5Oleksandr Byelkin2023-01-271-1/+1
|\ \ \
| * \ \ Merge branch '10.3' into 10.4Oleksandr Byelkin2023-01-261-1/+1
| |\ \ \ | | |/ / | |/| / | | |/
| | * MDEV-30081 Crash with splitting from constant mergeable derived tableIgor Babaev2023-01-241-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This bug manifested itself in very rare situations when splitting optimization was applied to a materialized derived table with group clause by key over a constant meargeable derived table that was in inner part of an outer join. In this case the used tables for the key to access the split table incorrectly was evaluated to a not empty table map. Approved by Oleksandr Byelkin <sanja@mariadb.com>
* | | cleanup: const_Item->real_item()Sergei Golubchik2023-01-171-1/+1
| | | | | | | | | | | | | | | allow real_item() to be called for const Item*, remove casts in the code
* | | Merge 10.4 into 10.5Marko Mäkelä2023-01-131-27/+75
|\ \ \ | |/ /
| * | MDEV-30345 DML does not find rows it is supposed toMonty2023-01-111-2/+2
| | | | | | | | | | | | | | | | | | This only happens with 'timestamp_column IN (select ...) The reason was a missing assignment in Item_cache_timestamp::cache_value()
| * | Merge branch '10.3' into 10.4Sergei Golubchik2023-01-101-17/+69
| |\ \ | | |/
| | * fixes for json.json_table and main.func_json in --psSergei Golubchik2023-01-021-1/+2
| | |
| | * MDEV-29988: Major performance regression with 10.6.11Dmitry Shulga2023-01-021-14/+66
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The idea is to put Item_direct_ref_to_item as a transparent and permanent wrapper before a string which require conversion. So that Item_direct_ref_to_item would be the only place where the pointer to the string item is stored, this pointer can be changed and restored during PS execution as needed. And if any permanent (subquery) optimization would need a pointer to the item, it'll use a pointer to the Item_direct_ref_to_item - which is a permanent item and won't go away.
| * | cleanupSergei Golubchik2023-01-091-3/+3
| | | | | | | | | | | | remove casts. uchar can store 1/0 as good as bool.
| * | cleanupSergei Golubchik2023-01-091-5/+1
| | | | | | | | | | | | | | | Helper class to swicth to relaxed checks during field copy. Temporarily.
* | | Merge 10.4 into 10.5Marko Mäkelä2022-12-131-7/+28
|\ \ \ | |/ /
| * | Merge 10.3 into 10.4Marko Mäkelä2022-12-131-1/+20
| |\ \ | | |/
| | * MDEV-28696 View created as "select b''; " references invalid table(s) or ↵Alexander Barkov2022-12-021-0/+19
| | | | | | | | | | | | column(s) or function(s) or definer/invoker of view lack rights to use them
* | | Merge 10.4 into 10.5Marko Mäkelä2022-10-251-0/+16
|\ \ \ | |/ /
| * | Merge 10.3 into 10.4Marko Mäkelä2022-10-251-0/+16
| |\ \ | | |/
| | * MDEV-16549 Server crashes in Item_field::fix_fields on query with view and ↵Oleksandr Byelkin2022-10-241-0/+14
| | | | | | | | | | | | | | | | | | | | | subquery, Assertion `context' failed, Assertion `field' failed Add one-table-resolve context for items created with an aim of switching to temporary table because then it can be cloned in push-down-condition.
| | * MDEV-29750 triggers can modify historySergei Golubchik2022-10-161-0/+2
| | | | | | | | | | | | | | | | | | should be the same behavior as for virtual columns: * a warning on every inserted row * silently ignored in a trigger
* | | Merge branch '10.4' into 10.5Sergei Golubchik2022-05-091-9/+33
|\ \ \ | |/ /
| * | 10.4 specific fixes for DEFAULT()Sergei Golubchik2022-05-091-0/+23
| | |
| * | Merge branch '10.3' into 10.4Sergei Golubchik2022-05-081-5/+8
| |\ \ | | |/
| | * Merge branch '10.2' into 10.3Sergei Golubchik2022-04-211-5/+8
| | |\
| | | * cleanup: remove Item_default_value::cached_fieldSergei Golubchik2022-04-141-5/+2
| | | |
| | | * MDEV-26061 MariaDB server crash at Field::set_defaultSergei Golubchik2022-04-141-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | * Item_default_value::fix_fields creates a copy of its argument's field. * Field::default_value is changed when its expression is prepared in unpack_vcol_info_from_frm() This means we must unpack any vcol expression that includes DEFAULT(x) strictly after unpacking x->default_value. To avoid building and solving this dependency graph on every table open, we update Item_default_value::field->default_value after all vcols are unpacked and fixed.
| * | | cleanup: (*order->item) -> itemSergei Golubchik2022-04-291-4/+2
| | | | | | | | | | | | | | | | and minor style fixes
* | | | Merge 10.4 into 10.5Marko Mäkelä2022-04-211-10/+2
|\ \ \ \ | |/ / /
| * | | Merge 10.3 into 10.4Marko Mäkelä2022-04-211-10/+2
| |\ \ \ | | |/ /
| | * | MDEV-24176 Server crashes after insert in the table with virtualAleksey Midenkov2022-04-181-10/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | column generated using date_format() and if() vcol_info->expr is allocated on expr_arena at parsing stage. Since expr item is allocated on expr_arena all its containee items must be allocated on expr_arena too. Otherwise fix_session_expr() will encounter prematurely freed item. When table is reopened from cache vcol_info contains stale expression. We refresh expression via TABLE::vcol_fix_exprs() but first we must prepare a proper context (Vcol_expr_context) which meets some requirements: 1. As noted above expr update must be done on expr_arena as there may be new items created. It was a bug in fix_session_expr_for_read() and was just not reproduced because of no second refix. Now refix is done for more cases so it does reproduce. Tests affected: vcol.binlog 2. Also name resolution context must be narrowed to the single table. Tested by: vcol.update main.default vcol.vcol_syntax gcol.gcol_bugfixes 3. sql_mode must be clean and not fail expr update. sql_mode such as MODE_NO_BACKSLASH_ESCAPES, MODE_NO_ZERO_IN_DATE, etc must not affect vcol expression update. If the table was created successfully any further evaluation must not fail. Tests affected: main.func_like Reviewed by: Sergei Golubchik <serg@mariadb.org>
| | * | MDEV-24176 PreparationsAleksey Midenkov2022-04-181-3/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 1. moved fix_vcol_exprs() call to open_table() mysql_alter_table() doesn't do lock_tables() so it cannot win from fix_vcol_exprs() from there. Tests affected: main.default_session 2. Vanilla cleanups and comments.
| | * | MDEV-28267 ASAN heap-use-after-free in Item_sp::func_name_cstringAlexander Barkov2022-04-091-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This crash happens on a combination of multiple conditions: - There is a thead#1 running an "ANALYZE FORMAT=JSON" query for a "SELECT .. FROM INFORMATION_SCHEMA.COLUMNS WHERE .. " - The WHERE clause contains a stored function call, say f1(). - The WHERE clause is built in the way so that the function f1() is never actually called, e.g. WHERE .. AND (TRUE OR f1()=expr) - The database contains multiple VIEWs that have the function f1() call, e.g. in their <select list> - The WHERE clause is built in the way so that these VIEWs match the condition. - There is a parallel thread#2 running. It creates or drops or recreates some other stored routine, say f2(), which is not used in the ANALYZE query. It effectively invalidates the stored routine cache for thread#1 without locking. Note, it is important that f2() is NOT used by ANALYZE query. Otherwise, thread#2 would be locked until the ANALYZE query finishes. When all of the above conditions are met, the following happens: 1. thread#1 starts the ANALYZE query. It notices a call for the stored function f1() in the WHERE condition. The function f1() gets parsed and cached to the SP cache. Its address also gets assigned to Item_func_sp::m_sp. 2. thread#1 starts iterating through all tables that match the WHERE condition to find the information about their columns. 3. thread#1 processes columns of the VIEW v1. It notices a call for f1() in the VIEW v1 definition. But f1() is already cached in the step#1 and it is up to date. So nothing happens with the SP cache. 4. thread#2 re-creates f2() in a non-locking mode. It effectively invalidates the SP cache in thread#1. 5. thread#1 processes columns of the VIEW v2. It notices a call for f1() in the VIEW v2 definition. It also notices that the cached version of f1() is not up to date. It frees the old definition of f1(), parses it again, and puts a new version of f1() to the SP cache. 6. thread#1 finishes processing rows and generates the JSON output. When printing the "attached_condition" value, it calls Item_func_sp::print() for f1(). But this Item_func_sp links to the old (freed) version of f1(). The above scenario demonstrates that Item_func_sp::m_sp can point to an alredy freed instance when Item_func_sp::func_name() is called, so accessing to Item_sp::m_sp->m_handler is not safe. This patch rewrites the code to use Item_func_sp::m_handler instead, which is always reliable. Note, this patch is only a cleanup for MDEV-28166 to quickly fix the regression. It fixes MDEV-28267. But it does not fix the core problem: The code behind I_S does not take into account that the SP cache can be updated while evaluating rows of the COLUMNS table. This is a corner case and it never happens with any other tables. I_S.COLUMNS is very special. Another example of the core problem is reported in MDEV-25243. The code accesses to Item_sp::m_sp->m_chistics of an already freed m_sp, again. It will be addressed separately.
* | | | Merge 10.4 into 10.5Marko Mäkelä2022-03-291-2/+18
|\ \ \ \ | |/ / /
| * | | Merge 10.3 into 10.4Marko Mäkelä2022-03-291-2/+18
| |\ \ \ | | |/ /
| | * | MDEV-28166 sql_mode=ORACLE: fully qualified package function calls do not ↵Alexander Barkov2022-03-251-2/+18
| | | | | | | | | | | | | | | | | | | | | | | | work: db.pkg.func() Also fixes MDEV-19328 sql_mode=ORACLE: Package function in VIEW
* | | | Merge branch '10.4' into 10.5Oleksandr Byelkin2022-02-011-70/+41
|\ \ \ \ | |/ / /
| * | | Merge branch '10.3' into 10.4Oleksandr Byelkin2022-01-301-70/+41
| |\ \ \ | | |/ /
| | * | Merge branch '10.2' into 10.3mariadb-10.3.33Oleksandr Byelkin2022-01-291-70/+41
| | |\ \ | | | |/
| | | * MDEV-25631 Crash executing query with VIEW, aggregate and subqueryIgor Babaev2022-01-101-0/+5
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This bug could cause a crash of the server for queries with a derived table whose specification contained the set function using a subquery over a view as its only argument. The crash could happen if the specification of the view contained an outer reference. In this case the aggregation select could be determined incorrectly. The crash also could be observed if a CTE is used instead of the view, but only for queries having at least two references to the CTE.
| | | * MDEV-25086 Stored Procedure Crashes ServerIgor Babaev2022-01-101-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The cause of this bug is the same as of the bug MDEV-24454. This bug manifested itself at the second execution of the queries that contained a set function whose only argument was outer reference to a column of a mergeable view or derived table or CTE. The first execution of such query worked fine, but the second execution of the query caused a crash of the server because the aggregation select for the used set function was determined incorrectly at the name resolution phase of the second execution.
| | | * Revert "MDEV-24454 Crash at change_item_tree"Igor Babaev2022-01-101-70/+34
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | This patch reverts the fixes of the bugs MDEV-24454 and MDEV-25631 from the commit 3690c549c6e72646ba74f6b4c83813ee4ac3aea4. It leaves the changes in plugin/feedback/feedback.cc and corresponding test files introduced in this commit intact. Proper fixes for the bug MDEV-24454 and MDEV-25631 will follow immediately.
| | | * MDEV-21639 DEFAULT(col) evaluates to a bad value in WHERE clausebb-10.2-bar-MDEV-21639Alexander Barkov2021-12-291-0/+42
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The problem happened because Item_default_value did not overload properly the val_xxx_result() family methods. This change backports the patch for: MDEV-24958 Server crashes in my_strtod / Value_source::Converter_strntod::Converter_strntod with DEFAULT(blob) which earlier fixed the problem in 10.3.
* | | | MDEV-27018 IF and COALESCE lose "json" propertybb-10.5-bar-MDEV-27018Alexander Barkov2022-01-211-11/+0
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Hybrid functions (IF, COALESCE, etc) did not preserve the JSON property from their arguments. The same problem was repeatable for single row subselects. The problem happened because the method Item::is_json_type() was inconsistently implemented across the Item hierarchy. For example, Item_hybrid_func and Item_singlerow_subselect did not override is_json_type(). Solution: - Removing Item::is_json_type() - Implementing specific JSON type handlers: Type_handler_string_json Type_handler_varchar_json Type_handler_tiny_blob_json Type_handler_blob_json Type_handler_medium_blob_json Type_handler_long_blob_json - Reusing the existing data type infrastructure to pass JSON type handlers across all item types, including classes Item_hybrid_func and Item_singlerow_subselect. Note, these two classes themselves do not need any changes! - Extending the data type infrastructure so data types can inherit their properties (e.g. aggregation rules) from their base data types. E.g. VARCHAR/JSON acts as VARCHAR, LONGTEXT/JSON acts as LONGTEXT when mixed to a non-JSON data type. This is done by: - adding virtual method Type_handler::type_handler_base() - adding a helper class Type_handler_pair - refactoring Type_handler_hybrid_field_type methods aggregate_for_result(), aggregate_for_min_max(), aggregate_for_num_op() to use Type_handler_pair. This change also fixes: MDEV-27361 Hybrid functions with JSON arguments do not send format metadata Also, adding mtr tests for JSON replication. It was not covered yet. And the current patch changes the replication code slightly.
* | | | Merge 10.4 into 10.5st-10.5-mergeMarko Mäkelä2021-10-271-20/+76
|\ \ \ \ | |/ / /
| * | | Merge remote-tracking branch 'origin/10.3' into 10.4Alexander Barkov2021-10-271-20/+76
| |\ \ \ | | |/ /
| | * | MDEV-22380: Assertion `name.length == strlen(name.str)' failed ...bb-10.3-bar-MDEV-22380Alexander Barkov2021-10-271-20/+76
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Also fixes: MDEV-25399 Assertion `name.length == strlen(name.str)' failed in Item_func_sp::make_send_field Also fixes a problem that in this scenario: SET NAMES binary; SELECT 'some not well-formed utf8 string'; the auto-generated column name copied the binary string value directly to the Item name, without checking utf8 well-formedness. After this change auto-generated column names work as follows: - Zero bytes 0x00 are copied to the name using HEX notation - In case of "SET NAMES binary", all bytes sequences that do not make well-formed utf8 characters are copied to the name using HEX notation.
* | | | Merge 10.4 into 10.5Marko Mäkelä2021-10-211-2/+42
|\ \ \ \ | |/ / /
| * | | Merge 10.3 into 10.4Marko Mäkelä2021-10-211-2/+42
| |\ \ \ | | |/ /
| | * | Merge 10.2 into 10.3Marko Mäkelä2021-10-211-2/+42
| | |\ \ | | | |/