[tarantool-patches] [PATCH v1 1/6] box: rename space->opts checks to checks_ast

Kirill Shcherbatov kshcherbatov at tarantool.org
Thu Nov 29 16:09:45 MSK 2018


The checks field of space_opts object renamed to checks_ast to avoid a
confusion due to introduction of a new object sql_check, representing
precompiled VDBE program to execute.

Need for #3691
---
 src/box/alter.cc    |  4 ++--
 src/box/space_def.c | 15 ++++++++-------
 src/box/space_def.h |  4 ++--
 src/box/sql.c       |  2 +-
 src/box/sql/build.c | 17 +++++++++--------
 5 files changed, 22 insertions(+), 20 deletions(-)

diff --git a/src/box/alter.cc b/src/box/alter.cc
index 029da029e..3e9b43a54 100644
--- a/src/box/alter.cc
+++ b/src/box/alter.cc
@@ -540,8 +540,8 @@ space_def_new_from_tuple(struct tuple *tuple, uint32_t errcode,
 		space_def_new_xc(id, uid, exact_field_count, name, name_len,
 				 engine_name, engine_name_len, &opts, fields,
 				 field_count);
-	if (def->opts.checks != NULL &&
-	    sql_checks_resolve_space_def_reference(def->opts.checks,
+	if (def->opts.checks_ast != NULL &&
+	    sql_checks_resolve_space_def_reference(def->opts.checks_ast,
 						   def) != 0) {
 		box_error_t *err = box_error_last();
 		if (box_error_code(err) != ENOMEM) {
diff --git a/src/box/space_def.c b/src/box/space_def.c
index 69b92c5c1..585d29e1d 100644
--- a/src/box/space_def.c
+++ b/src/box/space_def.c
@@ -55,7 +55,7 @@ const struct space_opts space_opts_default = {
 	/* .is_temporary = */ false,
 	/* .view = */ false,
 	/* .sql        = */ NULL,
-	/* .checks     = */ NULL,
+	/* .checks_ast     = */ NULL,
 };
 
 const struct opt_def space_opts_reg[] = {
@@ -63,7 +63,7 @@ const struct opt_def space_opts_reg[] = {
 	OPT_DEF("temporary", OPT_BOOL, struct space_opts, is_temporary),
 	OPT_DEF("view", OPT_BOOL, struct space_opts, is_view),
 	OPT_DEF("sql", OPT_STRPTR, struct space_opts, sql),
-	OPT_DEF_ARRAY("checks", struct space_opts, checks,
+	OPT_DEF_ARRAY("checks", struct space_opts, checks_ast,
 		      checks_array_decode),
 	OPT_END,
 };
@@ -112,15 +112,16 @@ space_def_dup_opts(struct space_def *def, const struct space_opts *opts)
 			return -1;
 		}
 	}
-	if (opts->checks != NULL) {
-		def->opts.checks = sql_expr_list_dup(sql_get(), opts->checks, 0);
-		if (def->opts.checks == NULL) {
+	if (opts->checks_ast != NULL) {
+		def->opts.checks_ast =
+			sql_expr_list_dup(sql_get(), opts->checks_ast, 0);
+		if (def->opts.checks_ast == NULL) {
 			free(def->opts.sql);
 			diag_set(OutOfMemory, 0, "sql_expr_list_dup",
 				 "def->opts.checks");
 			return -1;
 		}
-		sql_checks_update_space_def_reference(def->opts.checks, def);
+		sql_checks_update_space_def_reference(def->opts.checks_ast, def);
 	}
 	return 0;
 }
@@ -283,7 +284,7 @@ void
 space_opts_destroy(struct space_opts *opts)
 {
 	free(opts->sql);
-	sql_expr_list_delete(sql_get(), opts->checks);
+	sql_expr_list_delete(sql_get(), opts->checks_ast);
 	TRASH(opts);
 }
 
diff --git a/src/box/space_def.h b/src/box/space_def.h
index 0d1e90233..a9a119e6d 100644
--- a/src/box/space_def.h
+++ b/src/box/space_def.h
@@ -66,8 +66,8 @@ struct space_opts {
 	bool is_view;
 	/** SQL statement that produced this space. */
 	char *sql;
-	/** SQL Checks expressions list. */
-	struct ExprList *checks;
+	/** Checks AST expressions list. */
+	struct ExprList *checks_ast;
 };
 
 extern const struct space_opts space_opts_default;
diff --git a/src/box/sql.c b/src/box/sql.c
index 7b41c9926..2b710fab6 100644
--- a/src/box/sql.c
+++ b/src/box/sql.c
@@ -1204,7 +1204,7 @@ sql_encode_table_opts(struct region *region, struct Table *table,
 	struct ExprList_item *a;
 	if (table != NULL) {
 		is_view = table->def->opts.is_view;
-		struct ExprList *checks = table->def->opts.checks;
+		struct ExprList *checks = table->def->opts.checks_ast;
 		if (checks != NULL) {
 			checks_cnt = checks->nExpr;
 			a = checks->a;
diff --git a/src/box/sql/build.c b/src/box/sql/build.c
index 52f0bde15..7d32f3874 100644
--- a/src/box/sql/build.c
+++ b/src/box/sql/build.c
@@ -276,7 +276,7 @@ table_delete(struct sqlite3 *db, struct Table *tab)
 		for (uint32_t i = 0; i < tab->space->index_count; ++i)
 			index_def_delete(tab->space->index[i]->def);
 		/* Do not delete table->def allocated on region. */
-		sql_expr_list_delete(db, tab->def->opts.checks);
+		sql_expr_list_delete(db, tab->def->opts.checks_ast);
 	} else if (tab->def->id == 0) {
 		space_def_delete(tab->def);
 	}
@@ -863,15 +863,16 @@ sql_add_check_constraint(struct Parse *parser, struct ExprSpan *span)
 					 (int)(span->zEnd - span->zStart));
 		if (expr->u.zToken == NULL)
 			goto release_expr;
-		table->def->opts.checks =
+		table->def->opts.checks_ast =
 			sql_expr_list_append(parser->db,
-					     table->def->opts.checks, expr);
-		if (table->def->opts.checks == NULL) {
+					     table->def->opts.checks_ast, expr);
+		if (table->def->opts.checks_ast == NULL) {
 			sqlite3DbFree(parser->db, expr->u.zToken);
 			goto release_expr;
 		}
 		if (parser->constraintName.n) {
-			sqlite3ExprListSetName(parser, table->def->opts.checks,
+			sqlite3ExprListSetName(parser,
+					       table->def->opts.checks_ast,
 					       &parser->constraintName, 1);
 		}
 	} else {
@@ -947,7 +948,7 @@ space_checks_expr_list(uint32_t space_id)
 	space = space_by_id(space_id);
 	assert(space != NULL);
 	assert(space->def != NULL);
-	return space->def->opts.checks;
+	return space->def->opts.checks_ast;
 }
 
 int
@@ -1610,8 +1611,8 @@ sqlite3EndTable(Parse * pParse,	/* Parse context */
 		vdbe_emit_fkey_create(pParse, fk);
 	}
 cleanup:
-	sql_expr_list_delete(db, p->def->opts.checks);
-	p->def->opts.checks = NULL;
+	sql_expr_list_delete(db, p->def->opts.checks_ast);
+	p->def->opts.checks_ast = NULL;
 }
 
 void
-- 
2.19.2





More information about the Tarantool-patches mailing list