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

  • From: Kirill Shcherbatov <kshcherbatov@xxxxxxxxxxxxx>
  • To: tarantool-patches@xxxxxxxxxxxxx, korablev@xxxxxxxxxxxxx
  • Date: Thu, 10 Jan 2019 16:54:47 +0300

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 0589c9678..dcbb1ca66 100644
--- a/src/box/alter.cc
+++ b/src/box/alter.cc
@@ -532,8 +532,8 @@ space_def_new_from_tuple(struct tuple *tuple, uint32_t 
errcode,
                                 engine_name, engine_name_len, &opts, fields,
                                 field_count);
        auto def_guard = make_scoped_guard([=] { space_def_delete(def); });
-       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 3516bdd8d..1ed9d4280 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;
 }
@@ -284,7 +285,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 8044f88fd..c23c578ff 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 081a038f1..26b84c5db 100644
--- a/src/box/sql.c
+++ b/src/box/sql.c
@@ -1048,7 +1048,7 @@ sql_encode_table_opts(struct region *region, struct Table 
*table,
        int checks_cnt = 0;
        struct ExprList_item *a;
        bool 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 49b90b5d0..7e5bcc518 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);
        }
@@ -767,15 +767,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 {
@@ -852,7 +853,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
@@ -1375,8 +1376,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


Other related posts: