diff options
author | Oleksandr Byelkin <sanja@mariadb.com> | 2022-11-02 16:07:38 +0100 |
---|---|---|
committer | Oleksandr Byelkin <sanja@mariadb.com> | 2022-11-02 16:07:38 +0100 |
commit | 33825755c76cd71cbd299d9daff0da75ca04bcf8 (patch) | |
tree | 333d70b9b64c0c6eb3eb861c0bfc3f87787c8f89 /storage/federatedx | |
parent | e0421b7cc8969edefca25c9a47e24f7e77c4bdf6 (diff) | |
parent | 15de3aa2f5b0fb5404a00f1a3cd5c0291f0ef67d (diff) | |
download | mariadb-git-33825755c76cd71cbd299d9daff0da75ca04bcf8.tar.gz |
Merge branch '10.7' into 10.8
Diffstat (limited to 'storage/federatedx')
-rw-r--r-- | storage/federatedx/CMakeLists.txt | 3 | ||||
-rw-r--r-- | storage/federatedx/federatedx_io_mysql.cc | 1 | ||||
-rw-r--r-- | storage/federatedx/federatedx_pushdown.cc | 87 | ||||
-rw-r--r-- | storage/federatedx/ha_federatedx.cc | 3 | ||||
-rw-r--r-- | storage/federatedx/ha_federatedx.h | 1 |
5 files changed, 85 insertions, 10 deletions
diff --git a/storage/federatedx/CMakeLists.txt b/storage/federatedx/CMakeLists.txt index 5f983b5d637..6a9b12ee362 100644 --- a/storage/federatedx/CMakeLists.txt +++ b/storage/federatedx/CMakeLists.txt @@ -1,2 +1,3 @@ SET(FEDERATEDX_SOURCES ha_federatedx.cc federatedx_txn.cc federatedx_io.cc federatedx_io_null.cc federatedx_io_mysql.cc) -MYSQL_ADD_PLUGIN(federatedx ${FEDERATEDX_SOURCES} STORAGE_ENGINE) +MYSQL_ADD_PLUGIN(federatedx ${FEDERATEDX_SOURCES} STORAGE_ENGINE + RECOMPILE_FOR_EMBEDDED) diff --git a/storage/federatedx/federatedx_io_mysql.cc b/storage/federatedx/federatedx_io_mysql.cc index 669a8faef63..fc32146b5cd 100644 --- a/storage/federatedx/federatedx_io_mysql.cc +++ b/storage/federatedx/federatedx_io_mysql.cc @@ -31,6 +31,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include <my_global.h> #include "sql_priv.h" #include <mysqld_error.h> +#include <mysql.h> #include "ha_federatedx.h" diff --git a/storage/federatedx/federatedx_pushdown.cc b/storage/federatedx/federatedx_pushdown.cc index 664f0570238..0d58e0d8270 100644 --- a/storage/federatedx/federatedx_pushdown.cc +++ b/storage/federatedx/federatedx_pushdown.cc @@ -35,6 +35,64 @@ */ +/* + Check if table and database names are equal on local and remote servers + + SYNOPSIS + local_and_remote_names_match() + tbl_share Pointer to current table TABLE_SHARE structure + fshare Pointer to current table FEDERATEDX_SHARE structure + + DESCRIPTION + FederatedX table on the local server may refer to a table having another + name on the remote server. The remote table may even reside in a different + database. For example: + + -- Remote server + CREATE TABLE t1 (id int(32)); + + -- Local server + CREATE TABLE t2 ENGINE="FEDERATEDX" + CONNECTION="mysql://joe:joespass@192.168.1.111:9308/federatedx/t1"; + + It's not a problem while the federated_pushdown is disabled 'cause + the CONNECTION strings are being parsed for every table during + the execution, so the table names are translated from local to remote. + But in case of the federated_pushdown the whole query is pushed down + to the engine without any translation, so the remote server may try + to select data from a nonexistent table (for example, query + "SELECT * FROM t2" will try to retrieve data from nonexistent "t2"). + + This function checks whether there is a mismatch between local and remote + table/database names + + RETURN VALUE + false names are equal + true names are not equal + +*/ +bool local_and_remote_names_mismatch(const TABLE_SHARE *tbl_share, + const FEDERATEDX_SHARE *fshare) +{ + + if (lower_case_table_names) + { + if (strcasecmp(fshare->database, tbl_share->db.str) != 0) + return true; + } + else + { + if (strncmp(fshare->database, tbl_share->db.str, tbl_share->db.length) != 0) + return true; + } + + return my_strnncoll(system_charset_info, (uchar *) fshare->table_name, + strlen(fshare->table_name), + (uchar *) tbl_share->table_name.str, + tbl_share->table_name.length) != 0; +} + + static derived_handler* create_federatedx_derived_handler(THD* thd, TABLE_LIST *derived) { @@ -42,7 +100,6 @@ create_federatedx_derived_handler(THD* thd, TABLE_LIST *derived) return 0; ha_federatedx_derived_handler* handler = NULL; - handlerton *ht= 0; SELECT_LEX_UNIT *unit= derived->derived; @@ -54,9 +111,16 @@ create_federatedx_derived_handler(THD* thd, TABLE_LIST *derived) { if (!tbl->table) return 0; - if (!ht) - ht= tbl->table->file->partition_ht(); - else if (ht != tbl->table->file->partition_ht()) + /* + We intentionally don't support partitioned federatedx tables here, so + use file->ht and not file->partition_ht(). + */ + if (tbl->table->file->ht != federatedx_hton) + return 0; + + const FEDERATEDX_SHARE *fshare= + ((ha_federatedx*)tbl->table->file)->get_federatedx_share(); + if (local_and_remote_names_mismatch(tbl->table->s, fshare)) return 0; } } @@ -170,15 +234,22 @@ create_federatedx_select_handler(THD* thd, SELECT_LEX *sel) return 0; ha_federatedx_select_handler* handler = NULL; - handlerton *ht= 0; for (TABLE_LIST *tbl= thd->lex->query_tables; tbl; tbl= tbl->next_global) { if (!tbl->table) return 0; - if (!ht) - ht= tbl->table->file->partition_ht(); - else if (ht != tbl->table->file->partition_ht()) + /* + We intentionally don't support partitioned federatedx tables here, so + use file->ht and not file->partition_ht(). + */ + if (tbl->table->file->ht != federatedx_hton) + return 0; + + const FEDERATEDX_SHARE *fshare= + ((ha_federatedx*)tbl->table->file)->get_federatedx_share(); + + if (local_and_remote_names_mismatch(tbl->table->s, fshare)) return 0; } diff --git a/storage/federatedx/ha_federatedx.cc b/storage/federatedx/ha_federatedx.cc index 62c48ed19d8..6199504e04f 100644 --- a/storage/federatedx/ha_federatedx.cc +++ b/storage/federatedx/ha_federatedx.cc @@ -315,6 +315,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #define MYSQL_SERVER 1 #include <my_global.h> #include <mysql/plugin.h> +#include <mysql.h> #include "ha_federatedx.h" #include "sql_servers.h" #include "sql_analyse.h" // append_escaped() @@ -610,7 +611,7 @@ error: parse_url() mem_root MEM_ROOT pointer for memory allocation share pointer to FEDERATEDX share - table pointer to current TABLE class + table_s pointer to current TABLE_SHARE class table_create_flag determines what error to throw DESCRIPTION diff --git a/storage/federatedx/ha_federatedx.h b/storage/federatedx/ha_federatedx.h index a382f9367f9..3eb7a9c662c 100644 --- a/storage/federatedx/ha_federatedx.h +++ b/storage/federatedx/ha_federatedx.h @@ -463,6 +463,7 @@ public: int reset(void); int free_result(void); + const FEDERATEDX_SHARE *get_federatedx_share() const { return share; } friend class ha_federatedx_derived_handler; friend class ha_federatedx_select_handler; }; |