From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 0E70D29654 for ; Tue, 21 Aug 2018 16:38:49 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id UAxahLXwOKtg for ; Tue, 21 Aug 2018 16:38:48 -0400 (EDT) Received: from smtp40.i.mail.ru (smtp40.i.mail.ru [94.100.177.100]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 09A5229643 for ; Tue, 21 Aug 2018 16:38:47 -0400 (EDT) From: "n.pettik" Message-Id: <5C92CDEF-15F0-4394-970F-608B9B59F333@tarantool.org> Content-Type: multipart/alternative; boundary="Apple-Mail=_4C52911B-8A05-46F7-AF01-723B4205F772" Mime-Version: 1.0 (Mac OS X Mail 10.3 \(3273\)) Subject: [tarantool-patches] Re: [PATCH 1/2] sql: after table rename properly update indexes Date: Tue, 21 Aug 2018 23:38:39 +0300 In-Reply-To: <20180821122038.zlyjqxk5nzpj755l@tarantool.org> References: <8A23ACEC-DCAA-47A2-8311-F46D75C9F9C0@tarantool.org> <20180821122038.zlyjqxk5nzpj755l@tarantool.org> Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org Cc: Kirill Yukhin --Apple-Mail=_4C52911B-8A05-46F7-AF01-723B4205F772 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=us-ascii > diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c > index dc5146f..821c7a9 100644 > --- a/src/box/sql/vdbe.c > +++ b/src/box/sql/vdbe.c > @@ -4625,13 +4625,35 @@ case OP_RenameTable: { > db->init.busy = 1; > init.rc = SQLITE_OK; > sql_init_callback(&init, zNewTableName, space_id, 0, zSqlStmt); > - db->init.busy = 0; > rc = init.rc; > - if (rc) { > + if (rc != SQLITE_OK) { > sqlite3CommitInternalChanges(); > + db->init.busy = 0; > goto abort_due_to_error; > } > > + /* Space was altered, refetch the pointer. */ > + space = space_by_id(space_id); > + for (uint32_t i = 0; i < space->index_count; ++i) { > + struct index_def *def = space->index[i]->def; > + if (def->opts.sql == NULL) > + continue; > + char *sql_stmt; > + rc = sql_index_update_table_name(def, zNewTableName, &sql_stmt); Where do you free memory for sql_stmt? table_rename allocates new string using sqlite3DbMalloc AFAIK. > + if (rc != SQLITE_OK) rc != 0 (or better: if (sql_index_update_table_name() != 0)). > + goto abort_due_to_error; > + space = space_by_id(space_id); > + sql_init_callback(&init, zNewTableName, space_id, > + space->index[i]->def->iid, sql_stmt); > + rc = init.rc; > + if (rc != SQLITE_OK) { rc != 0 (or better: if (init.rc != 0) The rest seems to be ok. --Apple-Mail=_4C52911B-8A05-46F7-AF01-723B4205F772 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=us-ascii

diff --git a/src/box/sql/vdbe.c = b/src/box/sql/vdbe.c
index dc5146f..821c7a9 = 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -4625,13 +4625,35 @@ case OP_RenameTable: = {
= db->init.busy =3D 1;
init.rc =3D SQLITE_OK;
sql_init_callback(&init, = zNewTableName, space_id, 0, zSqlStmt);
- db->init.busy =3D 0;
rc =3D init.rc;
- = if (rc) {
+ if (rc !=3D SQLITE_OK) {
sqlite3CommitInternalChanges();
+ = db->init.busy =3D 0;
goto abort_due_to_error;
}

+ = /* Space was altered, refetch the pointer. = */
+ = space =3D space_by_id(space_id);
+ = for (uint32_t i =3D 0; i < = space->index_count; ++i) {
+ struct index_def *def =3D = space->index[i]->def;
+ if (def->opts.sql =3D=3D = NULL)
+ = continue;
+ char *sql_stmt;
+ = rc =3D sql_index_update_table_name(def, = zNewTableName, &sql_stmt);

Where do = you free memory for sql_stmt? table_rename allocates = new
string using sqlite3DbMalloc AFAIK.

+ if (rc !=3D SQLITE_OK)

rc !=3D 0 = (or better: if (sql_index_update_table_name() !=3D 0)).

+ = goto abort_due_to_error;
+ = space =3D = space_by_id(space_id);
+ sql_init_callback(&init, = zNewTableName, space_id,
+   space->index[i]->= def->iid, sql_stmt);
+ rc =3D init.rc;
+ = if (rc !=3D SQLITE_OK) {

rc !=3D 0 = (or better: if (init.rc !=3D 0)

The rest = seems to be ok.

= --Apple-Mail=_4C52911B-8A05-46F7-AF01-723B4205F772--