summaryrefslogtreecommitdiff
path: root/sql/item_create.h
diff options
context:
space:
mode:
authorAlexander Barkov <bar@mariadb.com>2022-04-04 14:50:21 +0400
committerAlexander Barkov <bar@mariadb.com>2023-04-25 12:53:46 +0400
commitcdafad0941f04437eaa0d6d2060e190990f84929 (patch)
treef9c88af9184a80d61a2bd0baaf7d8abc8a82a82d /sql/item_create.h
parent01199901d891c52689f1ca9e3fb7a3222b09d18f (diff)
downloadmariadb-git-bb-10.3-bar-MDEV-27744.tar.gz
MDEV-27744 InnoDB: Failing assertion: !cursor->index->is_committed() in row0ins.cc (from row_ins_sec_index_entry_by_modify) | Assertion `0' failed in row_upd_sec_index_entry (debug) | Corruptionbb-10.3-bar-MDEV-27744
The crash happened with an indexed virtual column whose value is evaluated using a function that has a different meaning in sql_mode='' vs sql_mode=ORACLE: - DECODE() - LTRIM() - RTRIM() - LPAD() - RPAD() - REPLACE() - SUBSTR() For example: CREATE TABLE t1 ( b VARCHAR(1), g CHAR(1) GENERATED ALWAYS AS (SUBSTR(b,0,0)) VIRTUAL, KEY g(g) ); So far we had replacement XXX_ORACLE() functions for all mentioned function, e.g. SUBSTR_ORACLE() for SUBSTR(). So it was possible to correctly re-parse SUBSTR_ORACLE() even in sql_mode=''. But it was not possible to re-parse the MariaDB version of SUBSTR() after switching to sql_mode=ORACLE. It was erroneously mis-interpreted as SUBSTR_ORACLE(). As a result, this combination worked fine: SET sql_mode=ORACLE; CREATE TABLE t1 ... g CHAR(1) GENERATED ALWAYS AS (SUBSTR(b,0,0)) VIRTUAL, ...; INSERT ... FLUSH TABLES; SET sql_mode=''; INSERT ... But the other way around it crashed: SET sql_mode=''; CREATE TABLE t1 ... g CHAR(1) GENERATED ALWAYS AS (SUBSTR(b,0,0)) VIRTUAL, ...; INSERT ... FLUSH TABLES; SET sql_mode=ORACLE; INSERT ... At CREATE time, SUBSTR was instantiated as Item_func_substr and printed in the FRM file as substr(). At re-open time with sql_mode=ORACLE, "substr()" was erroneously instantiated as Item_func_substr_oracle. Fix: The fix proposes a symmetric solution. It provides a way to re-parse reliably all sql_mode dependent functions to their original CREATE TABLE time meaning, no matter what the open-time sql_mode is. We take advantage of the same idea we previously used to resolve sql_mode dependent data types. Now all sql_mode dependent functions are printed by SHOW using a schema qualifier when the current sql_mode differs from the function sql_mode: SET sql_mode=''; CREATE TABLE t1 ... SUBSTR(a,b,c) ..; SET sql_mode=ORACLE; SHOW CREATE TABLE t1; -> mariadb_schema.substr(a,b,c) SET sql_mode=ORACLE; CREATE TABLE t2 ... SUBSTR(a,b,c) ..; SET sql_mode=''; SHOW CREATE TABLE t1; -> oracle_schema.substr(a,b,c) Old replacement names like substr_oracle() are still understood for backward compatibility and used in FRM files (for downgrade compatibility), but they are not printed by SHOW any more.
Diffstat (limited to 'sql/item_create.h')
-rw-r--r--sql/item_create.h53
1 files changed, 41 insertions, 12 deletions
diff --git a/sql/item_create.h b/sql/item_create.h
index 894e9777b8d..3fadaecb090 100644
--- a/sql/item_create.h
+++ b/sql/item_create.h
@@ -145,16 +145,6 @@ protected:
/**
- Find the native function builder associated with a given function name.
- @param thd The current thread
- @param name The native function name
- @return The native function builder associated with the name, or NULL
-*/
-extern Create_func *find_native_function_builder(THD *thd,
- const LEX_CSTRING *name);
-
-
-/**
Find the function builder for qualified functions.
@param thd The current thread
@return A function builder for qualified functions
@@ -215,9 +205,48 @@ struct Native_func_registry
Create_func *builder;
};
+
+class Native_functions_hash: public HASH
+{
+public:
+ Native_functions_hash()
+ {
+ bzero(this, sizeof(*this));
+ }
+ ~Native_functions_hash()
+ {
+ /*
+ No automatic free.
+ The the upper level code should call cleanup() explicitly.
+ */
+ DBUG_ASSERT(!records);
+ }
+ bool init(size_t count);
+ bool init(const Native_func_registry array[], size_t count)
+ {
+ return init(count) || append(array);
+ }
+ bool append(const Native_func_registry array[]);
+ bool remove(const Native_func_registry array[]);
+ void cleanup();
+ /**
+ Find the native function builder associated with a given function name.
+ @param thd The current thread
+ @param name The native function name
+ @return The native function builder associated with the name, or NULL
+ */
+ Create_func *find(THD *thd, const LEX_CSTRING &name) const;
+};
+
+extern Native_functions_hash native_functions_hash;
+extern Native_functions_hash native_functions_hash_oracle_overrides;
+
+extern const Native_func_registry func_array[];
+extern const size_t func_array_length;
+
int item_create_init();
-int item_create_append(Native_func_registry array[]);
-int item_create_remove(Native_func_registry array[]);
+int item_create_append(const Native_func_registry array[]);
+int item_create_remove(const Native_func_registry array[]);
void item_create_cleanup();
Item *create_func_dyncol_create(THD *thd, List<DYNCALL_CREATE_DEF> &list);