Tarantool development patches archive
 help / color / mirror / Atom feed
From: Imeev Mergen <imeevma@tarantool.org>
To: Vladislav Shpilevoy <v.shpilevoy@tarantool.org>,
	tarantool-patches@freelists.org,
	"n.pettik" <korablev@tarantool.org>
Subject: [tarantool-patches] Re: [PATCH v2 1/1] sql: hold in stat tables space/index id instead of name
Date: Sat, 8 Dec 2018 15:39:56 +0300	[thread overview]
Message-ID: <84edbcf1-5a59-d449-70f2-6a93a9a1c11c@tarantool.org> (raw)
In-Reply-To: <2b509f61-9145-c1fa-4e1d-a734f615479e@tarantool.org>

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

Hi! Thank you for review! New version and my answers below.

On 11/19/18 1:27 PM, Vladislav Shpilevoy wrote:
> Hi! Thanks for the rebase! See 4 comments below.
>
>> commit b9792dfc183d7d0851f3492c8ba9e2f7c46fe385
>> Author: Mergen Imeev <imeevma@gmail.com>
>> Date:   Fri Aug 31 12:37:48 2018 +0300
>>
>>      sql: hold in stat tables space/index id instead of name
>>
>>      To avoid problems with table and index renaming it is good idea
>>      to save ids of tables and indexes instead of their names. Ids of
>>      tables and indexes are fixed values.
>>
>>      Closes #3242
>>      Closes #2962
>>
>> diff --git a/src/box/bootstrap.snap b/src/box/bootstrap.snap
>> index b7789d6..538e635 100644
>> Binary files a/src/box/bootstrap.snap and b/src/box/bootstrap.snap 
>> differ
>> diff --git a/src/box/lua/upgrade.lua b/src/box/lua/upgrade.lua
>> index 3d9acc9..3ce586b 100644
>> --- a/src/box/lua/upgrade.lua
>> +++ b/src/box/lua/upgrade.lua
>> @@ -550,11 +550,11 @@ local function upgrade_to_2_1_0()
>>       _index:insert{_trigger.id, 1, 'space_id', 'tree', { unique = 
>> false },
>>                     {{1, 'unsigned'}}}
>>
>> -    local stat1_ft = {{name='tbl', type='string'},
>> -                      {name='idx', type='string'},
>> +    local stat1_ft = {{name='space_id', type='unsigned'},
>> +                      {name='index_id', type='unsigned'},
>>                         {name='stat', type='string'}}
>> -    local stat4_ft = {{name='tbl', type='string'},
>> -                      {name='idx', type='string'},
>> +    local stat4_ft = {{name='space_id', type='unsigned'},
>> +                      {name='index_id', type='unsigned'},
>>                         {name='neq', type='string'},
>>                         {name='nlt', type='string'},
>>                         {name='ndlt', type='string'}
>
> 1. Unfortunately, as I said earlier, you can not change the
> past. 2.1.0 is already released, so you should create upgrade_to_2_2_0()
> function and here update stat spaces format.
Done.
>
>> diff --git a/src/box/sql/analyze.c b/src/box/sql/analyze.c
>> index e786c90..aa5d349 100644
>> --- a/src/box/sql/analyze.c
>> +++ b/src/box/sql/analyze.c
>> @@ -800,13 +800,13 @@ vdbe_emit_analyze_space(struct Parse *parse, 
>> struct space *space)
>>       assert(space->index_count != 0);
>>       struct Vdbe *v = sqlite3GetVdbe(parse);
>>       assert(v != NULL);
>> -    const char *tab_name = space_name(space);
>> +    MAYBE_UNUSED const char *tab_name = space_name(space);
>
> 2. Why unused?
It is used only in VdbeComment, so it will not be used in
RelWithDebInfoWError build.
>
>>       sqlite3VdbeAddOp4(v, OP_IteratorOpen, tab_cursor, 0, 0, (void 
>> *) space,
>>                 P4_SPACEPTR);
>> -    sqlite3VdbeLoadString(v, tab_name_reg, space->def->name);
>> +    sqlite3VdbeAddOp2(v, OP_Integer, space->def->id, space_id_reg);
>>       for (uint32_t j = 0; j < space->index_count; ++j) {
>>           struct index *idx = space->index[j];
>> -        const char *idx_name;
>> +        MAYBE_UNUSED const char *idx_name;
>
> 3. Why?
Same as previous.
>
>>           /*
>>            * Primary indexes feature automatically generated
>>            * names. Thus, for the sake of clarity, use
>> @@ -1225,23 +1224,14 @@ analysis_loader(void *data, int argc, char 
>> **argv, char **unused)
>>       struct analysis_index_info *info = (struct analysis_index_info 
>> *) data;
>>       assert(info->stats != NULL);
>>       struct index_stat *stat = &info->stats[info->index_count++];
>> -    struct space *space = space_by_name(argv[0]);
>> -    if (space == NULL)
>> +    uint32_t space_id = atoll(argv[0]);
>> +    if (space_id == 0)
>>           return -1;
>> +    struct space *space = space_by_id(space_id);
>> +    assert(space != NULL);
>>       struct index *index;
>> -    uint32_t iid = box_index_id_by_name(space->def->id, argv[1],
>> -                        strlen(argv[1]));
>> -    /*
>> -     * Convention is if index's name matches with space's
>> -     * one, then it is primary index.
>> -     */
>> -    if (iid != BOX_ID_NIL) {
>> -        index = space_index(space, iid);
>> -    } else {
>> -        if (sqlite3_stricmp(argv[0], argv[1]) != 0)
>> -            return -1;
>> -        index = space_index(space, 0);
>> -    }
>> +    uint32_t iid = atoll(argv[1]);
>> +    index = space_index(space, iid);
>
> 4.1. Why in some places d oyou check result of
> atoll and sqlite3_column_int, but in others do not?
Fixed. Added all checks.
>
>>       assert(index != NULL);
>>       /*
>>        * Additional field is used to describe total
>> @@ -1387,24 +1381,14 @@ load_stat_from_space(struct sqlite3 *db, 
>> const char *sql_select_prepare,
>>           goto finalize;
>>       uint32_t current_idx_count = 0;
>>       while (sqlite3_step(stmt) == SQLITE_ROW) {
>> -        const char *space_name = (char *)sqlite3_column_text(stmt, 0);
>> -        if (space_name == NULL)
>> -            continue;
>> -        const char *index_name = (char *)sqlite3_column_text(stmt, 1);
>> -        if (index_name == NULL)
>> -            continue;
>> -        uint32_t sample_count = sqlite3_column_int(stmt, 2);
>> -        struct space *space = space_by_name(space_name);
>> +        uint32_t space_id = sqlite3_column_int(stmt, 0);
>> +        assert(space_id != 0);
>> +        struct space *space = space_by_id(space_id);
>
> 4.2. Here you do not check, but ...
Fixed.
>
>>           assert(space != NULL);
>> -        struct index *index;
>> @@ -1537,24 +1509,13 @@ load_stat_to_index(struct sqlite3 *db, const 
>> char *sql_select_load,
>>           return -1;
>>       uint32_t current_idx_count = 0;
>>       while (sqlite3_step(stmt) == SQLITE_ROW) {
>> -        const char *space_name = (char *)sqlite3_column_text(stmt, 0);
>> -        if (space_name == NULL)
>> -            continue;
>> -        const char *index_name = (char *)sqlite3_column_text(stmt, 1);
>> -        if (index_name == NULL)
>> -            continue;
>> -        struct space *space = space_by_name(space_name);
>> +        uint32_t space_id = sqlite3_column_int(stmt, 0);
>> +        if (space_id == 0)
>> +            return -1;
>
> 4.3. ... here you check again.
Fixed.
>
>> +        struct space *space = space_by_id(space_id);
>>           assert(space != NULL);
>> -        struct index *index;
>> -        uint32_t iid = box_index_id_by_name(space->def->id, index_name,
>> -                            strlen(index_name));
>> -        if (iid != BOX_ID_NIL) {
>> -            index = space_index(space, iid);
>> -        } else {
>> -            if (sqlite3_stricmp(space_name, index_name) != 0)
>> -                return -1;
>> -            index = space_index(space, 0);
>> -        }
>> +        uint32_t iid = sqlite3_column_int(stmt, 1);
>
> 4.4. And here you don't ...
Fixed.
>
>> +        struct index *index = space_index(space, iid);
>>           assert(index != NULL);
>>           free(index->def->opts.stat);
>>           index->def->opts.stat = stats[current_idx_count++];


*New version:*

commit 5e1eb513b33ee8ab31901e8e0bf8d8f5a9442b9f
Author: Mergen Imeev <imeevma@gmail.com>
Date:   Sun Dec 2 17:57:19 2018 +0300

     sql: hold in stat tables space/index id instead of name

     To avoid problems with table and index renaming it is good idea
     to save ids of tables and indexes instead of their names. Ids of
     tables and indexes are fixed values.

     Closes #3242
     Closes #2962

diff --git a/src/box/bootstrap.snap b/src/box/bootstrap.snap
index d6cc821..22208c6 100644
Binary files a/src/box/bootstrap.snap and b/src/box/bootstrap.snap differ
diff --git a/src/box/lua/upgrade.lua b/src/box/lua/upgrade.lua
index 3d9acc9..2767f9b 100644
--- a/src/box/lua/upgrade.lua
+++ b/src/box/lua/upgrade.lua
@@ -613,6 +613,31 @@ local function upgrade_to_2_1_0()
      upgrade_priv_to_2_1_0()
  end

+--------------------------------------------------------------------------------
+-- Tarantool 2.1.1
+--------------------------------------------------------------------------------
+
+local function upgrade_sql_stat_to_2_1_1(space_id, parts)
+    local _sql_stat = box.space[space_id]
+
+    local stats = _sql_stat:select()
+    for _, v in pairs(stats) do _sql_stat:delete{v.tbl, v.idx} end
+
+    local format = _sql_stat:format()
+    format[1].name = 'space_id'
+    format[1].type = 'unsigned'
+    format[2].name = 'index_id'
+    format[2].type = 'unsigned'
+    _sql_stat.index.primary:alter{parts={3, 'string'}}
+    _sql_stat:format(format)
+    _sql_stat.index.primary:alter{parts=parts}
+end
+
+local function upgrade_to_2_1_1()
+    upgrade_sql_stat_to_2_1_1(box.schema.SQL_STAT1_ID, {1, 'unsigned', 
2, 'unsigned'})
+    upgrade_sql_stat_to_2_1_1(box.schema.SQL_STAT4_ID, {1, 'unsigned', 
2, 'unsigned', 6, 'scalar'})
+end
+
  local function get_version()
      local version = box.space._schema:get{'version'}
      if version == nil then
@@ -640,7 +665,8 @@ local function upgrade(options)
          {version = mkversion(1, 7, 7), func = upgrade_to_1_7_7, auto = 
true},
          {version = mkversion(1, 10, 0), func = upgrade_to_1_10_0, auto 
= true},
          {version = mkversion(1, 10, 2), func = upgrade_to_1_10_2, auto 
= true},
-        {version = mkversion(2, 1, 0), func = upgrade_to_2_1_0, auto = 
true}
+        {version = mkversion(2, 1, 0), func = upgrade_to_2_1_0, auto = 
true},
+        {version = mkversion(2, 1, 1), func = upgrade_to_2_1_1, auto = 
true}
      }

      for _, handler in ipairs(handlers) do
diff --git a/src/box/schema.cc b/src/box/schema.cc
index 8625d92..844b6c3 100644
--- a/src/box/schema.cc
+++ b/src/box/schema.cc
@@ -444,21 +444,19 @@ schema_init()
      sc_space_new(BOX_INDEX_ID, "_index", key_parts, 2,
               &alter_space_on_replace_index, &on_stmt_begin_index);

-    /* _sql_stat1 - a simpler statistics on space, seen in SQL. */
-    key_parts[0].fieldno = 0; /* space name */
+    /*
+     *_sql_stat1 - a simpler statistics on space, seen in SQL.
+     * The real index is defined in the snapshot.
+     */
+    key_parts[0].fieldno = 2;
      key_parts[0].type = FIELD_TYPE_STRING;
-    key_parts[1].fieldno = 1; /* index name */
-    key_parts[1].type = FIELD_TYPE_STRING;
-    sc_space_new(BOX_SQL_STAT1_ID, "_sql_stat1", key_parts, 2, NULL, NULL);
+    sc_space_new(BOX_SQL_STAT1_ID, "_sql_stat1", key_parts, 1, NULL, NULL);

-    /* _sql_stat4 - extensive statistics on space, seen in SQL. */
-    key_parts[0].fieldno = 0; /* space name */
-    key_parts[0].type = FIELD_TYPE_STRING;
-    key_parts[1].fieldno = 1; /* index name */
-    key_parts[1].type = FIELD_TYPE_STRING;
-    key_parts[2].fieldno = 5; /* sample */
-    key_parts[2].type = FIELD_TYPE_SCALAR;
-    sc_space_new(BOX_SQL_STAT4_ID, "_sql_stat4", key_parts, 3, NULL, NULL);
+    /*
+     * _sql_stat4 - extensive statistics on space, seen in SQL.
+     * The real index is defined in the snapshot.
+     */
+    sc_space_new(BOX_SQL_STAT4_ID, "_sql_stat4", key_parts, 1, NULL, NULL);

      /* _fk_сonstraint - foreign keys constraints. */
      key_parts[0].fieldno = 0; /* constraint name */
diff --git a/src/box/sql/analyze.c b/src/box/sql/analyze.c
index 3f49280..426fe73 100644
--- a/src/box/sql/analyze.c
+++ b/src/box/sql/analyze.c
@@ -38,8 +38,8 @@
   *
   * The following system tables are or have been supported:
   *
- *    CREATE TABLE _sql_stat1(tbl, idx, stat);
- *    CREATE TABLE _sql_stat4(tbl, idx, nEq, nLt, nDLt, sample);
+ *    CREATE TABLE _sql_stat1(space_id, index_id, stat);
+ *    CREATE TABLE _sql_stat4(space_id, index_id, nEq, nLt, nDLt, sample);
   *
   * For most applications, _sql_stat1 provides all the statistics required
   * for the query planner to make good choices.
@@ -47,7 +47,7 @@
   * Format of _sql_stat1:
   *
   * There is normally one row per index, with the index identified by the
- * name in the idx column.  The tbl column is the name of the table to
+ * id in the index_id column.  The space_id column is the id of the 
space to
   * which the index belongs.  In each such row, the stat column will be
   * a string consisting of a list of integers.  The first integer in this
   * list is the number of rows in the index.  (This is the same as the
@@ -66,9 +66,9 @@
   * "unordered" keyword is present, then the query planner assumes that
   * the index is unordered and will not use the index for a range query.
   *
- * If the _sql_stat1.idx column is NULL, then the _sql_stat1.stat
+ * If the _sql_stat1.index_id column is NULL, then the _sql_stat1.stat
   * column contains a single integer which is the (estimated) number of
- * rows in the table identified by _sql_stat1.tbl.
+ * rows in the table identified by _sql_stat1.space_id.
   *
   * Format for _sql_stat4:
   *
@@ -78,9 +78,9 @@
   * queries.
   *
   * The _sql_stat4 table contains multiple entries for each index.
- * The idx column names the index and the tbl column is the table of the
- * index.  If the idx and tbl columns are the same, then the sample is
- * of the INTEGER PRIMARY KEY.  The sample column is a blob which is the
+ * The index_id column names the index and the space_id column is the 
space of
+ * the index. If the index_id is equal to 0, then the sample
+ * is of the INTEGER PRIMARY KEY.  The sample column is a blob which is the
   * binary encoding of a key from the index.  The nEq column is a
   * list of integers.  The first integer is the approximate number
   * of entries in the index whose left-most column exactly matches
@@ -122,10 +122,11 @@
   * created.
   *
   * @param parse Parsing context.
- * @param table_name Delete records of this table if specified.
+ * @param space_id Delete records of this table if id is not
+ *        BOX_ID_NIL.
   */
  static void
-vdbe_emit_stat_space_open(struct Parse *parse, const char *table_name)
+vdbe_emit_stat_space_open(struct Parse *parse, uint32_t space_id)
  {
      const char *stat_names[] = {"_sql_stat1", "_sql_stat4"};
      const uint32_t stat_ids[] = {BOX_SQL_STAT1_ID, BOX_SQL_STAT4_ID};
@@ -133,10 +134,9 @@ vdbe_emit_stat_space_open(struct Parse *parse, 
const char *table_name)
      assert(v != NULL);
      assert(sqlite3VdbeDb(v) == parse->db);
      for (uint i = 0; i < lengthof(stat_names); ++i) {
-        const char *space_name = stat_names[i];
-        if (table_name != NULL) {
-            vdbe_emit_stat_space_clear(parse, space_name, NULL,
-                           table_name);
+        if (space_id != BOX_ID_NIL) {
+            vdbe_emit_stat_space_clear(parse, stat_names[i],
+                           space_id, BOX_ID_NIL);
          } else {
              sqlite3VdbeAddOp1(v, OP_Clear, stat_ids[i]);
          }
@@ -780,10 +780,10 @@ vdbe_emit_analyze_space(struct Parse *parse, 
struct space *space)
      int key_reg = ++parse->nMem;
      /* Temporary use register. */
      int tmp_reg = ++parse->nMem;
-    /* Register containing table name. */
-    int tab_name_reg = ++parse->nMem;
-    /* Register containing index name. */
-    int idx_name_reg = ++parse->nMem;
+    /* Register containing space id. */
+    int space_id_reg = ++parse->nMem;
+    /* Register containing index id. */
+    int index_id_reg = ++parse->nMem;
      /* Value for the stat column of _sql_stat1. */
      int stat1_reg = ++parse->nMem;
      /* MUST BE LAST (see below). */
@@ -800,13 +800,13 @@ vdbe_emit_analyze_space(struct Parse *parse, 
struct space *space)
      assert(space->index_count != 0);
      struct Vdbe *v = sqlite3GetVdbe(parse);
      assert(v != NULL);
-    const char *tab_name = space_name(space);
+    MAYBE_UNUSED const char *tab_name = space_name(space);
      sqlite3VdbeAddOp4(v, OP_IteratorOpen, tab_cursor, 0, 0, (void *) 
space,
                P4_SPACEPTR);
-    sqlite3VdbeLoadString(v, tab_name_reg, space->def->name);
+    sqlite3VdbeAddOp2(v, OP_Integer, space->def->id, space_id_reg);
      for (uint32_t j = 0; j < space->index_count; ++j) {
          struct index *idx = space->index[j];
-        const char *idx_name;
+        MAYBE_UNUSED const char *idx_name;
          /*
           * Primary indexes feature automatically generated
           * names. Thus, for the sake of clarity, use
@@ -817,8 +817,8 @@ vdbe_emit_analyze_space(struct Parse *parse, struct 
space *space)
          else
              idx_name = idx->def->name;
          int part_count = idx->def->key_def->part_count;
-        /* Populate the register containing the index name. */
-        sqlite3VdbeLoadString(v, idx_name_reg, idx_name);
+        /* Populate the register containing the index id. */
+        sqlite3VdbeAddOp2(v, OP_Integer, idx->def->iid, index_id_reg);
          VdbeComment((v, "Analysis for %s.%s", tab_name, idx_name));
          /*
           * Pseudo-code for loop that calls stat_push():
@@ -993,9 +993,8 @@ vdbe_emit_analyze_space(struct Parse *parse, struct 
space *space)
          sqlite3VdbeAddOp2(v, OP_Next, idx_cursor, next_row_addr);
          /* Add the entry to the stat1 table. */
          callStatGet(v, stat4_reg, STAT_GET_STAT1, stat1_reg);
-        assert("BBB"[0] == AFFINITY_TEXT);
-        sqlite3VdbeAddOp4(v, OP_MakeRecord, tab_name_reg, 3, tmp_reg,
-                  "BBB", 0);
+        sqlite3VdbeAddOp4(v, OP_MakeRecord, space_id_reg, 3, tmp_reg,
+                  "DDB", 0);
          sqlite3VdbeAddOp4(v, OP_IdxInsert, tmp_reg, 0, 0,
                    (char *)stat1, P4_SPACEPTR);
          /* Add the entries to the stat4 table. */
@@ -1029,7 +1028,7 @@ vdbe_emit_analyze_space(struct Parse *parse, 
struct space *space)
          }
          sqlite3VdbeAddOp3(v, OP_MakeRecord, col_reg, part_count,
                    sample_reg);
-        sqlite3VdbeAddOp3(v, OP_MakeRecord, tab_name_reg, 6, tmp_reg);
+        sqlite3VdbeAddOp3(v, OP_MakeRecord, space_id_reg, 6, tmp_reg);
          sqlite3VdbeAddOp4(v, OP_IdxReplace, tmp_reg, 0, 0,
                    (char *)stat4, P4_SPACEPTR);
          /* P1==1 for end-of-loop. */
@@ -1070,7 +1069,7 @@ static void
  sql_analyze_database(struct Parse *parser)
  {
      sql_set_multi_write(parser, false);
-    vdbe_emit_stat_space_open(parser, NULL);
+    vdbe_emit_stat_space_open(parser, BOX_ID_NIL);
      space_foreach(sql_space_foreach_analyze, (void *)parser);
      loadAnalysis(parser);
  }
@@ -1091,7 +1090,7 @@ vdbe_emit_analyze_table(struct Parse *parse, 
struct space *space)
       * There are two system spaces for statistics: _sql_stat1
       * and _sql_stat4.
       */
-    vdbe_emit_stat_space_open(parse, space->def->name);
+    vdbe_emit_stat_space_open(parse, space->def->id);
      vdbe_emit_analyze_space(parse, space);
      loadAnalysis(parse);
  }
@@ -1225,24 +1224,17 @@ analysis_loader(void *data, int argc, char 
**argv, char **unused)
      struct analysis_index_info *info = (struct analysis_index_info *) 
data;
      assert(info->stats != NULL);
      struct index_stat *stat = &info->stats[info->index_count++];
-    struct space *space = space_by_name(argv[0]);
+    uint32_t space_id = atoll(argv[0]);
+    if (space_id == 0)
+        return -1;
+    struct space *space = space_by_id(space_id);
      if (space == NULL)
          return -1;
      struct index *index;
-    uint32_t iid = box_index_id_by_name(space->def->id, argv[1],
-                        strlen(argv[1]));
-    /*
-     * Convention is if index's name matches with space's
-     * one, then it is primary index.
-     */
-    if (iid != BOX_ID_NIL) {
-        index = space_index(space, iid);
-    } else {
-        if (sqlite3_stricmp(argv[0], argv[1]) != 0)
-            return -1;
-        index = space_index(space, 0);
-    }
-    assert(index != NULL);
+    uint32_t iid = atoll(argv[1]);
+    index = space_index(space, iid);
+    if (index == NULL)
+        return -1;
      /*
       * Additional field is used to describe total
       * count of tuples in index. Although now all
@@ -1354,8 +1346,12 @@ sample_compare(const void *a, const void *b, void 
*arg)
   * Arguments must point to SQL statements that return
   * data equivalent to the following:
   *
- *    prepare: SELECT tbl,idx,count(*) FROM _sql_stat4 GROUP BY tbl,idx;
- *    load: SELECT tbl,idx,neq,nlt,ndlt,sample FROM _sql_stat4;
+ * prepare:
+ *     SELECT space_id,index_id,count(*) FROM _sql_stat4
+ *     GROUP BY space_id,index_id;
+ * load:
+ *     SELECT space_id,index_id,neq,nlt,ndlt,sample
+ *     FROM _sql_stat4;
   *
   * 'prepare' statement is used to allocate enough memory for
   * statistics (i.e. arrays lt, dt, dlt and avg_eq). 'load' query
@@ -1387,24 +1383,17 @@ load_stat_from_space(struct sqlite3 *db, const 
char *sql_select_prepare,
          goto finalize;
      uint32_t current_idx_count = 0;
      while (sqlite3_step(stmt) == SQLITE_ROW) {
-        const char *space_name = (char *)sqlite3_column_text(stmt, 0);
-        if (space_name == NULL)
+        uint32_t space_id = sqlite3_column_int(stmt, 0);
+        if (space_id == 0)
              continue;
-        const char *index_name = (char *)sqlite3_column_text(stmt, 1);
-        if (index_name == NULL)
+        struct space *space = space_by_id(space_id);
+        if (space == NULL)
+            continue;
+        uint32_t iid = sqlite3_column_int(stmt, 1);
+        struct index *index = space_index(space, iid);
+        if (index == NULL)
              continue;
          uint32_t sample_count = sqlite3_column_int(stmt, 2);
-        struct space *space = space_by_name(space_name);
-        assert(space != NULL);
-        struct index *index;
-        uint32_t iid = box_index_id_by_name(space->def->id, index_name,
-                            strlen(index_name));
-        if (sqlite3_stricmp(space_name, index_name) == 0 &&
-            iid == BOX_ID_NIL)
-            index = space_index(space, 0);
-        else
-            index = space_index(space, iid);
-        assert(index != NULL);
          uint32_t column_count = index->def->key_def->part_count;
          struct index_stat *stat = &stats[current_idx_count];
          stat->sample_field_count = column_count;
@@ -1456,25 +1445,16 @@ load_stat_from_space(struct sqlite3 *db, const 
char *sql_select_prepare,
      struct index *prev_index = NULL;
      current_idx_count = 0;
      while (sqlite3_step(stmt) == SQLITE_ROW) {
-        const char *space_name = (char *)sqlite3_column_text(stmt, 0);
-        if (space_name == NULL)
+        uint32_t space_id = sqlite3_column_int(stmt, 0);
+        if (space_id == 0)
              continue;
-        const char *index_name = (char *)sqlite3_column_text(stmt, 1);
-        if (index_name == NULL)
+        struct space *space = space_by_id(space_id);
+        if (space == NULL)
+            continue;
+        uint32_t iid = sqlite3_column_int(stmt, 1);
+        struct index *index = space_index(space, iid);
+        if (index == NULL)
              continue;
-        struct space *space = space_by_name(space_name);
-        assert(space != NULL);
-        struct index *index;
-        uint32_t iid = box_index_id_by_name(space->def->id, index_name,
-                            strlen(index_name));
-        if (iid != BOX_ID_NIL) {
-            index = space_index(space, iid);
-        } else {
-            if (sqlite3_stricmp(space_name, index_name) != 0)
-                return -1;
-            index = space_index(space, 0);
-        }
-        assert(index != NULL);
          uint32_t column_count = index->def->key_def->part_count;
          if (index != prev_index) {
              if (prev_index != NULL) {
@@ -1537,25 +1517,16 @@ load_stat_to_index(struct sqlite3 *db, const 
char *sql_select_load,
          return -1;
      uint32_t current_idx_count = 0;
      while (sqlite3_step(stmt) == SQLITE_ROW) {
-        const char *space_name = (char *)sqlite3_column_text(stmt, 0);
-        if (space_name == NULL)
+        uint32_t space_id = sqlite3_column_int(stmt, 0);
+        if (space_id == 0)
              continue;
-        const char *index_name = (char *)sqlite3_column_text(stmt, 1);
-        if (index_name == NULL)
+        struct space *space = space_by_id(space_id);
+        if (space == NULL)
+            continue;
+        uint32_t iid = sqlite3_column_int(stmt, 1);
+        struct index *index = space_index(space, iid);
+        if (index == NULL)
              continue;
-        struct space *space = space_by_name(space_name);
-        assert(space != NULL);
-        struct index *index;
-        uint32_t iid = box_index_id_by_name(space->def->id, index_name,
-                            strlen(index_name));
-        if (iid != BOX_ID_NIL) {
-            index = space_index(space, iid);
-        } else {
-            if (sqlite3_stricmp(space_name, index_name) != 0)
-                return -1;
-            index = space_index(space, 0);
-        }
-        assert(index != NULL);
          free(index->def->opts.stat);
          index->def->opts.stat = stats[current_idx_count++];
      }
@@ -1699,7 +1670,7 @@ sql_analysis_load(struct sqlite3 *db)
      info.stats = stats;
      info.index_count = 0;
      const char *load_stat1 =
-        "SELECT \"tbl\",\"idx\",\"stat\" FROM \"_sql_stat1\"";
+        "SELECT \"space_id\",\"index_id\",\"stat\" FROM \"_sql_stat1\"";
      /* Load new statistics out of the _sql_stat1 table. */
      if (sqlite3_exec(db, load_stat1, analysis_loader, &info, 0) != 0)
          goto fail;
@@ -1712,10 +1683,10 @@ sql_analysis_load(struct sqlite3 *db)
       * statistics. Result rows are given in a form:
       * <table name>, <index name>, <count of samples>
       */
-    const char *init_query = "SELECT \"tbl\",\"idx\",count(*) FROM "
-                 "\"_sql_stat4\" GROUP BY \"tbl\",\"idx\"";
+    const char *init_query = "SELECT \"space_id\",\"index_id\",count(*) 
FROM "
+                 "\"_sql_stat4\" GROUP BY \"space_id\",\"index_id\"";
      /* Query for loading statistics into in-memory structs. */
-    const char *load_query = "SELECT \"tbl\",\"idx\",\"neq\",\"nlt\","
+    const char *load_query = "SELECT 
\"space_id\",\"index_id\",\"neq\",\"nlt\","
                   "\"ndlt\",\"sample\" FROM \"_sql_stat4\"";
      /* Load the statistics from the _sql_stat4 table. */
      if (load_stat_from_space(db, init_query, load_query, stats) != 0)
@@ -1759,8 +1730,8 @@ sql_analysis_load(struct sqlite3 *db)
       * Ordered query is needed to be sure that indexes come
       * in the same order as in previous SELECTs.
       */
-    const char *order_query = "SELECT \"tbl\",\"idx\" FROM "
-                  "\"_sql_stat4\" GROUP BY \"tbl\",\"idx\"";
+    const char *order_query = "SELECT \"space_id\",\"index_id\" FROM "
+                  "\"_sql_stat4\" GROUP BY \"space_id\",\"index_id\"";
      if (load_stat_to_index(db, order_query, heap_stats) != 0)
          goto fail;
      if (box_txn_commit() != 0)
diff --git a/src/box/sql/build.c b/src/box/sql/build.c
index 52f0bde..67d9627 100644
--- a/src/box/sql/build.c
+++ b/src/box/sql/build.c
@@ -1707,75 +1707,43 @@ sql_store_select(struct Parse *parse_context, 
struct Select *select)
      parse_context->parsed_ast.select = select_copy;
  }

-/**
- * Create expression record "@col_name = '@col_value'".
- *
- * @param parse The parsing context.
- * @param col_name Name of column.
- * @param col_value Name of row.
- * @retval not NULL on success.
- * @retval NULL on failure.
- */
-static struct Expr *
-sql_id_eq_str_expr(struct Parse *parse, const char *col_name,
-           const char *col_value)
-{
-    struct sqlite3 *db = parse->db;
-
-    struct Expr *col_name_expr = sqlite3Expr(db, TK_ID, col_name);
-    if (col_name_expr == NULL)
-        return NULL;
-    struct Expr *col_value_expr = sqlite3Expr(db, TK_STRING, col_value);
-    if (col_value_expr == NULL) {
-        sql_expr_delete(db, col_name_expr, false);
-        return NULL;
-    }
-    return sqlite3PExpr(parse, TK_EQ, col_name_expr, col_value_expr);
-}
-
  void
  vdbe_emit_stat_space_clear(struct Parse *parse, const char 
*stat_table_name,
-               const char *idx_name, const char *table_name)
+               uint32_t space_id, uint32_t index_id)
  {
-    assert(idx_name != NULL || table_name != NULL);
      struct sqlite3 *db = parse->db;
      assert(!db->mallocFailed);
      struct SrcList *src_list = sql_alloc_src_list(db);
      if (src_list != NULL)
          src_list->a[0].zName = sqlite3DbStrDup(db, stat_table_name);
-    struct Expr *where = NULL;
-    if (idx_name != NULL) {
-        struct Expr *expr = sql_id_eq_str_expr(parse, "idx", idx_name);
-        if (expr != NULL)
-            where = sqlite3ExprAnd(db, expr, where);
-    }
-    if (table_name != NULL) {
-        struct Expr *expr = sql_id_eq_str_expr(parse, "tbl", table_name);
-        if (expr != NULL)
-            where = sqlite3ExprAnd(db, expr, where);
-    }
-    /**
-     * On memory allocation error sql_table delete_from
-     * releases memory for its own.
-     */
-    sql_table_delete_from(parse, src_list, where);
+    struct Expr *expr = NULL;
+    struct Expr *col = sqlite3Expr(db, TK_ID, "space_id");
+    struct Expr *val = sqlite3ExprInteger(db, space_id);
+    if (col != NULL && val != NULL)
+        expr = sqlite3PExpr(parse, TK_EQ, col, val);
+    if (index_id != BOX_ID_NIL && expr != NULL) {
+        col = sqlite3Expr(db, TK_ID, "index_id");
+        val = sqlite3ExprInteger(db, index_id);
+        expr = sqlite3ExprAnd(db, sqlite3PExpr(parse, TK_EQ, col, val),
+                      expr);
+    }
+    sql_table_delete_from(parse, src_list, expr);
  }

  /**
   * Remove entries from the _sql_stat1 and _sql_stat4
   * system spaces after a DROP INDEX or DROP TABLE command.
   *
- * @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.
+ * @param parse The parsing context.
+ * @param space_id Id of table to be dropped or table that
+ *        contains index to be dropped.
+ * @param index_id Id of index to be dropped.
   */
  static void
-sql_clear_stat_spaces(struct Parse *parse, const char *table_name,
-              const char *idx_name)
+sql_clear_stat_spaces(struct Parse *parse, uint32_t space_id, uint32_t 
index_id)
  {
-    vdbe_emit_stat_space_clear(parse, "_sql_stat4", idx_name, table_name);
-    vdbe_emit_stat_space_clear(parse, "_sql_stat1", idx_name, table_name);
+    vdbe_emit_stat_space_clear(parse, "_sql_stat4", space_id, index_id);
+    vdbe_emit_stat_space_clear(parse, "_sql_stat1", space_id, index_id);
  }

  /**
@@ -1996,7 +1964,7 @@ sql_drop_table(struct Parse *parse_context, struct 
SrcList *table_name_list,
              goto exit_drop_table;
          }
      }
-    sql_clear_stat_spaces(parse_context, space_name, NULL);
+    sql_clear_stat_spaces(parse_context, space->def->id, BOX_ID_NIL);
      sql_code_drop_table(parse_context, space, is_view);

   exit_drop_table:
@@ -2845,7 +2813,8 @@ 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, table_name, index->def->name);
+    sql_clear_stat_spaces(parse_context, space->def->id, index->def->iid);
+
      int record_reg = ++parse_context->nMem;
      int space_id_reg = ++parse_context->nMem;
      sqlite3VdbeAddOp2(v, OP_Integer, space->def->id, space_id_reg);
diff --git a/src/box/sql/sqliteInt.h b/src/box/sql/sqliteInt.h
index dbf58d9..2958a68 100644
--- a/src/box/sql/sqliteInt.h
+++ b/src/box/sql/sqliteInt.h
@@ -4926,11 +4926,13 @@ vdbe_emit_halt_with_presence_test(struct Parse 
*parser, int space_id,
   *
   * @param parse The parsing context.
   * @param stat_table_name System stat table name.
- * @param idx_name Index name.
- * @param table_name Table name.
+ * @param table_id Id of table of which analysis will be deleted.
+ * @param index_id Id of index of which analysis will be deleted.
+ *        If index_id is BOX_ID_NIL than analysis of all indexes
+ *        of selected table will be deleted.
   */
  void
  vdbe_emit_stat_space_clear(struct Parse *parse, const char 
*stat_table_name,
-               const char *idx_name, const char *table_name);
+               uint32_t table_id, uint32_t index_id);

  #endif                /* SQLITEINT_H */
diff --git a/test/box-py/bootstrap.result b/test/box-py/bootstrap.result
index 506aca3..6dc13b4 100644
--- a/test/box-py/bootstrap.result
+++ b/test/box-py/bootstrap.result
@@ -5,7 +5,7 @@ box.space._schema:select{}
  ---
  - - ['cluster', '<cluster uuid>']
    - ['max_id', 511]
-  - ['version', 2, 1, 0]
+  - ['version', 2, 1, 1]
  ...
  box.space._cluster:select{}
  ---
@@ -74,11 +74,12 @@ box.space._space:select{}
          'type': 'unsigned'}]]
    - [340, 1, '_space_sequence', 'memtx', 0, {}, [{'name': 'id', 
'type': 'unsigned'},
        {'name': 'sequence_id', 'type': 'unsigned'}, {'name': 
'is_generated', 'type': 'boolean'}]]
-  - [348, 1, '_sql_stat1', 'memtx', 0, {}, [{'name': 'tbl', 'type': 
'string'}, {'name': 'idx',
-        'type': 'string'}, {'name': 'stat', 'type': 'string'}]]
-  - [349, 1, '_sql_stat4', 'memtx', 0, {}, [{'name': 'tbl', 'type': 
'string'}, {'name': 'idx',
-        'type': 'string'}, {'name': 'neq', 'type': 'string'}, {'name': 
'nlt', 'type': 'string'},
-      {'name': 'ndlt', 'type': 'string'}, {'name': 'sample', 'type': 
'scalar'}]]
+  - [348, 1, '_sql_stat1', 'memtx', 0, {}, [{'name': 'space_id', 
'type': 'unsigned'},
+      {'name': 'index_id', 'type': 'unsigned'}, {'name': 'stat', 
'type': 'string'}]]
+  - [349, 1, '_sql_stat4', 'memtx', 0, {}, [{'name': 'space_id', 
'type': 'unsigned'},
+      {'name': 'index_id', 'type': 'unsigned'}, {'name': 'neq', 'type': 
'string'},
+      {'name': 'nlt', 'type': 'string'}, {'name': 'ndlt', 'type': 
'string'}, {'name': 'sample',
+        'type': 'scalar'}]]
    - [356, 1, '_fk_constraint', 'memtx', 0, {}, [{'name': 'name', 
'type': 'string'},
        {'name': 'child_id', 'type': 'unsigned'}, {'name': 'parent_id', 
'type': 'unsigned'},
        {'name': 'is_deferred', 'type': 'boolean'}, {'name': 'match', 
'type': 'string'},
@@ -134,9 +135,9 @@ box.space._index:select{}
    - [330, 0, 'primary', 'tree', {'unique': true}, [[0, 'unsigned']]]
    - [340, 0, 'primary', 'tree', {'unique': true}, [[0, 'unsigned']]]
    - [340, 1, 'sequence', 'tree', {'unique': false}, [[1, 'unsigned']]]
-  - [348, 0, 'primary', 'tree', {'unique': true}, [[0, 'string'], [1, 
'string']]]
-  - [349, 0, 'primary', 'tree', {'unique': true}, [[0, 'string'], [1, 
'string'], [
-        5, 'scalar']]]
+  - [348, 0, 'primary', 'tree', {'unique': true}, [[0, 'unsigned'], [1, 
'unsigned']]]
+  - [349, 0, 'primary', 'tree', {'unique': true}, [[0, 'unsigned'], [1, 
'unsigned'],
+      [5, 'scalar']]]
    - [356, 0, 'primary', 'tree', {'unique': true}, [[0, 'string'], [1, 
'unsigned']]]
    - [356, 1, 'child_id', 'tree', {'unique': false}, [[1, 'unsigned']]]
  ...
diff --git a/test/box/access_misc.result b/test/box/access_misc.result
index 4ffeb38..83e9d3e 100644
--- a/test/box/access_misc.result
+++ b/test/box/access_misc.result
@@ -813,11 +813,12 @@ box.space._space:select()
          'type': 'unsigned'}]]
    - [340, 1, '_space_sequence', 'memtx', 0, {}, [{'name': 'id', 
'type': 'unsigned'},
        {'name': 'sequence_id', 'type': 'unsigned'}, {'name': 
'is_generated', 'type': 'boolean'}]]
-  - [348, 1, '_sql_stat1', 'memtx', 0, {}, [{'name': 'tbl', 'type': 
'string'}, {'name': 'idx',
-        'type': 'string'}, {'name': 'stat', 'type': 'string'}]]
-  - [349, 1, '_sql_stat4', 'memtx', 0, {}, [{'name': 'tbl', 'type': 
'string'}, {'name': 'idx',
-        'type': 'string'}, {'name': 'neq', 'type': 'string'}, {'name': 
'nlt', 'type': 'string'},
-      {'name': 'ndlt', 'type': 'string'}, {'name': 'sample', 'type': 
'scalar'}]]
+  - [348, 1, '_sql_stat1', 'memtx', 0, {}, [{'name': 'space_id', 
'type': 'unsigned'},
+      {'name': 'index_id', 'type': 'unsigned'}, {'name': 'stat', 
'type': 'string'}]]
+  - [349, 1, '_sql_stat4', 'memtx', 0, {}, [{'name': 'space_id', 
'type': 'unsigned'},
+      {'name': 'index_id', 'type': 'unsigned'}, {'name': 'neq', 'type': 
'string'},
+      {'name': 'nlt', 'type': 'string'}, {'name': 'ndlt', 'type': 
'string'}, {'name': 'sample',
+        'type': 'scalar'}]]
    - [356, 1, '_fk_constraint', 'memtx', 0, {}, [{'name': 'name', 
'type': 'string'},
        {'name': 'child_id', 'type': 'unsigned'}, {'name': 'parent_id', 
'type': 'unsigned'},
        {'name': 'is_deferred', 'type': 'boolean'}, {'name': 'match', 
'type': 'string'},
diff --git a/test/box/alter.result b/test/box/alter.result
index 9a1086e..86e8c3a 100644
--- a/test/box/alter.result
+++ b/test/box/alter.result
@@ -228,9 +228,9 @@ _index:select{}
    - [330, 0, 'primary', 'tree', {'unique': true}, [[0, 'unsigned']]]
    - [340, 0, 'primary', 'tree', {'unique': true}, [[0, 'unsigned']]]
    - [340, 1, 'sequence', 'tree', {'unique': false}, [[1, 'unsigned']]]
-  - [348, 0, 'primary', 'tree', {'unique': true}, [[0, 'string'], [1, 
'string']]]
-  - [349, 0, 'primary', 'tree', {'unique': true}, [[0, 'string'], [1, 
'string'], [
-        5, 'scalar']]]
+  - [348, 0, 'primary', 'tree', {'unique': true}, [[0, 'unsigned'], [1, 
'unsigned']]]
+  - [349, 0, 'primary', 'tree', {'unique': true}, [[0, 'unsigned'], [1, 
'unsigned'],
+      [5, 'scalar']]]
    - [356, 0, 'primary', 'tree', {'unique': true}, [[0, 'string'], [1, 
'unsigned']]]
    - [356, 1, 'child_id', 'tree', {'unique': false}, [[1, 'unsigned']]]
  ...
diff --git a/test/sql-tap/analyze1.test.lua b/test/sql-tap/analyze1.test.lua
index ea414e9..0eb4129 100755
--- a/test/sql-tap/analyze1.test.lua
+++ b/test/sql-tap/analyze1.test.lua
@@ -65,7 +65,7 @@ test:do_execsql_test(
  test:do_execsql_test(
      "analyze-1.7",
      [[
-        SELECT * FROM "_sql_stat1" WHERE "idx" IS NOT NULL
+        SELECT * FROM "_sql_stat1" WHERE "index_id" IS NOT NULL
      ]], {
          -- <analyze-1.7>
          -- </analyze-1.7>
@@ -84,7 +84,7 @@ test:do_catchsql_test(
  test:do_execsql_test(
      "analyze-1.9",
      [[
-        SELECT * FROM "_sql_stat1" WHERE "idx" IS NOT NULL
+        SELECT * FROM "_sql_stat1" WHERE "index_id" IS NOT NULL
      ]], {
          -- <analyze-1.9>
          -- </analyze-1.9>
@@ -119,7 +119,7 @@ test:do_execsql_test(
      [[
          CREATE INDEX t1i1 ON t1(a);
          ANALYZE t1;
-        SELECT * FROM "_sql_stat1" ORDER BY "idx";
+        SELECT * FROM "_sql_stat1" ORDER BY "index_id";
      ]], {
          -- <analyze-2.1>
          -- </analyze-2.1>
@@ -130,7 +130,7 @@ test:do_execsql_test(
      [[
          CREATE INDEX t1i2 ON t1(b);
          ANALYZE t1;
-        SELECT * FROM "_sql_stat1" ORDER BY "idx";
+        SELECT * FROM "_sql_stat1" ORDER BY "index_id";
      ]], {
          -- <analyze-2.2>
          -- </analyze-2.2>
@@ -141,7 +141,7 @@ test:do_execsql_test(
      [[
          CREATE INDEX t1i3 ON t1(a,b);
          ANALYZE;
-        SELECT * FROM "_sql_stat1" ORDER BY "idx";
+        SELECT * FROM "_sql_stat1" ORDER BY "index_id";
      ]], {
          -- <analyze-2.3>
          -- </analyze-2.3>
@@ -157,10 +157,10 @@ test:do_execsql_test(
          INSERT INTO t1 VALUES(1, 1,2);
          INSERT INTO t1 VALUES(2, 1,3);
          ANALYZE t1;
-        SELECT "idx", "stat" FROM "_sql_stat1" ORDER BY "idx";
+        SELECT "index_id", "stat" FROM "_sql_stat1" ORDER BY "index_id";
      ]], {
          -- <analyze-3.1>
-        "T1", "2 1", "T1I1", "2 2", "T1I2", "2 1", "T1I3", "2 2 1"
+        0, "2 1", 1, "2 2", 2, "2 1", 3, "2 2 1"
          -- </analyze-3.1>
      })

@@ -170,10 +170,10 @@ test:do_execsql_test(
          INSERT INTO t1 VALUES(3, 1,4);
          INSERT INTO t1 VALUES(4, 1,5);
          ANALYZE t1;
-        SELECT "idx", "stat" FROM "_sql_stat1" ORDER BY "idx";
+        SELECT "index_id", "stat" FROM "_sql_stat1" ORDER BY "index_id";
      ]], {
          -- <analyze-3.2>
-        "T1", "4 1", "T1I1", "4 4", "T1I2", "4 1", "T1I3", "4 4 1"
+        0, "4 1", 1, "4 4", 2, "4 1", 3, "4 4 1"
          -- </analyze-3.2>
      })

@@ -182,10 +182,10 @@ test:do_execsql_test(
      [[
          INSERT INTO t1 (a,b) VALUES(2,5);
          ANALYZE;
-        SELECT "idx", "stat" FROM "_sql_stat1" ORDER BY "idx";
+        SELECT "index_id", "stat" FROM "_sql_stat1" ORDER BY "index_id";
      ]], {
          -- <analyze-3.3>
-        "T1","5 1", "T1I1", "5 3", "T1I2", "5 2", "T1I3", "5 3 1"
+        0,"5 1", 1, "5 3", 2, "5 2", 3, "5 3 1"
          -- </analyze-3.3>
      })

@@ -198,10 +198,10 @@ test:do_execsql_test(
          CREATE INDEX t2i2 ON t2(b);
          CREATE INDEX t2i3 ON t2(a,b);
          ANALYZE;
-        SELECT "idx", "stat" FROM "_sql_stat1" ORDER BY "idx";
+        SELECT "index_id", "stat" FROM "_sql_stat1" ORDER BY "index_id";
      ]], {
          -- <analyze-3.4>
-        "T1","5 1","T1I1","5 3","T1I2","5 2","T1I3","5 3 1","T2","5 
1","T2I1","5 3","T2I2","5 2","T2I3","5 3 1"
+        0,"5 1",0,"5 1",1,"5 3",1,"5 3",2,"5 2",2,"5 2",3,"5 3 1",3,"5 3 1"
          -- </analyze-3.4>
      })

@@ -210,10 +210,10 @@ test:do_execsql_test(
      [[
          DROP INDEX t2i3 ON t2;;
          ANALYZE t1;
-        SELECT "idx", "stat" FROM "_sql_stat1" ORDER BY "idx";
+        SELECT "index_id", "stat" FROM "_sql_stat1" ORDER BY "index_id";
      ]], {
          -- <analyze-3.5>
-        "T1","5 1","T1I1","5 3","T1I2","5 2","T1I3","5 3 1","T2","5 
1","T2I1","5 3","T2I2","5 2"
+        0,"5 1",0,"5 1",1,"5 3",1,"5 3",2,"5 2",2,"5 2",3,"5 3 1"
          -- </analyze-3.5>
      })

@@ -221,10 +221,10 @@ test:do_execsql_test(
      "analyze-3.6",
      [[
          ANALYZE t2;
-        SELECT "idx", "stat" FROM "_sql_stat1" ORDER BY "idx";
+        SELECT "index_id", "stat" FROM "_sql_stat1" ORDER BY "index_id";
      ]], {
          -- <analyze-3.6>
-        "T1","5 1","T1I1","5 3","T1I2","5 2","T1I3","5 3 1","T2","5 
1","T2I1","5 3","T2I2","5 2"
+        0,"5 1",0,"5 1",1,"5 3",1,"5 3",2,"5 2",2,"5 2",3,"5 3 1"
          -- </analyze-3.6>
      })

@@ -233,10 +233,10 @@ test:do_execsql_test(
      [[
          DROP INDEX t2i2 ON t2;
          ANALYZE t2;
-        SELECT "idx", "stat" FROM "_sql_stat1" ORDER BY "idx";
+        SELECT "index_id", "stat" FROM "_sql_stat1" ORDER BY "index_id";
      ]], {
          -- <analyze-3.7>
-        "T1","5 1","T1I1","5 3","T1I2","5 2","T1I3","5 3 1","T2","5 
1","T2I1","5 3"
+        0,"5 1",0,"5 1",1,"5 3",1,"5 3",2,"5 2",3,"5 3 1"
          -- </analyze-3.7>
      })

@@ -250,7 +250,7 @@ test:do_execsql_test(
          CREATE INDEX t3i3 ON t3(d,b,c,a);
          DROP TABLE t1;
          DROP TABLE t2;
-        SELECT "idx", "stat" FROM "_sql_stat1" ORDER BY "idx";
+        SELECT "index_id", "stat" FROM "_sql_stat1" ORDER BY "index_id";
      ]], {
          -- <analyze-3.8>
          -- </analyze-3.8>
@@ -260,10 +260,10 @@ test:do_execsql_test(
      "analyze-3.9",
      [[
          ANALYZE;
-        SELECT "idx", "stat" FROM "_sql_stat1" ORDER BY "idx";
+        SELECT "index_id", "stat" FROM "_sql_stat1" ORDER BY "index_id";
      ]], {
          -- <analyze-3.9>
-        "T3","5 1","T3I1","5 3","T3I2","5 3 1 1 1","T3I3","5 5 2 1 1"
+        0,"5 1",1,"5 3",2,"5 3 1 1 1",3,"5 5 2 1 1"
          -- </analyze-3.9>
      })

@@ -277,7 +277,7 @@ test:do_execsql_test(
  --         INSERT INTO [silly " name] (a,b,c) VALUES(1, 2, 3);
  --         INSERT INTO [silly " name] (a,b,c) VALUES(4, 5, 6);
  --         ANALYZE;
---         SELECT "idx", "stat" FROM "_sql_stat1" ORDER BY "idx";
+--         SELECT "index_id", "stat" FROM "_sql_stat1" ORDER BY "index_id";
  --     ]], {
  --         -- <analyze-3.10>
  --         "another foolish ' name", "2 1", "foolish ' name", "2 1 1", 
"t3i1", "5 3", "t3i2", "5 3 1 1 1", "t3i3", "5 5 2 1 1"
@@ -288,7 +288,7 @@ test:do_execsql_test(
  --     "analyze-3.11",
  --     [[
  --         DROP INDEX "foolish ' name";
---         SELECT "idx", "stat" FROM sqlite_stat1 ORDER BY "idx";
+--         SELECT "index_id", "stat" FROM sqlite_stat1 ORDER BY "index_id";
  --     ]], {
  --         -- <analyze-3.11>
  --         "another foolish ' name", "2 1", "t3i1", "5 3", "t3i2", "5 
3 1 1 1", "t3i3", "5 5 2 1 1"
@@ -299,7 +299,7 @@ test:do_execsql_test(
  --     "analyze-3.11",
  --     [[
  --         DROP TABLE "silly "" name";
---         SELECT "idx", "stat" FROM sqlite_stat1 ORDER BY "idx";
+--         SELECT "index_id", "stat" FROM sqlite_stat1 ORDER BY "index_id";
  --     ]], {
  --         -- <analyze-3.11>
  --         "t3i1", "5 3", "t3i2", "5 3 1 1 1", "t3i3", "5 5 2 1 1"
@@ -317,31 +317,33 @@ test:do_execsql_test(
          CREATE INDEX t4i2 ON t4(y);
          INSERT INTO t4 SELECT id,a,b,c FROM t3;
          ANALYZE;
-        SELECT "idx", "stat" FROM "_sql_stat1" ORDER BY "idx";
+        SELECT "index_id", "stat" FROM "_sql_stat1" ORDER BY "index_id";
      ]], {
          -- <analyze-4.0>
-        "T3", "5 1", "T3I1", "5 3", "T3I2", "5 3 1 1 1", "T3I3", "5 5 2 
1 1", "T4", "5 1", "T4I1", "5 3", "T4I2", "5 2"
+        0, "5 1", 0, "5 1", 1, "5 3", 1, "5 3", 2, "5 3 1 1 1", 2, "5 
2", 3, "5 5 2 1 1"
          -- </analyze-4.0>
      })

+t4 = box.space.T4
+
  test:do_execsql_test(
      "analyze-4.1",
-    [[
+    string.format([[
          DELETE FROM "_sql_stat1";
-        INSERT INTO "_sql_stat1" VALUES('t4', 't4i1', 'nonsense');
-        INSERT INTO "_sql_stat1" VALUES('t4', 't4i2', 
'432653287412874653284129847632');
+        INSERT INTO "_sql_stat1" VALUES(%i, %i, 'nonsense');
+        INSERT INTO "_sql_stat1" VALUES(%i, %i, 
'432653287412874653284129847632');
          SELECT * FROM t4 WHERE x = 1234;
-    ]], {
+    ]], t4.id, t4.index['T4I1'].id, t4.id, t4.index['T4I2'].id), {
          -- <analyze-4.1>
          -- </analyze-4.1>
      })

  test:do_execsql_test(
      "analyze-4.2",
-    [[
-        INSERT INTO "_sql_stat1" VALUES('t4', 'xyzzy', '0 1 2 3');
+    string.format([[
+        INSERT INTO "_sql_stat1" VALUES(%i, 12345, '0 1 2 3');
          SELECT * FROM t4 WHERE x = 1234;
-    ]], {
+    ]], t4.id), {
          -- <analyze-4.2>
          -- </analyze-4.2>
      })
@@ -367,20 +369,20 @@ test:do_execsql_test(
          INSERT INTO t3 (a,b,c,d) SELECT a+64, b+64, c+64, d+64 FROM t3;
          INSERT INTO t4 (x,y,z) SELECT a, b, c FROM t3;
          ANALYZE;
-        SELECT DISTINCT "tbl" FROM "_sql_stat1" ORDER BY 1;
+        SELECT COUNT(DISTINCT "space_id") FROM "_sql_stat1" ORDER BY 1;
      ]], {
          -- <analyze-5.0>
-        "T3", "T4"
+        2
          -- </analyze-5.0>
      })

  test:do_execsql_test(
      "analyze-5.0.1",
      [[
-        SELECT DISTINCT "idx" FROM "_sql_stat1" ORDER BY 1;
+        SELECT "index_id" FROM "_sql_stat1" ORDER BY 1;
      ]], {
          -- <analyze-5.0>
-        "T3", "T3I1", "T3I2", "T3I3", "T4", "T4I1", "T4I2"
+        0, 0, 1, 1, 2, 2, 3
          -- </analyze-5.0>
      })

@@ -389,20 +391,20 @@ stat = "_sql_stat4"
  test:do_execsql_test(
      "analyze-5.1",
      string.format([[
-            SELECT DISTINCT "idx" FROM "%s" ORDER BY 1;
-        ]], stat, stat), {
+            SELECT DISTINCT "index_id" FROM "%s" ORDER BY 1;
+        ]], stat), {
          -- <analyze-5.1>
-        "T3", "T3I1", "T3I2", "T3I3", "T4", "T4I1", "T4I2"
+        0, 1, 2, 3
          -- </analyze-5.1>
      })

  test:do_execsql_test(
      "analyze-5.1.1",
      string.format([[
-            SELECT DISTINCT "tbl" FROM "%s" ORDER BY 1;
-        ]], stat, stat), {
+            SELECT COUNT(DISTINCT "space_id") FROM "%s" ORDER BY 1;
+        ]], stat), {
          -- <analyze-5.1>
-        "T3", "T4"
+        2
          -- </analyze-5.1>
      })

@@ -411,40 +413,40 @@ test:do_execsql_test(
      [[
          DROP INDEX t3i2 ON t3;
          ANALYZE;
-        SELECT DISTINCT "idx" FROM "_sql_stat1" ORDER BY 1;
+        SELECT "index_id" FROM "_sql_stat1" ORDER BY 1;
      ]], {
          -- <analyze-5.2>
-        "T3", "T3I1", "T3I3", "T4", "T4I1", "T4I2"
+        0, 0, 1, 1, 2, 3
          -- </analyze-5.2>
      })

  test:do_execsql_test(
      "analyze-5.2.1",
      [[
-        SELECT DISTINCT "tbl" FROM "_sql_stat1" ORDER BY 1;
+        SELECT COUNT(DISTINCT "space_id") FROM "_sql_stat1" ORDER BY 1;
      ]], {
          -- <analyze-5.2>
-        "T3", "T4"
+        2
          -- </analyze-5.2>
      })

  test:do_execsql_test(
      "analyze-5.3",
      string.format([[
-            SELECT DISTINCT "idx" FROM "%s" ORDER BY 1;
+            SELECT DISTINCT "index_id" FROM "%s" ORDER BY 1;
          ]], stat, stat), {
          -- <analyze-5.3>
-        "T3", "T3I1", "T3I3", "T4", "T4I1", "T4I2"
+        0, 1, 2, 3
          -- </analyze-5.3>
      })

  test:do_execsql_test(
      "analyze-5.3.1",
      string.format([[
-            SELECT DISTINCT "tbl" FROM "%s" ORDER BY 1;
-        ]], stat, stat), {
+            SELECT COUNT(DISTINCT "space_id") FROM "%s" ORDER BY 1;
+        ]], stat, stat, stat), {
          -- <analyze-5.3>
-        "T3", "T4"
+        2
          -- </analyze-5.3>
      })

@@ -453,40 +455,40 @@ test:do_execsql_test(
      [[
          DROP TABLE IF EXISTS t3;
          ANALYZE;
-        SELECT DISTINCT "idx" FROM "_sql_stat1" ORDER BY 1;
+        SELECT DISTINCT "index_id" FROM "_sql_stat1" ORDER BY 1;
      ]], {
          -- <analyze-5.4>
-        "T4", "T4I1", "T4I2"
+        0, 1, 2
          -- </analyze-5.4>
      })

  test:do_execsql_test(
      "analyze-5.4.1",
      [[
-        SELECT DISTINCT "tbl" FROM "_sql_stat1" ORDER BY 1;
+        SELECT COUNT(DISTINCT "space_id") FROM "_sql_stat1" ORDER BY 1;
      ]], {
          -- <analyze-5.4>
-        "T4"
+        1
          -- </analyze-5.4>
      })

  test:do_execsql_test(
      "analyze-5.5",
      string.format([[
-            SELECT DISTINCT "idx" FROM "%s" ORDER BY 1;
+            SELECT DISTINCT "index_id" FROM "%s" ORDER BY 1;
          ]], stat), {
          -- <analyze-5.5>
-        "T4", "T4I1", "T4I2"
+        0, 1, 2
          -- </analyze-5.5>
      })

  test:do_execsql_test(
      "analyze-5.5.1",
      string.format([[
-            SELECT DISTINCT "tbl" FROM "%s" ORDER BY 1;
-        ]], stat), {
+            SELECT COUNT(DISTINCT "space_id") FROM "%s" ORDER BY 1;
+        ]], stat, stat), {
          -- <analyze-5.5>
-        "T4"
+        1
          -- </analyze-5.5>
      })

@@ -516,33 +518,35 @@ test:do_test(
      -- </analyze-6.1.1>
  })

+t1 = box.space.T1
+
  test:do_execsql_test(
      "analyze-6.1.2",
-    [[
-            SELECT * FROM "_sql_stat1" where "tbl"='T1' and "idx"='I1' 
LIMIT 1;
-    ]], {
+    string.format([[
+            SELECT "index_id", "stat" FROM "_sql_stat1" where 
"space_id"=%i and "index_id"=%i LIMIT 1;
+    ]], t1.id, t1.index['I1'].id), {
      -- <analyze-6.1.2>
-    "T1", "I1", "221 221 221 221 2"
+    1, "221 221 221 221 2"
      -- </analyze-6.1.2>
  })

  test:do_execsql_test(
      "analyze-6.1.3",
-    [[
-            SELECT "tbl", "idx", "neq", "nlt", "ndlt" FROM "_sql_stat4" 
where "tbl"='T1' and "idx"='I1' ORDER BY "nlt" LIMIT 1;
-    ]], {
+    string.format([[
+            SELECT "index_id", "neq", "nlt", "ndlt" FROM "_sql_stat4" 
where "space_id"=%i and "index_id"=%i ORDER BY "nlt" LIMIT 1;
+    ]], t1.id, t1.index['I1'].id), {
      -- <analyze-6.1.3>
-    "T1", "I1", "221 221 221 1", "0 0 0 10", "0 0 0 10"
+    1, "221 221 221 1", "0 0 0 10", "0 0 0 10"
      -- </analyze-6.1.3>
  })

  test:do_execsql_test(
      "analyze-6.1.4",
-    [[
-            SELECT "tbl", "idx", "neq", "nlt", "ndlt" FROM "_sql_stat4" 
where "tbl"='T1' and "idx"='I1' ORDER BY "nlt" DESC LIMIT 1;
-    ]], {
+    string.format([[
+            SELECT "index_id", "neq", "nlt", "ndlt" FROM "_sql_stat4" 
where "space_id"=%i and "index_id"=%i ORDER BY "nlt" DESC LIMIT 1;
+    ]], t1.id, t1.index['I1'].id), {
      -- <analyze-6.1.4>
-    "T1", "I1", "221 221 221 1", "0 0 0 99", "0 0 0 99"
+    1, "221 221 221 1", "0 0 0 99", "0 0 0 99"
      -- </analyze-6.1.4>
  })

diff --git a/test/sql-tap/analyze4.test.lua b/test/sql-tap/analyze4.test.lua
index f734423..4cb3ad2 100755
--- a/test/sql-tap/analyze4.test.lua
+++ b/test/sql-tap/analyze4.test.lua
@@ -49,15 +49,19 @@ test:do_test(
          -- </analyze4-1.0>
      })

+t1 = box.space.T1
+
  -- Verify that the t1b index shows that it does not narrow down the
  -- search any at all.
  --
  test:do_execsql_test(
      "analyze4-1.1",
-    [[ SELECT "idx", "stat" FROM "_sql_stat1" WHERE "tbl"='T1' ORDER BY 
"idx"; ]],
+    string.format([[
+        SELECT "index_id", "stat" FROM "_sql_stat1" WHERE "space_id"=%i 
ORDER BY "index_id";
+    ]], t1.id),
      {
          -- <analyze4-1.1>
-        "T1","128 1", "T1A", "128 1", "T1B", "128 128"
+        0,"128 1", 1, "128 1", 2, "128 128"
          -- </analyze4-1.1>
      })

@@ -68,16 +72,16 @@ test:do_execsql_test(
  test:do_test(
      "analyze4-1.2",
      function()
-        return test:execsql([[
-            UPDATE t1 SET b='x' WHERE a%2;
+        return test:execsql(string.format([[
+            UPDATE t1 SET b='x' WHERE a%%2;
  -- pragma vdbe_debug=1;
              ANALYZE;
  -- pragma vdbe_debug=0;
-            SELECT "idx", "stat" FROM "_sql_stat1" WHERE "tbl"='T1' 
ORDER BY "idx";
-        ]])
+            SELECT "index_id", "stat" FROM "_sql_stat1" WHERE 
"space_id"=%i ORDER BY "index_id";
+        ]], t1.id))
      end, {
          -- <analyze4-1.2>
-        "T1", "128 1", "T1A", "128 1", "T1B", "128 64"
+        0, "128 1", 1, "128 1", 2, "128 64"
          -- </analyze4-1.2>
      })

@@ -85,37 +89,42 @@ test:do_test(
  -- Create a multi-column indices using t1.b and verify that ANALYZE
  -- processes them correctly.
  --
+
+test:execsql([[
+    -- Tarantool doesn't suppoort ALTER stmt yet.
+    -- UPDATE t1 SET b=NULL;
+    --ALTER TABLE t1 ADD COLUMN c;
+    --ALTER TABLE t1 ADD COLUMN d;
+    -- So, re-create the table and its contents
+    DROP TABLE t1;
+    CREATE TABLE t1(id INTEGER PRIMARY KEY AUTOINCREMENT, a INT ,b INT 
,c  INT DEFAULT NULL,d  INT DEFAULT NULL);
+    CREATE INDEX t1a ON t1(a);
+    CREATE INDEX t1b ON t1(b);
+    INSERT INTO t1 (a,b) VALUES(1,NULL);
+    INSERT INTO t1 (a,b) SELECT a+1, b FROM t1;
+    INSERT INTO t1 (a,b) SELECT a+2, b FROM t1;
+    INSERT INTO t1 (a,b) SELECT a+4, b FROM t1;
+    INSERT INTO t1 (a,b) SELECT a+8, b FROM t1;
+    INSERT INTO t1 (a,b) SELECT a+16, b FROM t1;
+    INSERT INTO t1 (a,b) SELECT a+32, b FROM t1;
+    INSERT INTO t1 (a,b) SELECT a+64, b FROM t1;
+
+    UPDATE t1 SET c=a/4, d=a/2;
+    CREATE INDEX t1bcd ON t1(b,c,d);
+    CREATE INDEX t1cdb ON t1(c,d,b);
+    CREATE INDEX t1cbd ON t1(c,b,d);
+    ANALYZE;
+]])
+
+t1 = box.space.T1
+
  test:do_execsql_test(
      "analyze4-1.3",
-    [[
-            -- Tarantool doesn't suppoort ALTER stmt yet.
-            -- UPDATE t1 SET b=NULL;
-            --ALTER TABLE t1 ADD COLUMN c;
-            --ALTER TABLE t1 ADD COLUMN d;
-            -- So, re-create the table and its contents
-            DROP TABLE t1;
-            CREATE TABLE t1(id INTEGER PRIMARY KEY AUTOINCREMENT, a INT 
,b INT ,c  INT DEFAULT NULL,d  INT DEFAULT NULL);
-            CREATE INDEX t1a ON t1(a);
-            CREATE INDEX t1b ON t1(b);
-            INSERT INTO t1 (a,b) VALUES(1,NULL);
-            INSERT INTO t1 (a,b) SELECT a+1, b FROM t1;
-            INSERT INTO t1 (a,b) SELECT a+2, b FROM t1;
-            INSERT INTO t1 (a,b) SELECT a+4, b FROM t1;
-            INSERT INTO t1 (a,b) SELECT a+8, b FROM t1;
-            INSERT INTO t1 (a,b) SELECT a+16, b FROM t1;
-            INSERT INTO t1 (a,b) SELECT a+32, b FROM t1;
-            INSERT INTO t1 (a,b) SELECT a+64, b FROM t1;
-
-            UPDATE t1 SET c=a/4, d=a/2;
-            CREATE INDEX t1bcd ON t1(b,c,d);
-            CREATE INDEX t1cdb ON t1(c,d,b);
-            CREATE INDEX t1cbd ON t1(c,b,d);
-            ANALYZE;
-            SELECT "idx", "stat" FROM "_sql_stat1" WHERE "tbl"='T1' 
ORDER BY "idx";
-    ]]
-    , {
+    string.format([[
+            SELECT "index_id", "stat" FROM "_sql_stat1" WHERE 
"space_id"=%i ORDER BY "index_id";
+    ]], t1.id), {
          -- <analyze4-1.3>
-        "T1","128 1", "T1A", "128 1", "T1B", "128 128", "T1BCD", "128 
128 4 2", "T1CBD", "128 4 4 2", "T1CDB", "128 4 2 2"
+        0,"128 1", 1, "128 1", 2, "128 128", 3, "128 128 4 2", 4, "128 
4 2 2", 5, "128 4 4 2"
          -- </analyze4-1.3>
      })

diff --git a/test/sql-tap/analyze5.test.lua b/test/sql-tap/analyze5.test.lua
index e4a6d5e..a55ef48 100755
--- a/test/sql-tap/analyze5.test.lua
+++ b/test/sql-tap/analyze5.test.lua
@@ -115,10 +115,11 @@ test:do_test(

          -- DISTINCT idx, sample -- lindex(test_decode(sample),0)
          -- WHERE idx='t1u' ORDER BY nlt;
-        return test:execsql([[ SELECT DISTINCT msgpack_decode("sample")
-                                 FROM "_sql_stat4"
-                                 WHERE "idx"='T1U'
-                                 ORDER BY "nlt"]])
+        return test:execsql(string.format([[
+            SELECT DISTINCT msgpack_decode("sample")
+            FROM "_sql_stat4"
+            WHERE "index_id"= %i
+            ORDER BY "nlt"]], box.space.T1.index['T1U'].id))
      end, {
          -- <analyze5-1.0>
          "alpha", "bravo", "charlie", "delta"
@@ -144,10 +145,10 @@ test:do_test(
  test:do_test(
      "analyze5-1.2",
      function()
-        return test:execsql([[SELECT "idx", count(*) FROM "_sql_stat4" 
GROUP BY 1 ORDER BY 1]])
+        return test:execsql([[SELECT "index_id", count(*) FROM 
"_sql_stat4" GROUP BY 1 ORDER BY 1]])
      end, {
          -- <analyze5-1.2>
- "T1",24,"T1T",4,"T1U",4,"T1V",1,"T1W",4,"T1X",4,"T1Y",2,"T1Z",4
+        0,24,1,4,2,4,3,1,4,4,5,4,6,2,7,4
          -- </analyze5-1.2>
      })

diff --git a/test/sql-tap/analyze9.test.lua b/test/sql-tap/analyze9.test.lua
index 585e918..55b8d8c 100755
--- a/test/sql-tap/analyze9.test.lua
+++ b/test/sql-tap/analyze9.test.lua
@@ -1,6 +1,6 @@
  #!/usr/bin/env tarantool
  test = require("sqltester")
-test:plan(121)
+test:plan(120)

  testprefix = "analyze9"

@@ -62,29 +62,29 @@ msgpack_decode_sample = function(txt)
  end

  box.internal.sql_create_function("msgpack_decode_sample", "TEXT", 
msgpack_decode_sample)
+t1 = box.space.T1

  test:do_execsql_test(
      1.2,
-    [[
-        SELECT 
"tbl","idx","neq","nlt","ndlt",msgpack_decode_sample("sample") FROM 
"_sql_stat4" where "idx" = 'I1';
-    ]], {
+    string.format([[
+        SELECT 
"index_id","neq","nlt","ndlt",msgpack_decode_sample("sample") FROM 
"_sql_stat4" where "index_id" = %i;
+    ]], t1.index['I1'].id), {
          -- <1.2>
-        "T1", "I1", "1 1", "0 0", "0 0", "(0) (0)", "T1", "I1", "1 1", 
"1 1", "1 1", "(1) (1)",
-        "T1", "I1", "1 1", "2 2", "2 2", "(2) (2)", "T1", "I1", "1 1", 
"3 3", "3 3", "(3) (3)",
-        "T1", "I1", "1 1", "4 4", "4 4", "(4) (4)"
+        1, "1 1", "0 0", "0 0", "(0) (0)", 1, "1 1", "1 1", "1 1", "(1) 
(1)",
+        1, "1 1", "2 2", "2 2", "(2) (2)", 1, "1 1", "3 3", "3 3", "(3) 
(3)",
+        1, "1 1", "4 4", "4 4", "(4) (4)"
          -- </1.2>
      })

  test:do_execsql_test(
      1.3,
-    [[
-        SELECT 
"tbl","idx","neq","nlt","ndlt",msgpack_decode_sample("sample") FROM 
"_sql_stat4" where "idx" = 'T1';
-
-    ]], {
+    string.format([[
+        SELECT 
"index_id","neq","nlt","ndlt",msgpack_decode_sample("sample") FROM 
"_sql_stat4" where "index_id" = %i;
+    ]], t1.index[0].id), {
          -- <1.3>
-        'T1', 'T1', '1', '0', '0', '(0)', 'T1', 'T1', '1', '1', '1', 
'(1)',
-        'T1', 'T1', '1', '2', '2', '(2)', 'T1', 'T1', '1', '3', '3', 
'(3)',
-        'T1', 'T1', '1', '4', '4', '(4)'
+        0, '1', '0', '0', '(0)', 0, '1', '1', '1', '(1)',
+        0, '1', '2', '2', '(2)', 0, '1', '3', '3', '(3)',
+        0, '1', '4', '4', '(4)'
          -- </1.3>
      })

@@ -101,10 +101,10 @@ test:do_execsql_test(
          INSERT INTO t1 VALUES('text', 12);
          CREATE INDEX i1 ON t1(a, b);
          ANALYZE;
-        SELECT msgpack_decode_sample("sample") FROM "_sql_stat4";
+        SELECT msgpack_decode_sample("sample") FROM "_sql_stat4" ORDER 
BY 1;
      ]], {
          -- <2.1>
-        "text 12","some text 14","text","some text"
+        "some text","some text 14","text","text 12"
          -- </2.1>
      })

@@ -116,6 +116,7 @@ test:do_execsql_test(
          CREATE TABLE t2(id INTEGER PRIMARY KEY AUTOINCREMENT, a INT , 
b INT );
          CREATE INDEX i2 ON t2(a, b);
      ]])
+t2 = box.space.T2

  test:do_test(
      3.2,
@@ -184,10 +185,10 @@ test:do_execsql_test(
  --
  test:do_execsql_test(
      "3.3.2",
-    [[
+    string.format([[
          ANALYZE;
-        SELECT lrange("neq", 1, 1) FROM "_sql_stat4" WHERE "idx" = 'I2';
-    ]], generate_tens_str(24))
+        SELECT lrange("neq", 1, 1) FROM "_sql_stat4" WHERE "space_id" = 
%i and "index_id" = %i;
+    ]], t2.id, t2.index['I2'].id) , generate_tens_str(24))

  ---------------------------------------------------------------------------
  --
@@ -232,6 +233,7 @@ test:do_execsql_test(
          CREATE TABLE t1(id INTEGER PRIMARY KEY AUTOINCREMENT, a TEXT , 
b INT , c INT);
          CREATE INDEX i1 ON t1(c, b, a);
      ]])
+t1 = box.space.T1

  insert_filler_rows_n = function(iStart, nCopy, nVal)
      for i = 0, nVal-1 do
@@ -282,10 +284,10 @@ test:do_execsql_test(

  test:do_execsql_test(
      4.3,
-    [[
+    string.format([[
          SELECT "neq", lrange("nlt", 1, 3), lrange("ndlt", 1, 3), 
lrange(msgpack_decode_sample("sample"), 1, 3)
-            FROM "_sql_stat4" WHERE "idx" = 'I1' ORDER BY "sample" 
LIMIT 16;
-    ]], {
+            FROM "_sql_stat4" WHERE "space_id" = %i and "index_id" = %i 
ORDER BY "sample" LIMIT 16;
+    ]], t1.id, t1.index['I1'].id), {
          -- <4.3>
          "10 10 10","0 0 0","0 0 0","0 0 0","10 10 10","10 10 10","1 1 
1","1 1 1","10 10 10","20 20 20",
          "2 2 2","2 2 2","10 10 10","30 30 30","3 3 3","3 3 3","10 10 
10","40 40 40","4 4 4","4 4 4",
@@ -299,10 +301,10 @@ test:do_execsql_test(

  test:do_execsql_test(
      4.4,
-    [[
+    string.format([[
          SELECT "neq", lrange("nlt", 1, 3), lrange("ndlt", 1, 3), 
lrange(msgpack_decode_sample("sample"), 1, 3)
-        FROM "_sql_stat4" WHERE "idx" = 'I1' ORDER BY "sample" DESC 
LIMIT 2;
-    ]], {
+        FROM "_sql_stat4" WHERE "space_id" = %i and "index_id" = %i 
ORDER BY "sample" DESC LIMIT 2;
+    ]], t1.id, t1.index['I1'].id), {
          -- <4.4>
          "2 1 1","295 296 296","120 122 125","201 4 h","5 3 1","290 290 
291","119 119 120","200 1 b"
          -- </4.4>
@@ -364,11 +366,12 @@ test:do_test(
  test:do_execsql_test(
      4.9,
      [[
-        SELECT msgpack_decode_sample("sample") FROM "_sql_stat4";
+        SELECT msgpack_decode_sample("sample") FROM "_sql_stat4" ORDER 
BY 1;
      ]], {
          -- <4.9>
-        "x", 1110, 2230, 2750, 3350, 4090, 4470, 4980, 5240, 5280, 
5290, 5590, 5920,
-        5930, 6220, 6710, 7000, 7710, 7830, 7970, 8890, 8950, 9240, 
9250, 9680
+        1110, 2230, 2750, 3350, 4090, 4470, 4980, 5240, 5280, 5290, 
5590, 5920,
+        5930, 6220, 6710, 7000, 7710, 7830, 7970, 8890, 8950, 9240, 
9250, 9680,
+        "x"
          -- </4.9>
      })

@@ -388,12 +391,14 @@ test:do_execsql_test(
          INSERT INTO t1 VALUES(null, 4, 4);
          INSERT INTO t1 VALUES(null, 5, 5);
          ANALYZE;
-        CREATE TABLE x1(tbl TEXT, idx TEXT , neq TEXT, nlt TEXT, ndlt 
TEXT, sample BLOB, PRIMARY KEY(tbl, idx, sample));
+        CREATE TABLE x1(tbl INT, idx INT , neq TEXT, nlt TEXT, ndlt 
TEXT, sample BLOB, PRIMARY KEY(tbl, idx, sample));
          INSERT INTO x1 SELECT * FROM "_sql_stat4";
          DELETE FROM "_sql_stat4";
          INSERT INTO "_sql_stat4" SELECT * FROM x1;
          ANALYZE;
      ]])
+t1 = box.space.T1
+x1 = box.space.X1

  test:do_execsql_test(
      6.2,
@@ -407,7 +412,7 @@ test:do_execsql_test(
  --
  test:do_execsql_test(
      7.1,
-    [[
+    string.format([[
          DROP TABLE IF EXISTS t1;
          CREATE TABLE t1(id INTEGER PRIMARY KEY AUTOINCREMENT, a INT , 
b INT );
          CREATE INDEX i1 ON t1(a, b);
@@ -418,9 +423,9 @@ test:do_execsql_test(
          INSERT INTO t1 VALUES(null, 5, 5);
          ANALYZE;
          UPDATE "_sql_stat4" SET "sample" = '' WHERE "sample" =
-            (SELECT "sample" FROM "_sql_stat4" WHERE "tbl" = 't1' AND 
"idx" = 'i1' LIMIT 1);
+            (SELECT "sample" FROM "_sql_stat4" WHERE "space_id" = %i 
AND "index_id" = %i LIMIT 1);
          ANALYZE;
-    ]])
+    ]], t1.id, t1.index['I1'].id))

  -- Doesn't work due to the fact that in Tarantool rowid has been removed,
  -- and tbl, idx and sample have been united into primary key.
@@ -1014,15 +1019,15 @@ test:do_execsql_test(
  --
  test:do_execsql_test(
      15.1,
-    [[
+    string.format([[
          DROP TABLE IF EXISTS x1;
          CREATE TABLE x1(a  INT PRIMARY KEY, b INT , UNIQUE(a, b));
          INSERT INTO x1 VALUES(1, 2);
          INSERT INTO x1 VALUES(3, 4);
          INSERT INTO x1 VALUES(5, 6);
          ANALYZE;
-        INSERT INTO "_sql_stat4" VALUES('x1', 'abc', '', '', '', '');
-    ]])
+        INSERT INTO "_sql_stat4" VALUES(%i, 12345, '', '', '', '');
+    ]], x1.id))

  test:do_execsql_test(
      15.2,
@@ -1037,7 +1042,7 @@ test:do_execsql_test(
  test:do_execsql_test(
      15.3,
      [[
-        INSERT INTO "_sql_stat4" VALUES('42', '42', '42', '42', '42', 
'42');
+        INSERT INTO "_sql_stat4" VALUES(42, 42, '42', '42', '42', 42);
      ]])

  test:do_execsql_test(
@@ -1054,7 +1059,7 @@ test:do_execsql_test(
      15.7,
      [[
          ANALYZE;
-        UPDATE "_sql_stat1" SET "tbl" = 'no such tbl';
+        UPDATE "_sql_stat1" SET "space_id" = "space_id" + 123456;
      ]])

  test:do_execsql_test(
@@ -1067,25 +1072,6 @@ test:do_execsql_test(
          -- </15.8>
      })

--- Tarantool: this test seems to be useless. There's no reason
--- for these fields to be nullable.
--- test:do_execsql_test(
---    15.9,
---    [[
---        ANALYZE;
---        UPDATE "_sql_stat4" SET "neq" = NULL, "nlt" = NULL, "ndlt" = 
NULL;
---    ]])
-
-test:do_execsql_test(
-    15.10,
-    [[
-        SELECT * FROM x1;
-    ]], {
-        -- <15.10>
-        1, 2, 3, 4, 5, 6
-        -- </15.10>
-    })
-
  -- This is just for coverage....
  test:do_execsql_test(
      15.11,
@@ -1135,6 +1121,7 @@ test:do_test(
          -- <17.1>
          -- </17.1>
      })
+t1 = box.space.T1

  test:do_execsql_test(
      17.2,
@@ -1197,7 +1184,7 @@ test:do_test(
              test:execsql(string.format("INSERT INTO t1 VALUES(%s, 
0);", i))
          end
          test:execsql("ANALYZE")
-        return test:execsql([[ SELECT count(*) FROM "_sql_stat4" WHERE 
"idx" = 'I1'; ]])
+        return test:execsql(string.format('SELECT count(*) FROM 
"_sql_stat4" WHERE "space_id" = %i AND "index_id" = %i;', 
box.space.T1.id, box.space.T1.index['I1'].id))
      end, {
          -- <18.1>
          9
@@ -1239,12 +1226,13 @@ test:do_execsql_test(
          -- </20.2>
      })

+t1 = box.space.T1
  for i = 0, 15 do
      test:do_test(
          "20.3."..i,
          function()
              return test:execsql(string.format(
-                [[SELECT count(*) FROM "_sql_stat4" WHERE "idx" = 'I1' 
AND lrange(msgpack_decode_sample("sample"), 1, 1) = '%s']], i))
+                [[SELECT count(*) FROM "_sql_stat4" WHERE "space_id" = 
%i AND "index_id" = %i AND lrange(msgpack_decode_sample("sample"), 1, 1) 
= '%s']], t1.id, t1.index['I1'].id, i))
          end, {
              1
          })
diff --git a/test/sql-tap/analyzeC.test.lua b/test/sql-tap/analyzeC.test.lua
index 266e37e..31392c8 100755
--- a/test/sql-tap/analyzeC.test.lua
+++ b/test/sql-tap/analyzeC.test.lua
@@ -30,9 +30,7 @@ testprefix = "analyzeC"
  -- Baseline case.  Range queries work OK.  Indexes can be used for
  -- ORDER BY.

-test:do_execsql_test(
-    1.0,
-    [[
+test:execsql([[
          DROP TABLE IF EXISTS t1;
          CREATE TABLE t1(a  INT PRIMARY KEY, b INT , c INT , d INT );
          INSERT INTO t1(a,b,c,d) 
VALUES(1,1,2,3),(2,7,8,9),(3,4,5,6),(4,10,11,12),(5,4,8,12),(6,1,11,111);
@@ -40,10 +38,17 @@ test:do_execsql_test(
          CREATE INDEX t1c ON t1(c);
          ANALYZE;
          DELETE FROM "_sql_stat1";
-        INSERT INTO "_sql_stat1"("tbl","idx","stat") 
VALUES('t1','t1b','12345 2'),('t1','t1c','12345 4');
+    ]]
+)
+t1 = box.space.T1
+
+test:do_execsql_test(
+    1.0,
+    string.format([[
+        INSERT INTO "_sql_stat1"("space_id","index_id","stat") 
VALUES(%i,1,'12345 2'),(%i,2,'12345 4');
          ANALYZE;
          SELECT b,c,d, '#' FROM t1 WHERE b BETWEEN 3 AND 8 ORDER BY d;
-    ]], {
+    ]], t1.id, t1.id), {
          -- <1.0>
          4, 5, 6, "#", 7, 8, 9, "#", 4, 8, 12, "#"
          -- </1.0>
@@ -85,11 +90,12 @@ test:do_execsql_test(
  --
  test:do_execsql_test(
      2.0,
+    string.format(
      [[
-        UPDATE "_sql_stat1" SET "stat"='12345 2 unordered' WHERE 
"idx"='t1b';
+        UPDATE "_sql_stat1" SET "stat"='12345 2 unordered' WHERE 
"index_id"=%i;
          ANALYZE;
          SELECT b, c, d, '#' FROM t1 WHERE b BETWEEN 3 AND 8 ORDER BY d;
-    ]], {
+    ]], box.space.T1.index['T1B'].id), {
          -- <2.0>
          4, 5, 6, "#", 7, 8, 9, "#", 4, 8, 12, "#"
          -- </2.0>
@@ -130,11 +136,12 @@ test:do_execsql_test(
  --
  test:do_execsql_test(
      3.0,
+    string.format(
      [[
-        UPDATE "_sql_stat1" SET "stat"='12345 2 whatever=5 unordered 
xyzzy=11' WHERE "idx"='t1b';
+        UPDATE "_sql_stat1" SET "stat"='12345 2 whatever=5 unordered 
xyzzy=11' WHERE "index_id"=%i;
          ANALYZE;
          SELECT b, c, d, '#' FROM t1 WHERE b BETWEEN 3 AND 8 ORDER BY d;
-    ]], {
+    ]], box.space.T1.index['T1B'].id), {
          -- <3.0>
          4, 5, 6, "#", 7, 8, 9, "#", 4, 8, 12, "#"
          -- </3.0>
@@ -173,17 +180,22 @@ test:do_execsql_test(

  -- The sz=NNN parameter determines which index to scan
  --
-test:do_execsql_test(
-    4.0,
-    [[
+
+test:execsql([[
          DROP INDEX t1b ON t1;
          CREATE INDEX t1bc ON t1(b,c);
          CREATE INDEX t1db ON t1(d,b);
          DELETE FROM "_sql_stat1";
-        INSERT INTO "_sql_stat1"("tbl","idx","stat") 
VALUES('t1','t1bc','12345 3 2 sz=10'),('t1','t1db','12345 3 2 sz=20');
+    ]]
+)
+
+test:do_execsql_test(
+    4.0,
+    string.format([[
+        INSERT INTO "_sql_stat1"("space_id","index_id","stat") 
VALUES(%i,%i,'12345 3 2 sz=10'),(%i,%i,'12345 3 2 sz=20');
          ANALYZE;
          SELECT count(b) FROM t1;
-    ]], {
+    ]], t1.id, t1.index['T1BC'].id, t1.id, t1.index['T1DB'].id), {
          -- <4.0>
          6
          -- </4.0>
@@ -201,12 +213,13 @@ test:do_execsql_test(

  test:do_execsql_test(
      4.2,
+    string.format(
      [[
          DELETE FROM "_sql_stat1";
-        INSERT INTO "_sql_stat1"("tbl","idx","stat") 
VALUES('t1','t1bc','12345 3 2 sz=20'),('t1','t1db','12345 3 2 sz=10');
+        INSERT INTO "_sql_stat1"("space_id","index_id","stat") 
VALUES(%i,%i,'12345 3 2 sz=20'),(%i,%i,'12345 3 2 sz=10');
          ANALYZE;
          SELECT count(b) FROM t1;
-    ]], {
+    ]], t1.id, t1.index['T1BC'].id, t1.id, t1.index['T1DB'].id), {
          -- <4.2>
          6
          -- </4.2>
@@ -227,14 +240,14 @@ test:do_execsql_test(
  --
  test:do_execsql_test(
      5.0,
-    [[
+    string.format([[
          DELETE FROM "_sql_stat1";
-        INSERT INTO "_sql_stat1"("tbl","idx","stat")
-          VALUES('t1','t1bc','12345 3 2 x=5 sz=10 y=10'),
-                ('t1','t1db','12345 3 2 whatever sz=20 junk');
+        INSERT INTO "_sql_stat1"("space_id","index_id","stat")
+          VALUES(%i,%i,'12345 3 2 x=5 sz=10 y=10'),
+                (%i,%i,'12345 3 2 whatever sz=20 junk');
          ANALYZE;
          SELECT count(b) FROM t1;
-    ]], {
+    ]], t1.id, t1.index['T1BC'].id, t1.id, t1.index['T1DB'].id), {
          -- <5.0>
          6
          -- </5.0>
@@ -253,12 +266,12 @@ test:do_execsql_test(

  test:do_execsql_test(
      5.2,
-    [[
+    string.format([[
          DELETE FROM "_sql_stat1";
-        INSERT INTO "_sql_stat1"("tbl","idx","stat") 
VALUES('t1','t1db','12345 3 2 x=5 sz=10 y=10'), ('t1','t1bc','12345 3 2 
whatever sz=20 junk');
+        INSERT INTO "_sql_stat1"("space_id","index_id","stat") 
VALUES(%i,%i,'12345 3 2 x=5 sz=10 y=10'), (%i,%i,'12345 3 2 whatever 
sz=20 junk');
          ANALYZE;
          SELECT count(b) FROM t1;
-    ]], {
+    ]], t1.id, t1.index['T1BC'].id, t1.id, t1.index['T1DB'].id), {
          -- <5.2>
          6
          -- </5.2>
diff --git a/test/sql-tap/analyzeD.test.lua b/test/sql-tap/analyzeD.test.lua
index 4bce88b..55f6e9d 100755
--- a/test/sql-tap/analyzeD.test.lua
+++ b/test/sql-tap/analyzeD.test.lua
@@ -153,9 +153,9 @@ test:do_catchsql_test(

  test:do_execsql_test(
      "analyzeD-1.10",
-    [[
-        SELECT * FROM "_sql_stat4" WHERE "tbl" = 'v';
-    ]], {
+    string.format([[
+        SELECT * FROM "_sql_stat4" WHERE "space_id" = %i;
+    ]], box.space.V.id), {
          -- <analyzeD-1.10>

          -- <analyzeD-1.10>
@@ -163,9 +163,9 @@ test:do_execsql_test(

  test:do_execsql_test(
      "analyzeD-1.11",
-    [[
-        SELECT * FROM "_sql_stat1" WHERE "tbl" = 'v';
-    ]], {
+    string.format([[
+        SELECT * FROM "_sql_stat1" WHERE "space_id" = %i;
+    ]], box.space.V.id), {
          -- <analyzeD-1.11>

          -- <analyzeD-1.11>
@@ -183,9 +183,9 @@ test:do_catchsql_test(

  test:do_execsql_test(
      "analyzeD-1.13",
-    [[
-        SELECT * FROM "_sql_stat4" WHERE "tbl" = 'v';
-    ]], {
+    string.format([[
+        SELECT * FROM "_sql_stat4" WHERE "space_id" = %i;
+    ]], box.space.V.id), {
          -- <analyzeD-1.13>

          -- <analyzeD-1.13>
@@ -193,9 +193,9 @@ test:do_execsql_test(

  test:do_execsql_test(
      "analyzeD-1.14",
-    [[
-        SELECT * FROM "_sql_stat1" WHERE "tbl" = 'v';
-    ]], {
+    string.format([[
+        SELECT * FROM "_sql_stat1" WHERE "space_id" = %i;
+    ]], box.space.V.id), {
          -- <analyzeD-1.14>

          -- <analyzeD-1.14>
diff --git a/test/sql-tap/gh-3350-skip-scan.test.lua 
b/test/sql-tap/gh-3350-skip-scan.test.lua
index 4cecfe0..640075e 100755
--- a/test/sql-tap/gh-3350-skip-scan.test.lua
+++ b/test/sql-tap/gh-3350-skip-scan.test.lua
@@ -77,9 +77,7 @@ test:do_execsql_test(
          }
  )

-test:do_execsql_test(
-        "skip-scan-1.4",
-        [[
+test:execsql([[
              DROP TABLE IF EXISTS t1;
              CREATE TABLE t1(id INTEGER PRIMARY KEY, a TEXT, b INT, c 
INT, d INT);
              CREATE INDEX t1abc ON t1(a,b,c);
@@ -96,10 +94,17 @@ test:do_execsql_test(
              ANALYZE;
              DELETE FROM "_sql_stat1";
              DELETE FROM "_sql_stat4";
-            INSERT INTO "_sql_stat1" VALUES('T1','T1ABC','10000 5000 
2000 10');
+        ]]
+)
+
+test:do_execsql_test(
+        "skip-scan-1.4",
+        string.format(
+        [[
+            INSERT INTO "_sql_stat1" VALUES(%i,%i,'10000 5000 2000 10');
              ANALYZE t2;
              SELECT a,b,c,d FROM t1 WHERE b=345;
-        ]], {
+        ]], box.space.T1.id, box.space.T1.index['T1ABC'].id), {
              "abc", 345, 7, 8, "def", 345, 9, 10
          }
  )
diff --git a/test/sql/sql-statN-index-drop.result 
b/test/sql/sql-statN-index-drop.result
index 7605951..b31dc81 100644
--- a/test/sql/sql-statN-index-drop.result
+++ b/test/sql/sql-statN-index-drop.result
@@ -31,36 +31,36 @@ box.sql.execute("ANALYZE;")
  ---
  ...
  -- Checking the data.
-box.sql.execute("SELECT * FROM \"_sql_stat4\";")
+box.sql.execute('SELECT "index_id","neq","nlt","ndlt","sample" FROM 
"_sql_stat4";')
  ---
-- - ['T1', 'I1', '1', '0', '0', !!binary kQI=]
-  - ['T1', 'T1', '1', '0', '0', !!binary kQE=]
-  - ['T2', 'I1', '1', '0', '0', !!binary kQI=]
-  - ['T2', 'T2', '1', '0', '0', !!binary kQE=]
+- - [0, '1', '0', '0', !!binary kQE=]
+  - [1, '1', '0', '0', !!binary kQI=]
+  - [0, '1', '0', '0', !!binary kQE=]
+  - [1, '1', '0', '0', !!binary kQI=]
  ...
-box.sql.execute("SELECT * FROM \"_sql_stat1\";")
+box.sql.execute('SELECT "index_id","stat" FROM "_sql_stat1";')
  ---
-- - ['T1', 'I1', '1 1']
-  - ['T1', 'T1', '1 1']
-  - ['T2', 'I1', '1 1']
-  - ['T2', 'T2', '1 1']
+- - [0, '1 1']
+  - [1, '1 1']
+  - [0, '1 1']
+  - [1, '1 1']
  ...
  -- Dropping an index.
  box.sql.execute("DROP INDEX i1 ON t1;")
  ---
  ...
  -- Checking the DROP INDEX results.
-box.sql.execute("SELECT * FROM \"_sql_stat4\";")
+box.sql.execute('SELECT "index_id","neq","nlt","ndlt","sample" FROM 
"_sql_stat4";')
  ---
-- - ['T1', 'T1', '1', '0', '0', !!binary kQE=]
-  - ['T2', 'I1', '1', '0', '0', !!binary kQI=]
-  - ['T2', 'T2', '1', '0', '0', !!binary kQE=]
+- - [0, '1', '0', '0', !!binary kQE=]
+  - [0, '1', '0', '0', !!binary kQE=]
+  - [1, '1', '0', '0', !!binary kQI=]
  ...
-box.sql.execute("SELECT * FROM \"_sql_stat1\";")
+box.sql.execute('SELECT "index_id","stat" FROM "_sql_stat1";')
  ---
-- - ['T1', 'T1', '1 1']
-  - ['T2', 'I1', '1 1']
-  - ['T2', 'T2', '1 1']
+- - [0, '1 1']
+  - [0, '1 1']
+  - [1, '1 1']
  ...
  --Cleaning up.
  box.sql.execute("DROP TABLE t1;")
@@ -93,36 +93,36 @@ box.sql.execute("ANALYZE;")
  ---
  ...
  -- Checking the data.
-box.sql.execute("SELECT * FROM \"_sql_stat4\";")
+box.sql.execute('SELECT "index_id","neq","nlt","ndlt","sample" FROM 
"_sql_stat4";')
  ---
-- - ['T1', 'I1', '1', '0', '0', !!binary kQI=]
-  - ['T1', 'T1', '1', '0', '0', !!binary kQE=]
-  - ['T2', 'I1', '1', '0', '0', !!binary kQI=]
-  - ['T2', 'T2', '1', '0', '0', !!binary kQE=]
+- - [0, '1', '0', '0', !!binary kQE=]
+  - [1, '1', '0', '0', !!binary kQI=]
+  - [0, '1', '0', '0', !!binary kQE=]
+  - [1, '1', '0', '0', !!binary kQI=]
  ...
-box.sql.execute("SELECT * FROM \"_sql_stat1\";")
+box.sql.execute('SELECT "index_id","stat" FROM "_sql_stat1";')
  ---
-- - ['T1', 'I1', '1 1']
-  - ['T1', 'T1', '1 1']
-  - ['T2', 'I1', '1 1']
-  - ['T2', 'T2', '1 1']
+- - [0, '1 1']
+  - [1, '1 1']
+  - [0, '1 1']
+  - [1, '1 1']
  ...
  -- Dropping an index.
  box.sql.execute("DROP INDEX i1 ON t2;")
  ---
  ...
  -- Checking the DROP INDEX results.
-box.sql.execute("SELECT * FROM \"_sql_stat4\";")
+box.sql.execute('SELECT "index_id","neq","nlt","ndlt","sample" FROM 
"_sql_stat4";')
  ---
-- - ['T1', 'I1', '1', '0', '0', !!binary kQI=]
-  - ['T1', 'T1', '1', '0', '0', !!binary kQE=]
-  - ['T2', 'T2', '1', '0', '0', !!binary kQE=]
+- - [0, '1', '0', '0', !!binary kQE=]
+  - [1, '1', '0', '0', !!binary kQI=]
+  - [0, '1', '0', '0', !!binary kQE=]
  ...
-box.sql.execute("SELECT * FROM \"_sql_stat1\";")
+box.sql.execute('SELECT "index_id","stat" FROM "_sql_stat1";')
  ---
-- - ['T1', 'I1', '1 1']
-  - ['T1', 'T1', '1 1']
-  - ['T2', 'T2', '1 1']
+- - [0, '1 1']
+  - [1, '1 1']
+  - [0, '1 1']
  ...
  --Cleaning up.
  box.sql.execute("DROP TABLE t1;")
diff --git a/test/sql/sql-statN-index-drop.test.lua 
b/test/sql/sql-statN-index-drop.test.lua
index 35f2291..9ce77a5 100644
--- a/test/sql/sql-statN-index-drop.test.lua
+++ b/test/sql/sql-statN-index-drop.test.lua
@@ -14,15 +14,15 @@ box.sql.execute("INSERT INTO t2 VALUES(1, 2);")
  box.sql.execute("ANALYZE;")

  -- Checking the data.
-box.sql.execute("SELECT * FROM \"_sql_stat4\";")
-box.sql.execute("SELECT * FROM \"_sql_stat1\";")
+box.sql.execute('SELECT "index_id","neq","nlt","ndlt","sample" FROM 
"_sql_stat4";')
+box.sql.execute('SELECT "index_id","stat" FROM "_sql_stat1";')

  -- Dropping an index.
  box.sql.execute("DROP INDEX i1 ON t1;")

  -- Checking the DROP INDEX results.
-box.sql.execute("SELECT * FROM \"_sql_stat4\";")
-box.sql.execute("SELECT * FROM \"_sql_stat1\";")
+box.sql.execute('SELECT "index_id","neq","nlt","ndlt","sample" FROM 
"_sql_stat4";')
+box.sql.execute('SELECT "index_id","stat" FROM "_sql_stat1";')

  --Cleaning up.
  box.sql.execute("DROP TABLE t1;")
@@ -41,15 +41,15 @@ box.sql.execute("INSERT INTO t2 VALUES(1, 2);")
  box.sql.execute("ANALYZE;")

  -- Checking the data.
-box.sql.execute("SELECT * FROM \"_sql_stat4\";")
-box.sql.execute("SELECT * FROM \"_sql_stat1\";")
+box.sql.execute('SELECT "index_id","neq","nlt","ndlt","sample" FROM 
"_sql_stat4";')
+box.sql.execute('SELECT "index_id","stat" FROM "_sql_stat1";')

  -- Dropping an index.
  box.sql.execute("DROP INDEX i1 ON t2;")

  -- Checking the DROP INDEX results.
-box.sql.execute("SELECT * FROM \"_sql_stat4\";")
-box.sql.execute("SELECT * FROM \"_sql_stat1\";")
+box.sql.execute('SELECT "index_id","neq","nlt","ndlt","sample" FROM 
"_sql_stat4";')
+box.sql.execute('SELECT "index_id","stat" FROM "_sql_stat1";')

  --Cleaning up.
  box.sql.execute("DROP TABLE t1;")
diff --git a/test/sql/upgrade.result b/test/sql/upgrade.result
index 5e7d851..9326209 100644
--- a/test/sql/upgrade.result
+++ b/test/sql/upgrade.result
@@ -30,14 +30,15 @@ box.space._space.index['name']:get('_trigger')
  ...
  box.space._space.index['name']:get('_sql_stat1')
  ---
-- [348, 1, '_sql_stat1', 'memtx', 0, {}, [{'name': 'tbl', 'type': 
'string'}, {'name': 'idx',
-      'type': 'string'}, {'name': 'stat', 'type': 'string'}]]
+- [348, 1, '_sql_stat1', 'memtx', 0, {}, [{'name': 'space_id', 'type': 
'unsigned'},
+    {'name': 'index_id', 'type': 'unsigned'}, {'name': 'stat', 'type': 
'string'}]]
  ...
  box.space._space.index['name']:get('_sql_stat4')
  ---
-- [349, 1, '_sql_stat4', 'memtx', 0, {}, [{'name': 'tbl', 'type': 
'string'}, {'name': 'idx',
-      'type': 'string'}, {'name': 'neq', 'type': 'string'}, {'name': 
'nlt', 'type': 'string'},
-    {'name': 'ndlt', 'type': 'string'}, {'name': 'sample', 'type': 
'scalar'}]]
+- [349, 1, '_sql_stat4', 'memtx', 0, {}, [{'name': 'space_id', 'type': 
'unsigned'},
+    {'name': 'index_id', 'type': 'unsigned'}, {'name': 'neq', 'type': 
'string'}, {
+      'name': 'nlt', 'type': 'string'}, {'name': 'ndlt', 'type': 
'string'}, {'name': 'sample',
+      'type': 'scalar'}]]
  ...
  box.space._index:get({box.space._space.index['name']:get('_trigger').id, 0})
  ---
@@ -45,12 +46,12 @@ 
box.space._index:get({box.space._space.index['name']:get('_trigger').id, 0})
  ...
  box.space._index:get({box.space._space.index['name']:get('_sql_stat1').id, 0})
  ---
-- [348, 0, 'primary', 'tree', {'unique': true}, [[0, 'string'], [1, 
'string']]]
+- [348, 0, 'primary', 'tree', {'unique': true}, [[0, 'unsigned'], [1, 
'unsigned']]]
  ...
  box.space._index:get({box.space._space.index['name']:get('_sql_stat4').id, 0})
  ---
-- [349, 0, 'primary', 'tree', {'unique': true}, [[0, 'string'], [1, 
'string'], [5,
-      'scalar']]]
+- [349, 0, 'primary', 'tree', {'unique': true}, [[0, 'unsigned'], [1, 
'unsigned'],
+    [5, 'scalar']]]
  ...
  box.space._schema:format()
  ---


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

      parent reply	other threads:[~2018-12-08 12:40 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-31 10:39 [tarantool-patches] " imeevma
2018-09-05 23:13 ` [tarantool-patches] " n.pettik
2018-09-07 16:49   ` Imeev Mergen
2018-09-30 23:40     ` n.pettik
2018-10-01 11:20       ` n.pettik
2018-10-02 16:42       ` [tarantool-patches] Re[2]: [tarantool-patches] " Мерген Имеев
2018-10-09 12:36         ` [tarantool-patches] " n.pettik
2018-10-10 17:17           ` Imeev Mergen
2018-10-11 11:41             ` n.pettik
2018-10-11 14:56               ` Imeev Mergen
2018-10-11 15:00                 ` n.pettik
2018-11-17 14:09                   ` Imeev Mergen
2018-11-19 10:27                     ` Vladislav Shpilevoy
2018-11-19 10:38                       ` Vladislav Shpilevoy
2018-11-21 16:00                       ` Konstantin Osipov
2018-11-21 16:11                         ` Vladislav Shpilevoy
2018-12-08 12:39                       ` Imeev Mergen [this message]

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=84edbcf1-5a59-d449-70f2-6a93a9a1c11c@tarantool.org \
    --to=imeevma@tarantool.org \
    --cc=korablev@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='[tarantool-patches] Re: [PATCH v2 1/1] sql: hold in stat tables space/index id instead of name' \
    /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