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

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Mon Aug 27 19:32:56 MSK 2018


Hi! Thanks for the patch! See 8 comments below.

On 23/08/2018 06:51, imeevma at tarantool.org wrote:
> There is no reason to hold in statistic tables names of spaces and
> indexes. This patch allows us to save id of space/index instead of
> name.

1. Please, explain why ids are better than names. 'No reason'
is not a reason. Actually the real point of storing ids is to
avoid problems with table and index renaming. Ids are fixed
values on the contrary.

> 
> Closes #3242
> ---
> Branch: https://github.com/tarantool/tarantool/tree/imeevma/gh-3242-hold-ids-in-stat-tables
> Issue: https://github.com/tarantool/tarantool/issues/3242
> 
>   src/box/bootstrap.snap                  | Bin 1818 -> 1822 bytes
>   src/box/lua/upgrade.lua                 |  12 ++--
>   src/box/schema.cc                       |   8 +--
>   src/box/sql.c                           |   8 +--
>   src/box/sql/analyze.c                   | 114 ++++++++++---------------------
>   src/box/sql/build.c                     |  87 +++++++-----------------
>   src/box/sql/sqliteInt.h                 |  10 +--
>   test/box-py/bootstrap.result            |  17 ++---
>   test/box/access_misc.result             |  11 +--
>   test/box/alter.result                   |   6 +-
>   test/sql-tap/analyze1.test.lua          | 100 ++++++++++++++-------------
>   test/sql-tap/analyze4.test.lua          |  79 ++++++++++++----------
>   test/sql-tap/analyze5.test.lua          |  11 +--
>   test/sql-tap/analyze9.test.lua          | 115 ++++++++++++--------------------
>   test/sql-tap/analyzeC.test.lua          |  51 ++++++++------
>   test/sql-tap/analyzeD.test.lua          |  24 +++----
>   test/sql-tap/gh-3350-skip-scan.test.lua |  15 +++--
>   test/sql/sql-statN-index-drop.result    |  72 ++++++++++----------
>   test/sql/sql-statN-index-drop.test.lua  |  16 ++---
>   test/sql/upgrade.result                 |  14 ++--
>   20 files changed, 346 insertions(+), 424 deletions(-)
> 
> diff --git a/src/box/sql/analyze.c b/src/box/sql/analyze.c
> index 00d96d2..86776ad 100644
> --- a/src/box/sql/analyze.c
> +++ b/src/box/sql/analyze.c
> @@ -124,28 +124,27 @@
>    * @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 table_id Delete records of this table if id is not 0.

2. Please, use BOX_ID_NIL constant.

>    */
>   static void
> -vdbe_emit_stat_space_open(struct Parse *parse, int stat_cursor,
> -			  const char *table_name)
> +vdbe_emit_stat_space_open(struct Parse *parse, int stat_cursor, int table_id)

3. Space_id has uint32_t type.

> @@ -837,8 +836,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, regIdxname);

4. regIdxName is not correct now.

>   		VdbeComment((v, "Analysis for %s.%s", pTab->def->name,
>   			    idx_name));
>   
> diff --git a/src/box/sql/build.c b/src/box/sql/build.c
> index dddeb12..0d21ff0 100644
> --- a/src/box/sql/build.c
> +++ b/src/box/sql/build.c
> @@ -1962,75 +1962,27 @@ 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,
> +		     int table_id, int index_id, bool is_index_received)

5. Use index_id == BOX_ID_NIL instead of is_index_received.

>   {
> -	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);
> -}
> @@ -2251,7 +2203,10 @@ 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_remove_from_stat(parse_context, TARANTOOL_SYS_SQL_STAT1_NAME,
> +			     space->def->id, 0, false);
> +	sql_remove_from_stat(parse_context, TARANTOOL_SYS_SQL_STAT4_NAME,
> +			     space->def->id, 0, false);

6. The previous was better. Please, encapsulate list of stat tables
inside a function.

>   	sql_code_drop_table(parse_context, space, is_view);
>   
>    exit_drop_table:
> diff --git a/src/box/sql/sqliteInt.h b/src/box/sql/sqliteInt.h
> index b1f2f26..4ac1dae 100644
> --- a/src/box/sql/sqliteInt.h
> +++ b/src/box/sql/sqliteInt.h
> @@ -4864,11 +4864,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.
> + * Used only if is_index_received is true.

7. Please, align multiple lines by the parameter name. 'Used' should
start at the same position as 'index_id.

> + * @param is_index_received True if index_id is given.
>    */
>   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,
> +		     int table_id, int index_id, bool is_index_received);
>   
>   #endif				/* SQLITEINT_H */
> diff --git a/test/sql-tap/analyzeC.test.lua b/test/sql-tap/analyzeC.test.lua
> index a3cea70..1241ee8 100755
> --- a/test/sql-tap/analyzeC.test.lua
> +++ b/test/sql-tap/analyzeC.test.lua
> @@ -199,14 +209,16 @@ test:do_execsql_test(
>           -- </4.1>
>       })
>   
> +

8. Redundant white space.

>   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"("tbl","idx","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>
> @@ -251,14 +263,15 @@ test:do_execsql_test(
>           -- </5.1>
>       })
>   
> +

Here the same.

>   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"("tbl","idx","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>




More information about the Tarantool-patches mailing list