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 A580D2D4A2 for ; Thu, 12 Apr 2018 02:06:18 -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 Pa0ORUF-QlCu for ; Thu, 12 Apr 2018 02:06:18 -0400 (EDT) Received: from mail-lf0-f42.google.com (mail-lf0-f42.google.com [209.85.215.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 1A8D82D498 for ; Thu, 12 Apr 2018 02:06:17 -0400 (EDT) Received: by mail-lf0-f42.google.com with SMTP id b189-v6so5951284lfe.2 for ; Wed, 11 Apr 2018 23:06:17 -0700 (PDT) MIME-Version: 1.0 References: <1522791436-8221-1-git-send-email-hollow653@gmail.com> <926E041C-FCCB-46B0-B49B-21292CB70813@tarantool.org> <4E93854E-25F3-45F7-8590-5CD96991E365@tarantool.org> In-Reply-To: <4E93854E-25F3-45F7-8590-5CD96991E365@tarantool.org> From: Hollow111 Date: Thu, 12 Apr 2018 06:06:05 +0000 Message-ID: Subject: [tarantool-patches] Re: [PATCH 2/2] sql: statistics removal after dropping an index Content-Type: multipart/alternative; boundary="000000000000b0124f0569a08dcd" 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: korablev@tarantool.org Cc: tarantool-patches@freelists.org --000000000000b0124f0569a08dcd Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Hello. Here's the diff for the changes: diff --git a/src/box/sql/build.c b/src/box/sql/build.c index 92f3cb6..0287183 100644 --- a/src/box/sql/build.c +++ b/src/box/sql/build.c @@ -2129,18 +2129,32 @@ sqliteViewResetAll(sqlite3 * db) * Remove entries from the _sql_stat1 and _sql_stat4 * system spaces after a DROP INDEX or DROP TABLE command. * - * @param pParse Parsing context. - * @param zType Type of entry to be deleted: - * 'idx' or 'tbl' string literal. - * @param zName Name of index or table. + * @param parse The parsing context. + * @param table_name The table to be dropped or + * the table that contains index to be dropped. + * @param idx_name Index to be dropped. */ static void -sql_clear_stat_spaces(Parse * pParse, const char *zType, const char *zName= ) +sql_clear_stat_spaces(Parse *parse, const char *table_name, + const char *idx_name) { - sqlite3NestedParse(pParse, "DELETE FROM \"_sql_stat1\" WHERE \"%s\"=3D%Q"= , - zType, zName); - sqlite3NestedParse(pParse, "DELETE FROM \"_sql_stat4\" WHERE \"%s\"=3D%Q"= , - zType, zName); + if (idx_name !=3D NULL) { + sqlite3NestedParse(parse, + "DELETE FROM \"_sql_stat1\" WHERE (\"idx\"=3D%Q AND " + "\"tbl\"=3D%Q)", + idx_name, table_name); + sqlite3NestedParse(parse, + "DELETE FROM \"_sql_stat4\" WHERE (\"idx\"=3D%Q AND " + "\"tbl\"=3D%Q)", + idx_name, table_name); + } else { + sqlite3NestedParse(parse, + "DELETE FROM \"_sql_stat1\" WHERE \"tbl\"=3D%Q", + table_name); + sqlite3NestedParse(parse, + "DELETE FROM \"_sql_stat4\" WHERE \"tbl\"=3D%Q", + table_name); + } } /** @@ -2325,7 +2339,7 @@ sql_drop_table(struct Parse *parse_context, struct SrcList *table_name_list, * tuple with corresponding space_id from _space. */ - sql_clear_stat_spaces(parse_context, "tbl", space_name); + sql_clear_stat_spaces(parse_context, space_name, NULL); struct Table *tab =3D sqlite3HashFind(&db->pSchema->tblHash, space_name); sqlite3FkDropTable(parse_context, table_name_list, tab); sql_code_drop_table(parse_context, space, is_view); @@ -3328,7 +3342,7 @@ sql_drop_index(struct Parse *parse_context, struct SrcList *index_name_list, * But firstly, delete statistics since schema * changes after DDL. */ - sql_clear_stat_spaces(parse_context, "idx", index->def->name); + sql_clear_stat_spaces(parse_context, table_name, index->def->name); int record_reg =3D ++parse_context->nMem; int space_id_reg =3D ++parse_context->nMem; sqlite3VdbeAddOp2(v, OP_Integer, space_id, space_id_reg); =D0=BF=D0=BD, 9 =D0=B0=D0=BF=D1=80. 2018 =D0=B3. =D0=B2 15:16, n.pettik : > Hello. I have noticed that you are using 4 spaces as an indentation. > According to our codestyle, we use tab symbol, instead of spaces, > which is equal to 8 spaces. > > Also, I don=E2=80=99t see any point in renaming function: > =E2=80=99sql_clear_stat_spaces=E2=80=99 -> =E2=80=99sql_clear_stat_tables= =E2=80=99. > I would even say that =E2=80=98spaces=E2=80=99 is more appropriate name, > since stat tables in fact are Tarantool=E2=80=99s system spaces. > > diff --git a/src/box/sql/build.c b/src/box/sql/build.c >> index 92f3cb6..7ca4191 100644 >> --- a/src/box/sql/build.c >> +++ b/src/box/sql/build.c >> @@ -2128,19 +2128,33 @@ sqliteViewResetAll(sqlite3 * db) >> /** >> * Remove entries from the _sql_stat1 and _sql_stat4 >> * system spaces after a DROP INDEX or DROP TABLE command. >> - * >> - * @param pParse Parsing context. >> - * @param zType Type of entry to be deleted: >> - * 'idx' or 'tbl' string literal. >> - * @param zName Name of index or table. >> + * >> + * @param parse The parsing context. >> + * @param table_name The table to be dropped or >> + * the table that contains index to be dropped. >> + * @param idx_name Index to be dropped. >> */ >> static void >> -sql_clear_stat_spaces(Parse * pParse, const char *zType, const char >> *zName) >> +sql_clear_stat_tables(Parse *parse, const char *table_name, >> + const char *idx_name) >> { >> - sqlite3NestedParse(pParse, "DELETE FROM \"_sql_stat1\" WHERE >> \"%s\"=3D%Q", >> - zType, zName); >> - sqlite3NestedParse(pParse, "DELETE FROM \"_sql_stat4\" WHERE >> \"%s\"=3D%Q", >> - zType, zName); >> + if (idx_name !=3D NULL) { >> + sqlite3NestedParse(parse, >> + "DELETE FROM \"_sql_stat1\" WHERE (\"idx\"=3D%Q AND= " >> + "\"tbl\"=3D%Q)", >> + idx_name, table_name); >> + sqlite3NestedParse(parse, >> + "DELETE FROM \"_sql_stat4\" WHERE (\"idx\"=3D%Q AND= " >> + "\"tbl\"=3D%Q)", >> + idx_name, table_name); >> + } else { >> + sqlite3NestedParse(parse, >> + "DELETE FROM \"_sql_stat1\" WHERE \"tbl\"=3D%Q", >> + table_name); >> + sqlite3NestedParse(parse, >> + "DELETE FROM \"_sql_stat4\" WHERE \"tbl\"=3D%Q", >> + table_name); >> + } >> } >> >> >> > > --000000000000b0124f0569a08dcd Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Hello. Here's the diff for the changes:

di= ff --git a/src/box/sql/build.c b/src/box/sql/build.c
index 92f3cb= 6..0287183 100644
--- a/src/box/sql/build.c
+++ b/src/b= ox/sql/build.c
@@ -2129,18 +2129,32 @@ sqliteViewResetAll(sqlite3= * db)
=C2=A0 * Remove entries from the _sql_stat1 and _sql_stat4=
=C2=A0 * system spaces after a DROP INDEX or DROP TABLE command.=
=C2=A0 *
- * @param pParse Parsing context.
= - * @param zType Type of entry to be deleted:
- * 'idx' or 'tbl' string literal.
- * @param zName Name of index or table.
+ * @param parse= =C2=A0 =C2=A0 =C2=A0 The parsing context.
+ * @param table_name T= he table to be dropped or
+ *=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0the table that contains index to be dropp= ed.
+ * @param idx_name=C2=A0 =C2=A0Index to be dropped.
=C2=A0 */
=C2=A0static void
-sql_clear_stat_spaces(Pa= rse * pParse, const char *zType, const char *zName)
+sql_clear_st= at_spaces(Parse *parse, const char *table_name,
+ const char *idx_name)
=C2=A0{
- sqlite3NestedParse(pParse, "= ;DELETE FROM \"_sql_stat1\" WHERE \"%s\"=3D%Q",
- =C2=A0 =C2=A0zType, zNam= e);
- sqlite3NestedParse(p= Parse, "DELETE FROM \"_sql_stat4\" WHERE \"%s\"=3D= %Q",
- =C2=A0 =C2= =A0zType, zName);
+ if (id= x_name !=3D NULL) {
+ sqli= te3NestedParse(parse,
+ "DELETE FROM \"_sql_stat1\" WHERE (\"idx\"=3D%Q = AND "
+ "\&q= uot;tbl\"=3D%Q)",
+ = idx_name, table_name);
+ = sqlite3NestedParse(parse,
+ "DELETE FROM \"_sql_stat4\" WHERE (\"idx\= "=3D%Q AND "
+ "\"tbl\"=3D%Q)",
+ idx_name, table_name);
+ } else {
+ sqlite3NestedParse(parse,
+ = "DELETE FROM \"_sql_stat1\" WHERE \"tbl\&quo= t;=3D%Q",
+ table= _name);
+ sqlite3NestedPa= rse(parse,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 "DELETE FROM \"_sql_stat4\" WHERE \"t= bl\"=3D%Q",
+ table_name);
+ }
=C2=A0}
=C2=A0
=C2=A0/**
@@ -2325,7 +2= 339,7 @@ sql_drop_table(struct Parse *parse_context, struct SrcList *table_= name_list,
=C2=A0 *=C2=A0= =C2=A0 tuple with corresponding space_id from _space.
=C2=A0 */
=C2=A0
- sql_clear_stat_spaces(parse_context, "= ;tbl", space_name);
+ sql_clear_stat_spaces(parse_context, space_name, NULL);
=C2=A0 struct Table *tab =3D sqlite3HashFind= (&db->pSchema->tblHash, space_name);
=C2=A0 sqlite3FkDropTable(parse_context, table_name_l= ist, tab);
=C2=A0 sql_code= _drop_table(parse_context, space, is_view);
@@ -3328,7 +3342,7 @@= sql_drop_index(struct Parse *parse_context, struct SrcList *index_name_lis= t,
=C2=A0 * But firstly, = delete statistics since schema
=C2=A0 * changes after DDL.
=C2=A0 */
- sql_c= lear_stat_spaces(parse_context, "idx", index->def->name);
+ sql_clear_stat_spaces(par= se_context, table_name, index->def->name);
=C2=A0 int record_reg =3D ++parse_context->nMem;<= /div>
=C2=A0 int space_id_reg = =3D ++parse_context->nMem;
=C2=A0 sqlite3VdbeAddOp2(v, OP_Integer, space_id, space_id_reg);
<= br>
=D0=BF=D0=BD, 9 =D0=B0=D0=BF= =D1=80. 2018 =D0=B3. =D0=B2 15:16, n.pettik <korablev@tarantool.org>:
Hello. I have noticed tha= t you are using 4 spaces as an indentation.
According to our codestyle,= we use tab symbol, instead of spaces,
which is equal to 8 spaces= .

Also, I don=E2=80=99t see any point in renaming = function:
=E2=80=99sql_clear_stat_spaces=E2=80=99 -> =E2=80=99= sql_clear_stat_tables=E2=80=99.
I would even say that =E2=80=98sp= aces=E2=80=99 is more appropriate name,
since stat tables in fact= are Tarantool=E2=80=99s system spaces.

diff --git a/src= /box/sql/build.c b/src/box/sql/build.c
index 92f3cb6..7ca4191 100= 644
--- a/src/box/sql/build.c
+++ b/src/box/sql/build.c=
@@ -2128,19 +2128,33 @@ sqliteViewResetAll(sqlite3 * db)
=C2=A0/**
=C2=A0 * Remove entries from the _sql_stat1 and _sql= _stat4
=C2=A0 * system spaces after a DROP INDEX or DROP TABLE co= mmand.
- *
- * @param pParse Parsing context.
- * @param zType Type of entry to be deleted:
- * 'idx' or 'tbl' string liter= al.
- * @param zName Name of index or table.
+ *=C2=A0<= /div>
+ * @param parse=C2=A0 =C2=A0 =C2=A0 The parsing context.
+ * @param table_name The table to be dropped or
+ *=C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0the table that c= ontains index to be dropped.
+ * @param idx_name=C2=A0 =C2=A0Inde= x to be dropped.
=C2=A0 */
=C2=A0static void
= -sql_clear_stat_spaces(Parse * pParse, const char *zType, const char *zName= )
+sql_clear_stat_tables(Parse *parse, const char *table_name,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 const char *idx_name)
=C2=A0{
- sqlite3NestedParse(pParse, "DELETE F= ROM \"_sql_stat1\" WHERE \"%s\"=3D%Q",
-= =C2=A0 =C2=A0zType, zName);<= /div>
- sqlite3NestedParse(= pParse, "DELETE FROM \"_sql_stat4\" WHERE \"%s\"= =3D%Q",
- =C2= =A0 =C2=A0zType, zName);
+=C2=A0 =C2=A0 if (idx_name !=3D NULL) {=
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 sqlite3NestedParse(parse,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 &qu= ot;DELETE FROM \"_sql_stat1\" WHERE (\"idx\"=3D%Q AND &= quot;
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 = =C2=A0 =C2=A0 "\"tbl\"=3D%Q)",
+=C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 idx_name, table_na= me);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 sqlite3NestedParse(parse,
=
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0= "DELETE FROM \"_sql_stat4\" WHERE (\"idx\"=3D%Q A= ND "
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 "\"tbl\"=3D%Q)",
+=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 idx_name, ta= ble_name);
+=C2=A0 =C2=A0 } else {
+=C2=A0 =C2=A0 =C2= =A0 =C2=A0 sqlite3NestedParse(parse,
+=C2=A0 =C2=A0 =C2=A0 =C2=A0= =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "DELETE FROM \"_sql_st= at1\" WHERE \"tbl\"=3D%Q",
+=C2=A0 =C2=A0 =C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 table_name);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 sqlite3NestedParse(parse,
+=C2=A0 = =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 "DELETE= FROM \"_sql_stat4\" WHERE \"tbl\"=3D%Q",
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 ta= ble_name);
+=C2=A0 =C2=A0 =C2=A0 =C2=A0 }
=C2=A0}
=

=C2=A0

--000000000000b0124f0569a08dcd--