[tarantool-patches] Re: [PATCH v2 1/1] sql: hold in stat tables space/index id instead of name

Imeev Mergen imeevma at tarantool.org
Fri Sep 7 19:49:16 MSK 2018


Hello! Thank you for review.


On 09/06/2018 02:13 AM, n.pettik wrote:
>> diff --git a/src/box/lua/upgrade.lua b/src/box/lua/upgrade.lua
>> index d9c2ae4..bb8dc36 100644
>> --- a/src/box/lua/upgrade.lua
>> +++ b/src/box/lua/upgrade.lua
>> @@ -520,11 +520,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='tbl', type='unsigned'},
>> +                      {name='idx', type='unsigned’},
> Nit: why you didn’t rename these fields to ’space_id’ and ‘index_id’
> (like in _index)? The same for stat4.
Done.
>
>> @@ -793,8 +794,8 @@ analyzeOneTable(Parse * pParse,	/* Parser context */
>> 	int regChng = iMem++;	/* Index of changed index field */
>> 	int regKey = iMem++;	/* Key argument passed to stat_push() */
>> 	int regTemp = iMem++;	/* Temporary use register */
>> -	int regTabname = iMem++;	/* Register containing table name */
>> -	int regIdxname = iMem++;	/* Register containing index name */
>> +	int reg_space_id = iMem++;	/* Register containing table id */
>> +	int reg_index_id = iMem++;	/* Register containing index id */
> Nit: put comments above the code to be commented and put dots
> at the end of comment.
Fixed.
>
>> @@ -1246,24 +1246,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++];
>> -	uint32_t space_id = box_space_id_by_name(argv[0], strlen(argv[0]));
>> +	uint32_t space_id = atoll(argv[0]);
> I would add assertion like:
> assert(space_id != 0);
> Since atoll in case of fail returns 0 and BOX_ID_NIL != 0.
Actually now we cannot get BOX_ID_NIL, but we can get 0. Changed "if"
that placed next line after "atoll".
>
>> 	if (space_id == BOX_ID_NIL)
>> 		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_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);
>> 	assert(index != NULL);
>> 	/*
>> 	 * Additional field is used to describe total
>> @@ -1410,27 +1400,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)
>> -			continue;
>> -		const char *index_name = (char *)sqlite3_column_text(stmt, 1);
>> -		if (index_name == NULL)
>> +		if (sqlite3_column_text(stmt, 0) == NULL ||
>> +		    sqlite3_column_text(stmt, 1) == NULL)
>> 			continue;
>> -		uint32_t sample_count = sqlite3_column_int(stmt, 2);
>> -		uint32_t space_id = box_space_id_by_name(space_name,
>> -							 strlen(space_name));
>> +		uint32_t space_id = sqlite3_column_int(stmt, 0);
> Why do you check on nullability text value, but fetch int?
> It looks suspicious…
> The same for other usages.
Changed, now error occurs on space_id being 0.
>
>> diff --git a/src/box/sql/build.c b/src/box/sql/build.c
>> index a1e16b2..ece1092 100644
>> --- a/src/box/sql/build.c
>> +++ b/src/box/sql/build.c
>> @@ -1888,75 +1888,45 @@ 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)
>> +sql_remove_from_stat(struct Parse *parse, const char *stat_table_name,
>> +		     uint32_t space_id, uint32_t index_id)
> Remove what? Why did you rename function?
Fixed.
>
>> /**
>> - * Remove entries from the _sql_stat1 and _sql_stat4
>> - * system spaces after a DROP INDEX or DROP TABLE command.
>> + * Remove entries from the _sql_stat1 and _sql_stat4 system spaces
>> + * after a DROP INDEX or DROP TABLE command.
> Nit: noise diff.
Fixed.
>
>>   *
>> - * @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 table_name The table to be dropped or the table that
>> + *        contains index to be dropped.
> You forgot to rename args here.
Fixed.
>
>> + * @param idx_name 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);
>> +	sql_remove_from_stat(parse, TARANTOOL_SYS_SQL_STAT1_NAME, space_id,
>> +			     index_id);
>> +	sql_remove_from_stat(parse, TARANTOOL_SYS_SQL_STAT4_NAME, space_id,
>> +			     index_id);
> Don’t use this macros: it is awful and going to disappear.
> Just simply inline name of stat space.
Fixed.
>
>> }
>>
>> /**
>> @@ -2177,7 +2147,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:
>> @@ -3119,11 +3089,12 @@ sql_drop_index(struct Parse *parse_context, struct SrcList *index_name_list,
>> 	}
>>
>> 	/*
>> -	 * Generate code to remove entry from _index space
>> -	 * But firstly, delete statistics since schema
>> -	 * changes after DDL.
>> +	 * Generate code to remove entry from _index space.
>> +	 * But firstly, delete statistics since schema changes
>> +	 * after DDL.
> Nit: again noise diff.
Fixed.
>
>> diff --git a/test/sql-tap/analyze9.test.lua b/test/sql-tap/analyze9.test.lua
>> index 1dbfe5d..2c6b4b8 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(118)
>>
>> -test:do_execsql_test(
>> -    15.7,
>> -    [[
>> -        ANALYZE;
>> -        UPDATE "_sql_stat1" SET "tbl" = 'no such tbl';
>> -    ]])
> Why did you simply delete this test? Rewrite it pls using space id.
Done.
>
>> diff --git a/test/sql/sql-statN-index-drop.result b/test/sql/sql-statN-index-drop.result
>> index a751eca..0e5f2a3 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 "idx","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 "idx","stat" FROM \"_sql_stat1\";’)
> Without space_id/space name this test is less representative.
> The same for other similar tests.
Done.
>

commit 94d83afa5703a7ccf558202df752651646ba9c72
Author: Mergen Imeev <imeevma at 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

diff --git a/src/box/bootstrap.snap b/src/box/bootstrap.snap
index 6573938..54ec5c7 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 d9c2ae4..bc18b49 100644
--- a/src/box/lua/upgrade.lua
+++ b/src/box/lua/upgrade.lua
@@ -520,11 +520,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'},
@@ -536,7 +536,7 @@ local function upgrade_to_2_1_0()

      log.info("create index primary on _sql_stat1")
      _index:insert{box.schema.SQL_STAT1_ID, 0, 'primary', 'tree',
-                  {unique = true}, {{0, 'string'}, {1, 'string'}}}
+                  {unique = true}, {{0, 'unsigned'}, {1, 'unsigned'}}}

      log.info("create space _sql_stat4")
      _space:insert{box.schema.SQL_STAT4_ID, ADMIN, '_sql_stat4', 
'memtx', 0,
@@ -544,7 +544,7 @@ local function upgrade_to_2_1_0()

      log.info("create index primary on _sql_stat4")
      _index:insert{box.schema.SQL_STAT4_ID, 0, 'primary', 'tree',
-                  {unique = true}, {{0, 'string'}, {1, 'string'},
+                  {unique = true}, {{0, 'unsigned'}, {1, 'unsigned'},
                                      {5, 'scalar'}}}

      local fk_constr_ft = {{name='name', type='string'},
diff --git a/src/box/schema.cc b/src/box/schema.cc
index a6e413a..8b71d65 100644
--- a/src/box/schema.cc
+++ b/src/box/schema.cc
@@ -383,13 +383,13 @@ schema_init()
      sc_space_new(BOX_INDEX_ID, "_index", key_def,
               &alter_space_on_replace_index, &on_stmt_begin_index);

-    /* space name */
+    /* space id */
      key_def_set_part(key_def, 0 /* part no */, 0 /* field no */,
-             FIELD_TYPE_STRING, ON_CONFLICT_ACTION_DEFAULT, NULL,
+             FIELD_TYPE_UNSIGNED, ON_CONFLICT_ACTION_DEFAULT, NULL,
               COLL_NONE, SORT_ORDER_ASC);
-    /* index name */
+    /* index id */
      key_def_set_part(key_def, 1 /* part no */, 1 /* field no */,
-             FIELD_TYPE_STRING, ON_CONFLICT_ACTION_DEFAULT, NULL,
+             FIELD_TYPE_UNSIGNED, ON_CONFLICT_ACTION_DEFAULT, NULL,
               COLL_NONE, SORT_ORDER_ASC);
      /* _sql_stat1 - a simpler statistics on space, seen in SQL. */
      sc_space_new(BOX_SQL_STAT1_ID, "_sql_stat1", key_def, NULL, NULL);
@@ -399,13 +399,13 @@ schema_init()
      if (key_def == NULL)
          diag_raise();

-    /* space name */
+    /* space id */
      key_def_set_part(key_def, 0 /* part no */, 0 /* field no */,
-             FIELD_TYPE_STRING, ON_CONFLICT_ACTION_DEFAULT, NULL,
+             FIELD_TYPE_UNSIGNED, ON_CONFLICT_ACTION_DEFAULT, NULL,
               COLL_NONE, SORT_ORDER_ASC);
-    /* index name */
+    /* index id */
      key_def_set_part(key_def, 1 /* part no */, 1 /* field no */,
-             FIELD_TYPE_STRING, ON_CONFLICT_ACTION_DEFAULT, NULL,
+             FIELD_TYPE_UNSIGNED, ON_CONFLICT_ACTION_DEFAULT, NULL,
               COLL_NONE, SORT_ORDER_ASC);
      /* sample */
      key_def_set_part(key_def, 2 /* part no */, 5 /* field no */,
diff --git a/src/box/sql.c b/src/box/sql.c
index b158c50..87f2088 100644
--- a/src/box/sql.c
+++ b/src/box/sql.c
@@ -1217,21 +1217,21 @@ void tarantoolSqlite3LoadSchema(struct init_data 
*init)
      sql_init_callback(init, TARANTOOL_SYS_SQL_STAT1_NAME,
                BOX_SQL_STAT1_ID, 0,
                "CREATE TABLE \""TARANTOOL_SYS_SQL_STAT1_NAME
-                   "\"(\"tbl\" text,"
-                   "\"idx\" text,"
+                   "\"(\"space_id\" INT,"
+                   "\"index_id\" INT,"
                     "\"stat\" not null,"
-                   "PRIMARY KEY(\"tbl\", \"idx\"))");
+                   "PRIMARY KEY(\"space_id\", \"index_id\"))");

      sql_init_callback(init, TARANTOOL_SYS_SQL_STAT4_NAME,
                BOX_SQL_STAT4_ID, 0,
                "CREATE TABLE \""TARANTOOL_SYS_SQL_STAT4_NAME
-                   "\"(\"tbl\" text,"
-                   "\"idx\" text,"
+                   "\"(\"space_id\" INT,"
+                   "\"index_id\" INT,"
                     "\"neq\" text,"
                     "\"nlt\" text,"
                     "\"ndlt\" text,"
                     "\"sample\","
-                   "PRIMARY KEY(\"tbl\", \"idx\", \"sample\"))");
+                   "PRIMARY KEY(\"space_id\", \"index_id\", \"sample\"))");

      sql_init_callback(init, TARANTOOL_SYS_FK_CONSTRAINT_NAME,
                BOX_FK_CONSTRAINT_ID, 0,
diff --git a/src/box/sql/analyze.c b/src/box/sql/analyze.c
index 76ae153..6938dcb 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
+ * name in the index_id column.  The space_id column is the name of the 
table 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 
table of
+ * the index. If the index_id and space_id columns are the same, 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
@@ -124,11 +124,12 @@
   * @param parse Parsing context.
   * @param stat_cursor Open the _sql_stat1 table on this cursor.
   *        you should allocate |stat_names| cursors before call.
- * @param table_name Delete records of this index 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, int stat_cursor,
-              const char *table_name)
+              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};
@@ -136,16 +137,15 @@ vdbe_emit_stat_space_open(struct Parse *parse, int 
stat_cursor,
      assert(v != NULL);
      assert(sqlite3VdbeDb(v) == parse->db);
      for (uint i = 0; i < lengthof(stat_names); ++i) {
-        const char *space_name = stat_names[i];
          /*
           * The table already exists, because it is a
           * system space.
           */
assert(sqlite3HashFind(&parse->db->pSchema->tblHash,
-                       space_name) != NULL);
-        if (table_name != NULL) {
-            vdbe_emit_stat_space_clear(parse, space_name, NULL,
-                           table_name);
+                       stat_names[i]) != NULL);
+        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]);
          }
