From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
To: tarantool-patches@freelists.org, Nikita Pettik <korablev@tarantool.org>
Subject: [tarantool-patches] Re: [PATCH 2/6] sql: don't update SQL string during renaming
Date: Mon, 10 Dec 2018 17:16:15 +0300 [thread overview]
Message-ID: <02252f24-c2cb-d9f3-c327-48015855c1dc@tarantool.org> (raw)
In-Reply-To: <ce2335565a3da375bc342fa1b7fb0c78dc7a0064.1544387419.git.korablev@tarantool.org>
Thanks for the patch!
On 10/12/2018 00:30, Nikita Pettik wrote:
> Since SQL string containing "CREATE TABLE ..." statement is not used
> anymore for ordinary tables/space, it makes no sense to modify it during
> renaming. Hence, now rename routine needs only to update name in _space,
> so it can be done using simple update operation.
>
> Moreover, now we are able to rename spaces created from Lua-land.
>
> Part of #2647
> ---
> src/box/sql.c | 187 ++++++++------------------------------------
> src/box/sql/tarantoolInt.h | 3 +-
> src/box/sql/vdbe.c | 4 +-
> test/sql-tap/alter.test.lua | 32 +++++++-
> 4 files changed, 63 insertions(+), 163 deletions(-)
You forgot to remove some code and comments. My
review fixes here and on the branch.
========================================================
commit 3eeb01aa01766001fb313eaf26d539273100b71b
Author: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>
Date: Mon Dec 10 16:27:04 2018 +0300
Review fixes
diff --git a/src/box/sql/alter.c b/src/box/sql/alter.c
index 89e51eb30..d0ce9d893 100644
--- a/src/box/sql/alter.c
+++ b/src/box/sql/alter.c
@@ -77,78 +77,6 @@ tnt_error:
goto exit_rename_table;
}
-/*
- * This function implements part of the ALTER TABLE command.
- * The first argument is the text of a CREATE TABLE or CREATE INDEX command.
- * The second is a table name. The table name in the CREATE TABLE or
- * CREATE INDEX statement is replaced with the second argument and
- * the result returned. There is no need to deallocate returned memory, since
- * it will be doe automatically by VDBE. Note that new statement always
- * contains quoted new table name.
- *
- * Examples:
- *
- * sqlite_rename_table('CREATE TABLE abc(a, b, c)', 'def')
- * -> 'CREATE TABLE "def"(a, b, c)'
- *
- * sqlite_rename_table('CREATE INDEX i ON abc(a)', 'def')
- * -> 'CREATE INDEX i ON "def"(a, b, c)'
- *
- * @param sql_stmt text of a CREATE TABLE or CREATE INDEX statement
- * @param table_name new table name
- * @param[out] is_quoted true if statement to be modified contains quoted name
- *
- * @retval new SQL statement on success, NULL otherwise.
- */
-char*
-rename_table(sqlite3 *db, const char *sql_stmt, const char *table_name,
- bool *is_quoted)
-{
- assert(sql_stmt);
- assert(table_name);
- assert(is_quoted);
-
- int token;
- Token old_name;
- const char *csr = sql_stmt;
- int len = 0;
- char *new_sql_stmt;
- bool unused;
-
- /* The principle used to locate the table name in the CREATE TABLE
- * statement is that the table name is the first non-space token that
- * is immediately followed by a TK_LP or TK_USING token.
- */
- do {
- if (!*csr) {
- /* Ran out of input before finding a bracket. */
- return NULL;
- }
- /* Store the token that zCsr points to in tname. */
- old_name.z = (char *)csr;
- old_name.n = len;
- /* Advance zCsr to the next token.
- * Store that token type in 'token', and its length
- * in 'len' (to be used next iteration of this loop).
- */
- do {
- csr += len;
- len = sql_token(csr, &token, &unused);
- } while (token == TK_SPACE);
- assert(len > 0);
- } while (token != TK_LP && token != TK_USING);
-
- if (*old_name.z == '"')
- *is_quoted = true;
- /* No need to care about deallocating zRet, since its memory
- * will be automatically freed by VDBE.
- */
- new_sql_stmt = sqlite3MPrintf(db, "%.*s\"%w\"%s",
- (int)((old_name.z) - sql_stmt), sql_stmt,
- table_name, old_name.z + old_name.n);
- return new_sql_stmt;
-}
-
/* This function is used to implement the ALTER TABLE command.
* The table name in the CREATE TRIGGER statement is replaced with the third
* argument and the result returned. This is analagous to rename_table()
diff --git a/src/box/sql/sqliteInt.h b/src/box/sql/sqliteInt.h
index dbf58d967..85adcdb18 100644
--- a/src/box/sql/sqliteInt.h
+++ b/src/box/sql/sqliteInt.h
@@ -4462,7 +4462,6 @@ int sqlite3ResolveOrderGroupBy(Parse *, Select *, ExprList *, const char *);
void
sqlite3ColumnDefault(Vdbe *v, struct space_def *def, int i, int ireg);
-char* rename_table(sqlite3 *, const char *, const char *, bool *);
char* rename_trigger(sqlite3 *, char const *, char const *, bool *);
/**
* Find a collation by name. Set error in @a parser if not found.
diff --git a/src/box/sql/tarantoolInt.h b/src/box/sql/tarantoolInt.h
index e963132fe..0aa31bdd6 100644
--- a/src/box/sql/tarantoolInt.h
+++ b/src/box/sql/tarantoolInt.h
@@ -61,37 +61,15 @@ sql_delete_by_key(struct space *space, uint32_t iid, char *key,
int tarantoolSqlite3ClearTable(struct space *space, uint32_t *tuple_count);
/**
- * Rename the table in _space. Update tuple with corresponding id
- * with new name and statement fields and insert back. If sql_stmt
- * is NULL, then return from function after getting length of new
- * statement: it is the way how to dynamically allocate memory for
- * new statement in VDBE. So basically this function should be
- * called twice: firstly to get length of CREATE TABLE statement,
- * and secondly to make routine of replacing tuple and filling out
- * param sql_stmt with new CREATE TABLE statement.
- *
+ * Rename the table in _space.
* @param space_id Table's space identifier.
* @param new_name new name of table
*
- * @retval SQLITE_OK on success, SQLITE_TARANTOOL_ERROR otherwise.
+ * @retval 0 on success, SQL_TARANTOOL_ERROR otherwise.
*/
int
sql_rename_table(uint32_t space_id, const char *new_name);
-/**
- * Update CREATE INDEX field (def->opt.sql) replacing table name
- * w/ new one in _index space.
- *
- * @param idef Index definition.
- * @param new_tbl_name new name of table
- * @param[out] sql_stmt New CREATE INDEX statement.
- *
- * @retval 0 on success, -1 otherwise.
- */
-int
-sql_index_update_table_name(struct index_def *idef, const char *new_tbl_name,
- char **sql_stmt);
-
/* Alter trigger statement after rename table. */
int tarantoolSqlite3RenameTrigger(const char *zTriggerName,
const char *zOldName, const char *zNewName);
next prev parent reply other threads:[~2018-12-10 14:16 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-12-09 21:30 [tarantool-patches] [PATCH 0/6] Remove string of SQL statement from opts Nikita Pettik
2018-12-09 21:30 ` [tarantool-patches] [PATCH 1/6] sql: avoid calling sql_encode_table_opts() during trigger creation Nikita Pettik
2018-12-10 14:17 ` [tarantool-patches] " Vladislav Shpilevoy
2018-12-11 18:29 ` n.pettik
2018-12-09 21:30 ` [tarantool-patches] [PATCH 2/6] sql: don't update SQL string during renaming Nikita Pettik
2018-12-10 14:16 ` Vladislav Shpilevoy [this message]
2018-12-11 18:29 ` [tarantool-patches] " n.pettik
2018-12-12 12:36 ` Vladislav Shpilevoy
2018-12-13 12:42 ` n.pettik
2018-12-09 21:30 ` [tarantool-patches] [PATCH 3/6] test: fix sqltester methods to drop all tables/views Nikita Pettik
2018-12-10 14:16 ` [tarantool-patches] " Vladislav Shpilevoy
2018-12-11 18:29 ` n.pettik
2018-12-09 21:30 ` [tarantool-patches] [PATCH 4/6] sql: don't add string of 'CREATE TABLE...' to space opts Nikita Pettik
2018-12-10 14:17 ` [tarantool-patches] " Vladislav Shpilevoy
2018-12-11 18:29 ` n.pettik
2018-12-09 21:30 ` [tarantool-patches] [PATCH 5/6] sql: don't add string of 'CREATE INDEX ...' to index opts Nikita Pettik
2018-12-10 14:18 ` [tarantool-patches] " Vladislav Shpilevoy
2018-12-11 18:29 ` n.pettik
2018-12-09 21:30 ` [tarantool-patches] [PATCH 6/6] Remove SQL string from " Nikita Pettik
2018-12-25 13:45 ` [tarantool-patches] Re: [PATCH 0/6] Remove string of SQL statement from opts Kirill Yukhin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=02252f24-c2cb-d9f3-c327-48015855c1dc@tarantool.org \
--to=v.shpilevoy@tarantool.org \
--cc=korablev@tarantool.org \
--cc=tarantool-patches@freelists.org \
--subject='[tarantool-patches] Re: [PATCH 2/6] sql: don'\''t update SQL string during renaming' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox