From 08a1ac9d35d8435d73c0c37d971563e6a0775bc5 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Sun, 16 Jun 2013 17:07:15 +0200 Subject: [PATCH] MDEV-4449 SEQUENCE depends on TEST_SQL_DISCOVERY for discovering tables upon DDL implement a non-dummy discover_table_existence() method --- .../mysql-test/sequence/simple.result | 1 + .../sequence/mysql-test/sequence/simple.test | 4 ++ storage/sequence/sequence.cc | 43 +++++++++++++------ 3 files changed, 35 insertions(+), 13 deletions(-) diff --git a/storage/sequence/mysql-test/sequence/simple.result b/storage/sequence/mysql-test/sequence/simple.result index 2d56e57d199..24619e47ce2 100644 --- a/storage/sequence/mysql-test/sequence/simple.result +++ b/storage/sequence/mysql-test/sequence/simple.result @@ -268,3 +268,4 @@ master-bin.000001 # Gtid # # BEGIN GTID #-#-# master-bin.000001 # Query # # use test; insert t1 select * from seq_1_to_10 master-bin.000001 # Xid # # COMMIT /* XID */ drop table t1; +drop table seq_1_to_1; diff --git a/storage/sequence/mysql-test/sequence/simple.test b/storage/sequence/mysql-test/sequence/simple.test index b16c954176e..040c91d1d77 100644 --- a/storage/sequence/mysql-test/sequence/simple.test +++ b/storage/sequence/mysql-test/sequence/simple.test @@ -91,3 +91,7 @@ let $binlog_limit= 10; --source include/show_binlog_events.inc drop table t1; +# +# MDEV-4449 SEQUENCE depends on TEST_SQL_DISCOVERY for discovering tables upon DDL +# +drop table seq_1_to_1; diff --git a/storage/sequence/sequence.cc b/storage/sequence/sequence.cc index 2349f7aae63..c92ef0b16e0 100644 --- a/storage/sequence/sequence.cc +++ b/storage/sequence/sequence.cc @@ -255,16 +255,26 @@ static handler *create_handler(handlerton *hton, TABLE_SHARE *table, return new (mem_root) ha_seq(hton, table); } + +static bool parse_table_name(const char *name, size_t name_length, + ulonglong *from, ulonglong *to, ulonglong *step) +{ + uint n1= 0, n2= 0; + *step= 1; + + // the table is discovered if its name matches the pattern of seq_1_to_10 or + // seq_1_to_10_step_3 + sscanf(name, "seq_%llu_to_%llu%n_step_%llu%n", + from, to, &n1, step, &n2); + return n1 != name_length && n2 != name_length; +} + + static int discover_table(handlerton *hton, THD *thd, TABLE_SHARE *share) { - // the table is discovered if it has the pattern of seq_1_to_10 or - // seq_1_to_10_step_3 - ulonglong from, to, step= 1; - uint n1= 0, n2= 0; - bool reverse; - sscanf(share->table_name.str, "seq_%llu_to_%llu%n_step_%llu%n", - &from, &to, &n1, &step, &n2); - if (n1 != share->table_name.length && n2 != share->table_name.length) + ulonglong from, to, step; + if (parse_table_name(share->table_name.str, share->table_name.length, + &from, &to, &step)) return HA_ERR_NO_SUCH_TABLE; if (step == 0) @@ -275,6 +285,7 @@ static int discover_table(handlerton *hton, THD *thd, TABLE_SHARE *share) if (res) return res; + bool reverse; if ((reverse = from > to)) { if (step > from - to) @@ -303,15 +314,21 @@ static int discover_table(handlerton *hton, THD *thd, TABLE_SHARE *share) } +static int discover_table_existence(handlerton *hton, const char *db, + const char *table_name) +{ + ulonglong from, to, step; + return !parse_table_name(table_name, strlen(table_name), &from, &to, &step); +} + static int dummy_ret_int() { return 0; } static int init(void *p) { - handlerton *hton = (handlerton *)p; - hton->create = create_handler; - hton->discover_table = discover_table; - hton->discover_table_existence = - (int (*)(handlerton *, const char *, const char *)) &dummy_ret_int; + handlerton *hton= (handlerton *)p; + hton->create= create_handler; + hton->discover_table= discover_table; + hton->discover_table_existence= discover_table_existence; hton->commit= hton->rollback= hton->prepare= (int (*)(handlerton *, THD *, bool)) &dummy_ret_int; hton->savepoint_set= hton->savepoint_rollback= hton->savepoint_release=