Tarantool development patches archive
 help / color / mirror / Atom feed
From: Hollow111 <hollow653@gmail.com>
To: korablev@tarantool.org
Cc: tarantool-patches@freelists.org
Subject: [tarantool-patches] Re: [PATCH 2/2] sql: statistics removal after dropping an index
Date: Thu, 12 Apr 2018 06:06:05 +0000	[thread overview]
Message-ID: <CAEi+_aoqivtQ3_stgy+1wsrzyBqSqzT70wNEA1zuSjW2e09Yig@mail.gmail.com> (raw)
In-Reply-To: <4E93854E-25F3-45F7-8590-5CD96991E365@tarantool.org>

[-- Attachment #1: Type: text/plain, Size: 5064 bytes --]

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\"=%Q",
-    zType, zName);
- sqlite3NestedParse(pParse, "DELETE FROM \"_sql_stat4\" WHERE \"%s\"=%Q",
-    zType, zName);
+ if (idx_name != NULL) {
+ sqlite3NestedParse(parse,
+ "DELETE FROM \"_sql_stat1\" WHERE (\"idx\"=%Q AND "
+ "\"tbl\"=%Q)",
+ idx_name, table_name);
+ sqlite3NestedParse(parse,
+ "DELETE FROM \"_sql_stat4\" WHERE (\"idx\"=%Q AND "
+ "\"tbl\"=%Q)",
+ idx_name, table_name);
+ } else {
+ sqlite3NestedParse(parse,
+ "DELETE FROM \"_sql_stat1\" WHERE \"tbl\"=%Q",
+ table_name);
+ sqlite3NestedParse(parse,
+                    "DELETE FROM \"_sql_stat4\" WHERE \"tbl\"=%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 = 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 = ++parse_context->nMem;
  int space_id_reg = ++parse_context->nMem;
  sqlite3VdbeAddOp2(v, OP_Integer, space_id, space_id_reg);

пн, 9 апр. 2018 г. в 15:16, n.pettik <korablev@tarantool.org>:

> 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’t see any point in renaming function:
> ’sql_clear_stat_spaces’ -> ’sql_clear_stat_tables’.
> I would even say that ‘spaces’ is more appropriate name,
> since stat tables in fact are Tarantool’s 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\"=%Q",
>> -    zType, zName);
>> - sqlite3NestedParse(pParse, "DELETE FROM \"_sql_stat4\" WHERE
>> \"%s\"=%Q",
>> -    zType, zName);
>> +    if (idx_name != NULL) {
>> +        sqlite3NestedParse(parse,
>> +                    "DELETE FROM \"_sql_stat1\" WHERE (\"idx\"=%Q AND "
>> +                    "\"tbl\"=%Q)",
>> +                    idx_name, table_name);
>> +        sqlite3NestedParse(parse,
>> +                    "DELETE FROM \"_sql_stat4\" WHERE (\"idx\"=%Q AND "
>> +                    "\"tbl\"=%Q)",
>> +                    idx_name, table_name);
>> +    } else {
>> +        sqlite3NestedParse(parse,
>> +                    "DELETE FROM \"_sql_stat1\" WHERE \"tbl\"=%Q",
>> +                    table_name);
>> +        sqlite3NestedParse(parse,
>> +                    "DELETE FROM \"_sql_stat4\" WHERE \"tbl\"=%Q",
>> +                    table_name);
>> +        }
>>  }
>>
>>
>>
>
>

[-- Attachment #2: Type: text/html, Size: 8920 bytes --]

  reply	other threads:[~2018-04-12  6:06 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-04-03 21:37 [tarantool-patches] " N.Tatunov
2018-04-04 14:06 ` [tarantool-patches] " n.pettik
2018-04-04 15:46   ` Hollow111
2018-04-04 16:11     ` n.pettik
2018-04-04 16:34       ` Hollow111
2018-04-05 18:01         ` n.pettik
     [not found]           ` <CAEi+_aq5oyeB0cbnxAXXjQqu=h+PCGaaZuLkk3p33yq371+Xog@mail.gmail.com>
2018-04-07  2:12             ` Hollow111
2018-04-09 12:16               ` n.pettik
2018-04-12  6:06                 ` Hollow111 [this message]
2018-04-13  8:50                   ` n.pettik
2018-04-14  4:29                     ` Hollow111
2018-04-14  8:13                       ` n.pettik
2018-04-15  6:09                         ` Hollow111
2018-04-15  6:35                           ` Hollow111
2018-04-15 22:41                             ` n.pettik
2018-04-16 13:19                               ` 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=CAEi+_aoqivtQ3_stgy+1wsrzyBqSqzT70wNEA1zuSjW2e09Yig@mail.gmail.com \
    --to=hollow653@gmail.com \
    --cc=korablev@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='[tarantool-patches] Re: [PATCH 2/2] sql: statistics removal after dropping an index' \
    /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