From 044339d37fba1eacbb0a6da539b17977c262e59c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Wed, 13 Dec 2017 12:55:37 +0200 Subject: [PATCH] Add missing detection of CREATE TABLE AS As MaxScale does not have the actual data returned by the SELECT SQL query done to create the table, CREATE TABLE AS cannot be supported. --- server/modules/routing/avrorouter/avro_file.c | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/server/modules/routing/avrorouter/avro_file.c b/server/modules/routing/avrorouter/avro_file.c index 71f54432a..73df4ef98 100644 --- a/server/modules/routing/avrorouter/avro_file.c +++ b/server/modules/routing/avrorouter/avro_file.c @@ -917,6 +917,27 @@ bool is_create_like_statement(const char* ptr, size_t len) return strcasestr(sql, " like ") || strcasestr(sql, "(like "); } +bool is_create_as_statement(const char* ptr, size_t len) +{ + int err = 0; + char sql[len + 1]; + memcpy(sql, ptr, len); + sql[len] = '\0'; + const char* pattern = + // Case-insensitive mode + "(?i)" + // Main CREATE TABLE part (the \s is for any whitespace) + "create\\stable\\s" + // Optional IF NOT EXISTS + "(if\\snot\\sexists\\s)?" + // The table name with optional database name, both enclosed in optional backticks + "(`?\\S+`?.)`?\\S+`?\\s" + // And finally the AS keyword + "as"; + + return mxs_pcre2_simple_match(pattern, sql, 0, &err) == MXS_PCRE2_MATCH; +} + /** * @brief Detection of table alteration statements * @param router Avro router instance @@ -1033,6 +1054,15 @@ void handle_query_event(AVRO_INSTANCE *router, REP_HEADER *hdr, int *pending_tra { created = table_create_copy(router, sql, len, db); } + else if (is_create_as_statement(sql, len)) + { + static bool warn_create_as = true; + if (warn_create_as) + { + MXS_WARNING("`CREATE TABLE AS` is not yet supported, ignoring events to this table: %.*s", len, sql); + warn_create_as = false; + } + } else { created = table_create_alloc(sql, len, db);