@@ -793,8 +793,10 @@ analyzeOneTable(Parse * pParse,    /* Parser context */
      int regChng = iMem++;    /* Index of changed index field */
      int regKey = iMem++;    /* Key argument passed to stat_push() */
      int regTemp = iMem++;    /* Temporary use register */
-    int regTabname = iMem++;    /* Register containing table name */
-    int regIdxname = iMem++;    /* Register containing index name */
+    /* Register containing table id. */
+    int reg_space_id = iMem++;
+    /* Register containing index id. */
+    int reg_index_id = iMem++;
      int regStat1 = iMem++;    /* Value for the stat column of 
_sql_stat1 */
      int regPrev = iMem;    /* MUST BE LAST (see below) */

@@ -818,7 +820,7 @@ analyzeOneTable(Parse * pParse,    /* Parser context */
      iIdxCur = iTab++;
      pParse->nTab = MAX(pParse->nTab, iTab);
      sqlite3OpenTable(pParse, iTabCur, pTab, OP_OpenRead);
-    sqlite3VdbeLoadString(v, regTabname, pTab->def->name);
+    sqlite3VdbeAddOp2(v, OP_Integer, pTab->def->id, reg_space_id);

      for (pIdx = pTab->pIndex; pIdx; pIdx = pIdx->pNext) {
          int addrRewind;    /* Address of "OP_Rewind iIdxCur" */
@@ -837,8 +839,8 @@ analyzeOneTable(Parse * pParse,    /* Parser context */
              idx_name = pIdx->def->name;
          int part_count = pIdx->def->key_def->part_count;

-        /* Populate the register containing the index name. */
-        sqlite3VdbeLoadString(v, regIdxname, idx_name);
+        /* Populate the register containing the index id. */
+        sqlite3VdbeAddOp2(v, OP_Integer, pIdx->def->iid, reg_index_id);
          VdbeComment((v, "Analysis for %s.%s", pTab->def->name,
                  idx_name));

@@ -1015,9 +1017,8 @@ analyzeOneTable(Parse * pParse,    /* Parser 
context */

          /* Add the entry to the stat1 table. */
          callStatGet(v, regStat4, STAT_GET_STAT1, regStat1);
-        assert("BBB"[0] == AFFINITY_TEXT);
-        sqlite3VdbeAddOp4(v, OP_MakeRecord, regTabname, 3, regTemp,
-                  "BBB", 0);
+        sqlite3VdbeAddOp4(v, OP_MakeRecord, reg_space_id, 3, regTemp,
+                  "DDB", 0);
          sqlite3VdbeAddOp2(v, OP_IdxInsert, iStatCur, regTemp);

          /* Add the entries to the stat4 table. */
@@ -1053,7 +1054,7 @@ analyzeOneTable(Parse * pParse,    /* Parser 
context */
          }
          sqlite3VdbeAddOp3(v, OP_MakeRecord, regCol, part_count,
                    regSample);
-        sqlite3VdbeAddOp3(v, OP_MakeRecord, regTabname, 6, regTemp);
+        sqlite3VdbeAddOp3(v, OP_MakeRecord, reg_space_id, 6, regTemp);
          sqlite3VdbeAddOp2(v, OP_IdxReplace, iStatCur + 1, regTemp);
          sqlite3VdbeAddOp2(v, OP_Goto, 1, addrNext);    /* P1==1 for 
end-of-loop */
          sqlite3VdbeJumpHere(v, addrIsNull);
@@ -1086,7 +1087,7 @@ sql_analyze_database(Parse *parser)
      sql_set_multi_write(parser, false);
      int stat_cursor = parser->nTab;
      parser->nTab += 3;
-    vdbe_emit_stat_space_open(parser, stat_cursor, NULL);
+    vdbe_emit_stat_space_open(parser, stat_cursor, BOX_ID_NIL);
      int reg = parser->nMem + 1;
      int tab_cursor = parser->nTab;
      for (struct HashElem *k = sqliteHashFirst(&schema->tblHash); k != 
NULL;
@@ -1114,7 +1115,7 @@ vdbe_emit_analyze_table(struct Parse *parse, 
struct Table *table)
      sql_set_multi_write(parse, false);
      int stat_cursor = parse->nTab;
      parse->nTab += 3;
-    vdbe_emit_stat_space_open(parse, stat_cursor, table->def->name);
+    vdbe_emit_stat_space_open(parse, stat_cursor, table->def->id);
      analyzeOneTable(parse, table, NULL, stat_cursor, parse->nMem + 1,
              parse->nTab);
      loadAnalysis(parse);
@@ -1246,24 +1247,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++];
-    uint32_t space_id = box_space_id_by_name(argv[0], strlen(argv[0]));
-    if (space_id == BOX_ID_NIL)
+    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_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);
      assert(index != NULL);
      /*
       * Additional field is used to describe total
@@ -1377,8 +1368,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
@@ -1410,27 +1405,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);
-        uint32_t space_id = box_space_id_by_name(space_name,
-                             strlen(space_name));
-        assert(space_id != BOX_ID_NIL);
+        uint32_t space_id = sqlite3_column_int(stmt, 0);
+        assert(space_id != BOX_ID_NIL && space_id != 0);
          struct space *space = space_by_id(space_id);
          assert(space != NULL);
-        struct index *index;
-        uint32_t iid = box_index_id_by_name(space_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);
+        uint32_t iid = sqlite3_column_int(stmt, 1);
+        struct index *index = space_index(space, iid);
          assert(index != NULL);
+        uint32_t sample_count = sqlite3_column_int(stmt, 2);
          uint32_t column_count = index->def->key_def->part_count;
          struct index_stat *stat = &stats[current_idx_count];
          stat->sample_field_count = column_count;
@@ -1482,27 +1464,12 @@ 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)
-            continue;
-        const char *index_name = (char *)sqlite3_column_text(stmt, 1);
-        if (index_name == NULL)
-            continue;
-        uint32_t space_id = box_space_id_by_name(space_name,
-                             strlen(space_name));
-        assert(space_id != BOX_ID_NIL);
+        uint32_t space_id = sqlite3_column_int(stmt, 0);
+        assert(space_id != BOX_ID_NIL && space_id != 0);
          struct space *space = space_by_id(space_id);
          assert(space != NULL);
-        struct index *index;
-        uint32_t iid = box_index_id_by_name(space_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);
+        struct index *index = space_index(space, iid);
          assert(index != NULL);
          uint32_t column_count = index->def->key_def->part_count;
          if (index != prev_index) {
@@ -1566,28 +1533,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;
-        uint32_t space_id = box_space_id_by_name(space_name,
-                             strlen(space_name));
-        if (space_id == BOX_ID_NIL)
+        uint32_t space_id = sqlite3_column_int(stmt, 0);
+        if (space_id == BOX_ID_NIL || 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_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);
+        struct index *index = space_index(space, iid);
          assert(index != NULL);
          free(index->def->opts.stat);
          index->def->opts.stat = stats[current_idx_count++];
@@ -1727,7 +1679,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;
@@ -1740,10 +1692,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)
@@ -1787,8 +1739,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 a1e16b2..5aea4ea 100644
--- a/src/box/sql/build.c
+++ b/src/box/sql/build.c
@@ -1888,75 +1888,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);
  }

  /**
@@ -2177,7 +2145,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:
@@ -3123,7 +3091,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_id, space_id_reg);
diff --git a/src/box/sql/sqliteInt.h b/src/box/sql/sqliteInt.h
index 1d32c9a..9bfa259 100644
--- a/src/box/sql/sqliteInt.h
+++ b/src/box/sql/sqliteInt.h
@@ -4862,11 +4862,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..b5850c2 100644
--- a/test/box-py/bootstrap.result
+++ b/test/box-py/bootstrap.result
@@ -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 87ccc46..a55ec49 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 dab7255..afd8901 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,7 +369,7 @@ 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 DISTINCT "name" FROM "_sql_stat1" JOIN "_space" ON 
"_sql_stat1"."space_id" = "_space"."id" ORDER BY 1;
      ]], {
          -- <analyze-5.0>
          "T3", "T4"
@@ -377,10 +379,10 @@ test:do_execsql_test(
  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,18 +391,18 @@ stat = "_sql_stat4"
  test:do_execsql_test(
      "analyze-5.1",
      string.format([[
-            SELECT DISTINCT "idx" FROM "%s" ORDER BY 1;
+            SELECT DISTINCT "index_id" FROM "%s" ORDER BY 1;
          ]], stat, 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 DISTINCT "name" FROM "%s" JOIN "_space" ON 
"%s"."space_id" = "_space"."id" ORDER BY 1;
+        ]], stat, stat, stat), {
          -- <analyze-5.1>
          "T3", "T4"
          -- </analyze-5.1>
@@ -411,17 +413,17 @@ 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 DISTINCT "name" FROM "_sql_stat1" JOIN "_space" ON 
"_sql_stat1"."space_id" = "_space"."id" ORDER BY 1;
      ]], {
          -- <analyze-5.2>
          "T3", "T4"
@@ -431,18 +433,18 @@ test:do_execsql_test(
  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 DISTINCT "name" FROM "%s" JOIN "_space" ON 
"%s"."space_id" = "_space"."id" ORDER BY 1;
+        ]], stat, stat, stat), {
          -- <analyze-5.3>
          "T3", "T4"
          -- </analyze-5.3>
@@ -453,17 +455,17 @@ 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 DISTINCT "name" FROM "_sql_stat1" JOIN "_space" ON 
"_sql_stat1"."space_id" = "_space"."id" ORDER BY 1;
      ]], {
          -- <analyze-5.4>
          "T4"
@@ -473,18 +475,18 @@ test:do_execsql_test(
  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 DISTINCT "name" FROM "%s" JOIN "_space" ON 
"%s"."space_id" = "_space"."id" ORDER BY 1;
+        ]], stat, stat), {
          -- <analyze-5.5>
          "T4"
          -- </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 c2cc190..d64cba8 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,b,c DEFAULT 
NULL,d 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,b,c 
DEFAULT NULL,d 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 d68bd3c..ece26e4 100755
--- a/test/sql-tap/analyze5.test.lua
+++ b/test/sql-tap/analyze5.test.lua
@@ -114,10 +114,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"
@@ -143,10 +144,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 1dbfe5d..d105c6f 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", 
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(22.0, 'some text');
          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>
-        "some text 14", "22 some text", "some text", 22
+        22, "22 some text", "some text", "some text 14"
          -- </2.1>
      })

@@ -116,6 +116,7 @@ test:do_execsql_test(
          CREATE TABLE t2(id INTEGER PRIMARY KEY AUTOINCREMENT, a, b);
          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, b, c);
          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>
      })

@@ -394,6 +397,8 @@ test:do_execsql_test(
          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, b);
          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 PRIMARY KEY, b, 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', 0, 0, 0, '');
-    ]])
+        INSERT INTO "_sql_stat4" VALUES(%i,  12345, 0, 0, 0, '');
+    ]], x1.id))

  test:do_execsql_test(
      15.2,
@@ -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 a3cea70..e772d71 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 PRIMARY KEY, b, c, d);
          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 ef6aced..9d89933 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 301b04a..917c74c 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 a751eca..cd35d3b 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 "name","index_id","neq","nlt","ndlt","sample" 
FROM "_sql_stat4" join "_space" on "_sql_stat4"."space_id" = 
"_space"."id";')
  ---
-- - ['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=]
+- - ['T1', 0, '1', '0', '0', !!binary kQE=]
+  - ['T1', 1, '1', '0', '0', !!binary kQI=]
+  - ['T2', 0, '1', '0', '0', !!binary kQE=]
+  - ['T2', 1, '1', '0', '0', !!binary kQI=]
  ...
-box.sql.execute("SELECT * FROM \"_sql_stat1\";")
+box.sql.execute('SELECT "name","index_id","stat" FROM "_sql_stat1" join 
"_space" on "_sql_stat1"."space_id" = "_space"."id";')
  ---
-- - ['T1', 'I1', '1 1']
-  - ['T1', 'T1', '1 1']
-  - ['T2', 'I1', '1 1']
-  - ['T2', 'T2', '1 1']
+- - ['T1', 0, '1 1']
+  - ['T1', 1, '1 1']
+  - ['T2', 0, '1 1']
+  - ['T2', 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 "name","index_id","neq","nlt","ndlt","sample" 
FROM "_sql_stat4" join "_space" on "_sql_stat4"."space_id" = 
"_space"."id";')
  ---
-- - ['T1', 'T1', '1', '0', '0', !!binary kQE=]
-  - ['T2', 'I1', '1', '0', '0', !!binary kQI=]
-  - ['T2', 'T2', '1', '0', '0', !!binary kQE=]
+- - ['T1', 0, '1', '0', '0', !!binary kQE=]
+  - ['T2', 0, '1', '0', '0', !!binary kQE=]
+  - ['T2', 1, '1', '0', '0', !!binary kQI=]
  ...
-box.sql.execute("SELECT * FROM \"_sql_stat1\";")
+box.sql.execute('SELECT "name","index_id","stat" FROM "_sql_stat1" join 
"_space" on "_sql_stat1"."space_id" = "_space"."id";')
  ---
-- - ['T1', 'T1', '1 1']
-  - ['T2', 'I1', '1 1']
-  - ['T2', 'T2', '1 1']
+- - ['T1', 0, '1 1']
+  - ['T2', 0, '1 1']
+  - ['T2', 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 "name","index_id","neq","nlt","ndlt","sample" 
FROM "_sql_stat4" join "_space" on "_sql_stat4"."space_id" = 
"_space"."id";')
  ---
-- - ['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=]
+- - ['T1', 0, '1', '0', '0', !!binary kQE=]
+  - ['T1', 1, '1', '0', '0', !!binary kQI=]
+  - ['T2', 0, '1', '0', '0', !!binary kQE=]
+  - ['T2', 1, '1', '0', '0', !!binary kQI=]
  ...
-box.sql.execute("SELECT * FROM \"_sql_stat1\";")
+box.sql.execute('SELECT "name","index_id","stat" FROM "_sql_stat1" join 
"_space" on "_sql_stat1"."space_id" = "_space"."id";')
  ---
-- - ['T1', 'I1', '1 1']
-  - ['T1', 'T1', '1 1']
-  - ['T2', 'I1', '1 1']
-  - ['T2', 'T2', '1 1']
+- - ['T1', 0, '1 1']
+  - ['T1', 1, '1 1']
+  - ['T2', 0, '1 1']
+  - ['T2', 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 "name","index_id","neq","nlt","ndlt","sample" 
FROM "_sql_stat4" join "_space" on "_sql_stat4"."space_id" = 
"_space"."id";')
  ---
-- - ['T1', 'I1', '1', '0', '0', !!binary kQI=]
-  - ['T1', 'T1', '1', '0', '0', !!binary kQE=]
-  - ['T2', 'T2', '1', '0', '0', !!binary kQE=]
+- - ['T1', 0, '1', '0', '0', !!binary kQE=]
+  - ['T1', 1, '1', '0', '0', !!binary kQI=]
+  - ['T2', 0, '1', '0', '0', !!binary kQE=]
  ...
-box.sql.execute("SELECT * FROM \"_sql_stat1\";")
+box.sql.execute('SELECT "name","index_id","stat" FROM "_sql_stat1" join 
"_space" on "_sql_stat1"."space_id" = "_space"."id";')
  ---
-- - ['T1', 'I1', '1 1']
-  - ['T1', 'T1', '1 1']
-  - ['T2', 'T2', '1 1']
+- - ['T1', 0, '1 1']
+  - ['T1', 1, '1 1']
+  - ['T2', 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 fe7e15b..dacc1eb 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 "name","index_id","neq","nlt","ndlt","sample" 
FROM "_sql_stat4" join "_space" on "_sql_stat4"."space_id" = 
"_space"."id";')
+box.sql.execute('SELECT "name","index_id","stat" FROM "_sql_stat1" join 
"_space" on "_sql_stat1"."space_id" = "_space"."id";')

  -- 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 "name","index_id","neq","nlt","ndlt","sample" 
FROM "_sql_stat4" join "_space" on "_sql_stat4"."space_id" = 
"_space"."id";')
+box.sql.execute('SELECT "name","index_id","stat" FROM "_sql_stat1" join 
"_space" on "_sql_stat1"."space_id" = "_space"."id";')

  --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 "name","index_id","neq","nlt","ndlt","sample" 
FROM "_sql_stat4" join "_space" on "_sql_stat4"."space_id" = 
"_space"."id";')
+box.sql.execute('SELECT "name","index_id","stat" FROM "_sql_stat1" join 
"_space" on "_sql_stat1"."space_id" = "_space"."id";')

  -- 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 "name","index_id","neq","nlt","ndlt","sample" 
FROM "_sql_stat4" join "_space" on "_sql_stat4"."space_id" = 
"_space"."id";')
+box.sql.execute('SELECT "name","index_id","stat" FROM "_sql_stat1" join 
"_space" on "_sql_stat1"."space_id" = "_space"."id";')

  --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()
  ---







More information about the Tarantool-patches mailing list