[tarantool-patches] Re: [PATCH] sql: remove struct Table

n.pettik korablev at tarantool.org
Mon Feb 11 20:58:13 MSK 2019


> On 6 Feb 2019, at 20:17, i.koptelov <ivan.koptelov at tarantool.org> wrote:
> 
>>> On 1 Feb 2019, at 14:05, Ivan Koptelov<ivan.koptelov at tarantool.org>  wrote:
>>> 
>>> Thank you for the review! Sorry for all these code style errors.
>>> I consider review changes minor, so I put diff b/w first and
>>> second version of patch at the end of the letter.
>>> (second commit on the branch 'review fixes' would be squashed)
>> Don’t do it next time, pls. Instead, inline fixes as an answers to comments,
>> especially when it comes for huge diff ( 209 insertions(+), 259 deletions(-))
>> Otherwise, it takes a while to track fixed chunks of code in a whole diff.
> Sorry for this. All review fixes below is inlined.

Well, thank you. But don’t put fixes in a separate commit, at least when
you push your branch to the remote repository. You may *accidentally*
fail during final commit squashing and no-one will notice that.

Travis status was entirely negative: It can’t be compiled. 
You forgot to add forward declaration of space_def.
I fixed that and a couple of minor issues more. Here is a diff
(I’ve squashed your commits and pushed on top of your branch).

Please, check it out. If it is OK, squash them and then patch LGTM.
 
diff --git a/src/box/sql.h b/src/box/sql.h
index e7b3933b9..aef4cd3b0 100644
--- a/src/box/sql.h
+++ b/src/box/sql.h
@@ -67,6 +67,7 @@ struct Parse;
 struct Select;
 struct Table;
 struct sql_trigger;
+struct space_def;
 
 /**
  * Perform parsing of provided expression. This is done by
@@ -278,8 +279,9 @@ sql_expr_list_append(struct sqlite3 *db, struct ExprList *expr_list,
  * @param expr_list Expression list to resolve.  May be NUL.
  */
 void
-sql_resolve_self_reference(struct Parse *parser, struct space_def *def, int type,
-                          struct Expr *expr, struct ExprList *expr_list);
+sql_resolve_self_reference(struct Parse *parser, struct space_def *def,
+                          int type, struct Expr *expr,
+                          struct ExprList *expr_list);
 
 /**
  * Initialize check_list_item.
diff --git a/src/box/sql/build.c b/src/box/sql/build.c
index 4b055529c..7f9e5f6e6 100644
--- a/src/box/sql/build.c
+++ b/src/box/sql/build.c
@@ -282,6 +282,17 @@ sqlite3CheckIdentifierName(Parse *pParse, char *zName)
 
 /**
  * Return the PRIMARY KEY index of a table.
+ *
+ * Note that during parsing routines this function is not equal
+ * to space_index(space, 0); call since primary key can be added
+ * after seconary keys:
+ *
+ * CREATE TABLE t (a INT UNIQUE, b PRIMARY KEY);
+ *
+ * In this particular case, after secondary index processing
+ * space still lacks PK, but index[0] != NULL since index array
+ * is filled in a straightforward way. Hence, function must
+ * return NULL.
  */
 static struct index *
 sql_space_primary_key(const struct space *space)
@@ -447,8 +458,7 @@ sqlite3AddColumn(Parse * pParse, Token * pName, struct type_def *type_def)
 #endif
        /*
         * As sql_field_retrieve will allocate memory on region
-        * ensure that p->space->def is also temporal and would be
-        * dropped.
+        * ensure that def is also temporal and would be dropped.
         */
        assert(def->opts.is_temporary);
        if (sql_field_retrieve(pParse, def, def->field_count) == NULL)
@@ -598,9 +608,9 @@ sqlite3AddPrimaryKey(Parse * pParse,        /* Parsing context */
 {
        int iCol = -1, i;
        int nTerm;
-       if (pParse->updated_space == NULL)
-               goto primary_key_exit;
        struct space *space = pParse->updated_space;
+       if (space == NULL)
+               goto primary_key_exit;
        if (sql_space_primary_key(space) != NULL) {
                sqlite3ErrorMsg(pParse,
                                "table \"%s\" has more than one primary key",
@@ -742,17 +752,14 @@ sql_column_collation(struct space_def *def, uint32_t column, uint32_t *coll_id)
        struct space *space = space_by_id(def->id);
        /*
         * It is not always possible to fetch collation directly
-        * from struct space. To be more precise when:
-        * 1. space is ephemeral. Thus, its id is zero and
-        *    it can't be found in space cache.
-        * 2. space is a view. Hence, it lacks any functional
-        *    parts such as indexes or fields.
-        * 3. space is under construction. So, the same as p.1
-        *    it can't be found in space cache.
-        * In cases mentioned above collation is fetched from
-        * SQL specific structures.
+        * from struct space due to its absence in space cache.
+        * To be more precise when space is ephemeral or it is
+        * under construction.
+        *
+        * In cases mentioned above collation is fetched by id.
         */
-       if (space == NULL || space_index(space, 0) == NULL) {
+       if (space == NULL) {
+               assert(def->opts.is_temporary);
                assert(column < (uint32_t)def->field_count);
                *coll_id = def->fields[column].coll_id;
                struct coll_id *collation = coll_by_id(*coll_id);
@@ -1157,10 +1164,9 @@ sqlite3EndTable(Parse * pParse,  /* Parse context */
                return;
        }
        assert(!db->mallocFailed);
-       if (pParse->updated_space == NULL)
-               return;
-
        struct space *new_space = pParse->updated_space;
+       if (new_space == NULL)
+               return;
        assert(!db->init.busy);
 
        if (!new_space->def->opts.is_view) {
@@ -1290,9 +1296,9 @@ sql_create_view(struct Parse *parse_context, struct Token *begin,
                goto create_view_fail;
        }
        sqlite3StartTable(parse_context, name, if_exists);
-       if (parse_context->updated_space == NULL || parse_context->nErr != 0)
-               goto create_view_fail;
        struct space *space = parse_context->updated_space;
+       if (space == NULL || parse_context->nErr != 0)
+               goto create_view_fail;
 
        struct space *select_res_space =
                sqlite3ResultSetOfSelect(parse_context, select);
@@ -2047,7 +2053,6 @@ index_fill_def(struct Parse *parse, struct index *index,
                         "region", "key parts");
                goto tnt_error;
        }
-
        for (int i = 0; i < expr_list->nExpr; i++) {
                struct Expr *expr = expr_list->a[i].pExpr;
                sql_resolve_self_reference(parse, space_def, NC_IdxExpr,
diff --git a/src/box/sql/delete.c b/src/box/sql/delete.c
index 143803f9d..8c4ad3146 100644
--- a/src/box/sql/delete.c
+++ b/src/box/sql/delete.c
@@ -146,10 +146,8 @@ sql_table_delete_from(struct Parse *parse, struct SrcList *tab_list,
        struct space *space = sql_lookup_space(parse, tab_list->a);
        if (space == NULL)
                goto delete_from_cleanup;
-       assert(space != NULL);
        trigger_list = sql_triggers_exist(space->def, TK_DELETE, NULL, NULL);
-       bool is_complex = trigger_list != NULL ||
-                         fkey_is_required(space, NULL);
+       bool is_complex = trigger_list != NULL || fkey_is_required(space, NULL);
        bool is_view = space->def->opts.is_view;
 
        /* If table is really a view, make sure it has been
diff --git a/src/box/sql/insert.c b/src/box/sql/insert.c
index 6bd716767..d630524b3 100644
--- a/src/box/sql/insert.c
+++ b/src/box/sql/insert.c
@@ -114,7 +114,7 @@ sql_space_autoinc_fieldno(struct space *space)
 /**
  * This routine is used to see if a statement of the form
  * "INSERT INTO <table> SELECT ..." can run for the results of the
- * SELECT.
+ * SELECT. Otherwise, it may fall into infinite loop.
  *
  * @param parser Parse context.
  * @param space_def Space definition.
@@ -124,7 +124,7 @@ sql_space_autoinc_fieldno(struct space *space)
  * @retval  false else.
  */
 static bool
-vdbe_has_table_read(struct Parse *parser, const struct space_def *space_def)
+vdbe_has_space_read(struct Parse *parser, const struct space_def *space_def)
 {
        struct Vdbe *v = sqlite3GetVdbe(parser);
        int last_instr = sqlite3VdbeCurrentAddr(v);
@@ -456,7 +456,7 @@ sqlite3Insert(Parse * pParse,       /* Parser context */
                 * the SELECT statement. Also use a temp table in
                 * the case of row triggers.
                 */
-               if (trigger != NULL || vdbe_has_table_read(pParse, space_def))
+               if (trigger != NULL || vdbe_has_space_read(pParse, space_def))
                        useTempTable = 1;
 
                if (useTempTable) {
@@ -1210,9 +1210,7 @@ xferOptimization(Parse * pParse,  /* Parser context */
                /* Affinity must be the same on all columns. */
                if (dest_affinity != src_affinity)
                        return 0;
-               uint32_t id;
-               if (sql_column_collation(dest->def, i, &id) !=
-                   sql_column_collation(src->def, i, &id))
+               if (dest->def->fields[i].coll_id != src->def->fields[i].coll_id)
                        return 0;
                if (!dest->def->fields[i].is_nullable &&
                    src->def->fields[i].is_nullable)
diff --git a/src/box/sql/resolve.c b/src/box/sql/resolve.c
index 86d51280d..d3618d207 100644
--- a/src/box/sql/resolve.c
+++ b/src/box/sql/resolve.c
@@ -218,7 +218,6 @@ lookupName(Parse * pParse,  /* The parsing context */
        struct SrcList_item *pMatch = 0;        /* The matching pSrcList item */
        NameContext *pTopNC = pNC;      /* First namecontext in the list */
        int isTrigger = 0;      /* True if resolved to a trigger column */
-       struct space_def *space_def;
 
        assert(pNC);            /* the name context cannot be NULL. */
        assert(zCol);           /* The Z in X.Y.Z cannot be NULL */
@@ -311,11 +310,12 @@ lookupName(Parse * pParse,        /* The parsing context */
                /* If we have not already resolved the name, then maybe
                 * it is a new.* or old.* trigger argument reference
                 */
-               if (zTab != NULL && cntTab == 0
-                   && pParse->updated_space != NULL) {
+               if (zTab != NULL && cntTab == 0 &&
+                   pParse->updated_space != NULL) {
                        int op = pParse->eTriggerOp;
                        assert(op == TK_DELETE || op == TK_UPDATE
                               || op == TK_INSERT);
+                       struct space_def *space_def = NULL;
                        if (op != TK_DELETE && sqlite3StrICmp("new", zTab) == 0) {
                                pExpr->iTable = 1;
                                space_def = pParse->updated_space->def;
@@ -323,8 +323,6 @@ lookupName(Parse * pParse,  /* The parsing context */
                                   && sqlite3StrICmp("old", zTab) == 0) {
                                pExpr->iTable = 0;
                                space_def = pParse->updated_space->def;
-                       } else {
-                               space_def = NULL;
                        }
 
                        if (space_def != NULL) {
@@ -1614,8 +1612,9 @@ sqlite3ResolveSelectNames(Parse * pParse, /* The parser context */
 }
 
 void
-sql_resolve_self_reference(struct Parse *parser, struct space_def *def, int type,
-                          struct Expr *expr, struct ExprList *expr_list)
+sql_resolve_self_reference(struct Parse *parser, struct space_def *def,
+                          int type, struct Expr *expr,
+                          struct ExprList *expr_list)
 {
        /* Fake SrcList for parser->updated_space */
        SrcList sSrc;
diff --git a/src/box/sql/select.c b/src/box/sql/select.c
index b30aa6200..da602a9c0 100644
--- a/src/box/sql/select.c
+++ b/src/box/sql/select.c
@@ -421,8 +421,7 @@ sqlite3JoinType(Parse * pParse, Token * pA, Token * pB, Token * pC)
 static int
 columnIndex(struct space_def *def, const char *zCol)
 {
-       int i;
-       for (i = 0; i < (int)def->field_count; i++) {
+       for (uint32_t i = 0; i < def->field_count; i++) {
                if (strcmp(def->fields[i].name, zCol) == 0)
                        return i;
        }
@@ -1943,8 +1942,9 @@ cleanup:
  * statement be resolved.
  */
 void
-sqlite3SelectAddColumnTypeAndCollation(Parse *pParse, struct space_def *def,
-                                      Select *pSelect)
+sqlite3SelectAddColumnTypeAndCollation(struct Parse *pParse,
+                                      struct space_def *def,
+                                      struct Select *pSelect)
 {
        sqlite3 *db = pParse->db;
        NameContext sNC;
@@ -4021,7 +4021,8 @@ flattenSubquery(Parse * pParse,           /* Parsing context */
                        return 1;
        }
 
-       /* Begin flattening the iFrom-th entry of the FROM clause
+       /*
+        * Begin flattening the iFrom-th entry of the FROM clause
         * in the outer query.
         */
        pSub = pSub1 = pSubitem->pSelect;
@@ -4599,7 +4600,7 @@ withExpand(Walker * pWalker, struct SrcList_item *pFrom)
                /* Check if this is a recursive CTE. */
                pSel = pFrom->pSelect;
                bMayRecursive = (pSel->op == TK_ALL || pSel->op == TK_UNION);
-               int ref_counter = 0;
+               uint32_t ref_counter = 0;
                if (bMayRecursive) {
                        int i;
                        SrcList *pSrc = pFrom->pSelect->pSrc;
@@ -4770,13 +4771,12 @@ selectExpander(Walker * pWalker, Select * p)
                         * unique identifier.
                         */
                        const char *name = "sqlite_sq_DEADBEAFDEADBEAF";
-                       pFrom->space =
-                           sql_ephemeral_space_new(sqlite3ParseToplevel(pParse),
-                                                   name);
-                       struct space *space = pFrom->space;
-
+                       struct space *space =
+                               sql_ephemeral_space_new(sqlite3ParseToplevel(pParse),
+                                                       name);
                        if (space == NULL)
                                return WRC_Abort;
+                       pFrom->space = space;
                        /*
                         * Rewrite old name with correct pointer.
                         */
@@ -4786,7 +4786,7 @@ selectExpander(Walker * pWalker, Select * p)
                                pSel = pSel->pPrior;
                        }
                        sqlite3ColumnsFromExprList(pParse, pSel->pEList,
-                                                  space->def);
+                                                  space->def);
                } else {
                        /*
                         * An ordinary table or view name in the
@@ -4808,10 +4808,7 @@ selectExpander(Walker * pWalker, Select * p)
                                pFrom->pSelect = select;
                                sqlite3SelectSetName(pFrom->pSelect,
                                                     space->def->name);
-                               int columns = space->def->field_count;
-                               space->def->field_count = -1;
                                sqlite3WalkSelect(pWalker, pFrom->pSelect);
-                               space->def->field_count = columns;
                        }
                }
                /* Locate the index named by the INDEXED BY clause, if any. */
diff --git a/src/box/sql/sqliteInt.h b/src/box/sql/sqliteInt.h
index 874fd682f..1352f6efe 100644
--- a/src/box/sql/sqliteInt.h
+++ b/src/box/sql/sqliteInt.h
@@ -2313,7 +2313,8 @@ struct SrcList {
        struct SrcList_item {
                char *zName;    /* Name of the table */
                char *zAlias;   /* The "B" part of a "A AS B" phrase.  zName is the "A" */
-               struct space *space;    /* A space corresponding to zName */
+               /** A space corresponding to zName */
+               struct space *space;
                Select *pSelect;        /* A SELECT statement used in place of a table name */
                int addrFillSub;        /* Address of subroutine to manifest a subquery */
                int regReturn;  /* Register holding return address of addrFillSub */
@@ -2759,6 +2760,9 @@ struct Parse {
        TriggerPrg *pTriggerPrg;        /* Linked list of coded triggers */
        With *pWith;            /* Current WITH clause, or NULL */
        With *pWithToFree;      /* Free this WITH object at the end of the parse */
+       /** Space triggers are being coded for. */
+       struct space *triggered_space;
+       /** A space being constructed by CREATE TABLE */
        /**
         * Number of FK constraints declared within
         * CREATE TABLE statement.
@@ -3480,7 +3484,7 @@ void sqlite3IdListDelete(sqlite3 *, IdList *);
  *
  * @param parse All information about this parse.
  * @param token Index name. May be NULL.
- * @param tbl_name Table to index. Use pParse->updated_space ifNULL.
+ * @param tbl_name Table to index. Use pParse->updated_space if NULL.
  * @param col_list A list of columns to be indexed.
  * @param start The CREATE token that begins this statement.
  * @param sort_order Sort order of primary key when pList==NULL.
@@ -3510,7 +3514,7 @@ Select *sqlite3SelectNew(Parse *, ExprList *, SrcList *, Expr *, ExprList *,
                         Expr *, ExprList *, u32, Expr *, Expr *);
 
 /**
- * While a SrcList can in general represent multiple tables and
+ * While a SrcList can in general represent multiple spaces and
  * subqueries (as in the FROM clause of a SELECT statement) in
  * this case it contains the name of a single table, as one might
  * find in an INSERT, DELETE, or UPDATE statement. Look up that


What is more, I returned back separation into new_space and trigger_space.
The reason is that I am working on another patch where I replace new_space
with struct create_table_def - structure assembling all required arguments for
parsing routines. So, we won’t be able to store new_space and trigger_space
in one struct. Here is diff:

diff --git a/src/box/sql/build.c b/src/box/sql/build.c
index 7f9e5f6e6..1cae2bb2c 100644
--- a/src/box/sql/build.c
+++ b/src/box/sql/build.c
@@ -312,7 +312,7 @@ sql_space_primary_key(const struct space *space)
  * when the "TEMP" or "TEMPORARY" keyword occurs in between
  * CREATE and TABLE.
  *
- * The new table record is initialized and put in pParse->updated_space.
+ * The new table record is initialized and put in pParse->new_space.
  * As more of the CREATE TABLE statement is parsed, additional action
  * routines will be called to add more information to this record.
  * At the end of the CREATE TABLE statement, the sqlite3EndTable() routine
@@ -358,8 +358,8 @@ sqlite3StartTable(Parse *pParse, Token *pName, int noErr)
        strcpy(new_space->def->engine_name,
               sql_storage_engine_strs[current_session()->sql_default_engine]);
 
-       assert(pParse->updated_space == NULL);
-       pParse->updated_space = new_space;
+       assert(pParse->new_space == NULL);
+       pParse->new_space = new_space;
 
        if (!db->init.busy && (v = sqlite3GetVdbe(pParse)) != 0)
                sql_set_multi_write(pParse, true);
@@ -446,9 +446,9 @@ sqlite3AddColumn(Parse * pParse, Token * pName, struct type_def *type_def)
        assert(type_def != NULL);
        char *z;
        sqlite3 *db = pParse->db;
-       if (pParse->updated_space == NULL)
+       if (pParse->new_space == NULL)
                return;
-       struct space_def *def = pParse->updated_space->def;
+       struct space_def *def = pParse->new_space->def;
 
 #if SQLITE_MAX_COLUMN
        if ((int)def->field_count + 1 > db->aLimit[SQLITE_LIMIT_COLUMN]) {
@@ -501,10 +501,10 @@ void
 sql_column_add_nullable_action(struct Parse *parser,
                               enum on_conflict_action nullable_action)
 {
-       if (parser->updated_space == NULL ||
-           NEVER(parser->updated_space->def->field_count < 1))
+       if (parser->new_space == NULL ||
+           NEVER(parser->new_space->def->field_count < 1))
                return;
-       struct space_def *def = parser->updated_space->def;
+       struct space_def *def = parser->new_space->def;
        struct field_def *field = &def->fields[def->field_count - 1];
        if (field->nullable_action != ON_CONFLICT_ACTION_DEFAULT &&
            nullable_action != field->nullable_action) {
@@ -538,9 +538,9 @@ void
 sqlite3AddDefaultValue(Parse * pParse, ExprSpan * pSpan)
 {
        sqlite3 *db = pParse->db;
-       assert(pParse->updated_space->def->opts.is_temporary);
-       if (pParse->updated_space != NULL) {
-               struct space_def *def = pParse->updated_space->def;
+       assert(pParse->new_space->def->opts.is_temporary);
+       if (pParse->new_space != NULL) {
+               struct space_def *def = pParse->new_space->def;
                if (!sqlite3ExprIsConstantOrFunction
                    (pSpan->pExpr, db->init.busy)) {
                        sqlite3ErrorMsg(pParse,
@@ -608,7 +608,7 @@ sqlite3AddPrimaryKey(Parse * pParse,        /* Parsing context */
 {
        int iCol = -1, i;
        int nTerm;
-       struct space *space = pParse->updated_space;
+       struct space *space = pParse->new_space;
        if (space == NULL)
                goto primary_key_exit;
        if (sql_space_primary_key(space) != NULL) {
@@ -688,8 +688,8 @@ void
 sql_add_check_constraint(struct Parse *parser, struct ExprSpan *span)
 {
        struct Expr *expr = span->pExpr;
-       if (parser->updated_space != NULL) {
-               struct space *space = parser->updated_space;
+       if (parser->new_space != NULL) {
+               struct space *space = parser->new_space;
                expr->u.zToken =
                        sqlite3DbStrNDup(parser->db, (char *)span->zStart,
                                         (int)(span->zEnd - span->zStart));
@@ -719,9 +719,9 @@ release_expr:
 void
 sqlite3AddCollateType(Parse * pParse, Token * pToken)
 {
-       if (pParse->updated_space == NULL)
+       if (pParse->new_space == NULL)
                return;
-       struct space *space = pParse->updated_space;
+       struct space *space = pParse->new_space;
        uint32_t i = space->def->field_count - 1;
        sqlite3 *db = pParse->db;
        char *zColl = sqlite3NameFromToken(db, pToken);
@@ -839,7 +839,7 @@ vdbe_emit_create_index(struct Parse *parse, struct space_def *def,
        memcpy(raw, index_parts, index_parts_sz);
        index_parts = raw;
 
-       if (parse->updated_space != NULL) {
+       if (parse->new_space != NULL) {
                sqlite3VdbeAddOp2(v, OP_SCopy, space_id_reg, entry_reg);
                sqlite3VdbeAddOp2(v, OP_Integer, idx_def->iid, entry_reg + 1);
        } else {
@@ -884,7 +884,7 @@ createSpace(Parse * pParse, int iSpaceId, char *zStmt)
        int iRecord = (pParse->nMem += 7);
        struct region *region = &pParse->region;
        uint32_t table_opts_stmt_sz = 0;
-       struct space *space = pParse->updated_space;
+       struct space *space = pParse->new_space;
        char *table_opts_stmt = sql_encode_table_opts(region, space->def, zStmt,
                                                      &table_opts_stmt_sz);
        if (table_opts_stmt == NULL)
@@ -1029,14 +1029,14 @@ vdbe_emit_fkey_create(struct Parse *parse_context, const struct fkey_def *fk)
         * of <CREATE TABLE ...> statement, we don't have child
         * id, but we know register where it will be stored.
         */
-       if (parse_context->updated_space != NULL) {
+       if (parse_context->new_space != NULL) {
                sqlite3VdbeAddOp2(vdbe, OP_SCopy, fk->child_id,
                                  constr_tuple_reg + 1);
        } else {
                sqlite3VdbeAddOp2(vdbe, OP_Integer, fk->child_id,
                                  constr_tuple_reg + 1);
        }
-       if (parse_context->updated_space != NULL && fkey_is_self_referenced(fk)) {
+       if (parse_context->new_space != NULL && fkey_is_self_referenced(fk)) {
                sqlite3VdbeAddOp2(vdbe, OP_SCopy, fk->parent_id,
                                  constr_tuple_reg + 2);
        } else {
@@ -1099,7 +1099,7 @@ vdbe_emit_fkey_create(struct Parse *parse_context, const struct fkey_def *fk)
                          constr_tuple_reg + 9);
        sqlite3VdbeAddOp3(vdbe, OP_SInsert, BOX_FK_CONSTRAINT_ID, 0,
                          constr_tuple_reg + 9);
-       if (parse_context->updated_space == NULL)
+       if (parse_context->new_space == NULL)
                sqlite3VdbeChangeP5(vdbe, OPFLAG_NCHANGE);
        save_record(parse_context, BOX_FK_CONSTRAINT_ID, constr_tuple_reg, 2,
                    vdbe->nOp - 1);
@@ -1164,7 +1164,7 @@ sqlite3EndTable(Parse * pParse,   /* Parse context */
                return;
        }
        assert(!db->mallocFailed);
-       struct space *new_space = pParse->updated_space;
+       struct space *new_space = pParse->new_space;
        if (new_space == NULL)
                return;
        assert(!db->init.busy);
@@ -1296,7 +1296,7 @@ sql_create_view(struct Parse *parse_context, struct Token *begin,
                goto create_view_fail;
        }
        sqlite3StartTable(parse_context, name, if_exists);
-       struct space *space = parse_context->updated_space;
+       struct space *space = parse_context->new_space;
        if (space == NULL || parse_context->nErr != 0)
                goto create_view_fail;
 
@@ -1729,7 +1729,7 @@ sql_create_foreign_key(struct Parse *parse_context, struct SrcList *child,
         * Space under construction during CREATE TABLE
         * processing. NULL for ALTER TABLE statement handling.
         */
-       struct space *space = parse_context->updated_space;
+       struct space *space = parse_context->new_space;
        bool is_alter = space == NULL;
 
        uint32_t child_cols_count;
@@ -2164,11 +2164,11 @@ sql_create_index(struct Parse *parse, struct Token *token,
                        goto exit_create_index;
                }
        } else {
-               if (parse->updated_space == NULL)
+               if (parse->new_space == NULL)
                        goto exit_create_index;
                assert(token == NULL);
                assert(start == NULL);
-               space = parse->updated_space;
+               space = parse->new_space;
        }
        struct space_def *def = space->def;
 
@@ -2354,7 +2354,7 @@ sql_create_index(struct Parse *parse, struct Token *token,
         * constraint, but has different onError (behavior on
         * constraint violation), then an error is raised.
         */
-       if (parse->updated_space != NULL) {
+       if (parse->new_space != NULL) {
                for (uint32_t i = 0; i < space->index_count; ++i) {
                        struct index *existing_idx = space->index[i];
                        uint32_t iid = existing_idx->def->iid;
diff --git a/src/box/sql/delete.c b/src/box/sql/delete.c
index 8c4ad3146..d7070b70b 100644
--- a/src/box/sql/delete.c
+++ b/src/box/sql/delete.c
@@ -413,7 +413,7 @@ sql_table_delete_from(struct Parse *parse, struct SrcList *tab_list,
 
        /* Return the number of rows that were deleted. */
        if ((user_session->sql_flags & SQLITE_CountRows) != 0 &&
-           parse->updated_space != NULL) {
+           parse->triggered_space != NULL) {
                sqlite3VdbeAddOp2(v, OP_ResultRow, reg_count, 1);
                sqlite3VdbeSetNumCols(v, 1);
                sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows deleted",
diff --git a/src/box/sql/expr.c b/src/box/sql/expr.c
index b23f36731..d0ac87f14 100644
--- a/src/box/sql/expr.c
+++ b/src/box/sql/expr.c
@@ -4335,7 +4335,7 @@ sqlite3ExprCodeTarget(Parse * pParse, Expr * pExpr, int target)
                        break;
                }
        case TK_RAISE:
-               if (pParse->updated_space == NULL) {
+               if (pParse->triggered_space == NULL) {
                        sqlite3ErrorMsg(pParse, "RAISE() may only be used "
                                        "within a trigger-program");
                        return 0;
diff --git a/src/box/sql/insert.c b/src/box/sql/insert.c
index d630524b3..50204da4a 100644
--- a/src/box/sql/insert.c
+++ b/src/box/sql/insert.c
@@ -793,7 +793,7 @@ sqlite3Insert(Parse * pParse,       /* Parser context */
 
        /* Return the number of rows inserted. */
        if ((user_session->sql_flags & SQLITE_CountRows) != 0 &&
-           pParse->updated_space == NULL) {
+           pParse->triggered_space == NULL) {
                sqlite3VdbeAddOp2(v, OP_ResultRow, regRowCount, 1);
                sqlite3VdbeSetNumCols(v, 1);
                sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows inserted",
diff --git a/src/box/sql/resolve.c b/src/box/sql/resolve.c
index d3618d207..6e13151e6 100644
--- a/src/box/sql/resolve.c
+++ b/src/box/sql/resolve.c
@@ -311,18 +311,18 @@ lookupName(Parse * pParse,        /* The parsing context */
                 * it is a new.* or old.* trigger argument reference
                 */
                if (zTab != NULL && cntTab == 0 &&
-                   pParse->updated_space != NULL) {
+                   pParse->triggered_space != NULL) {
                        int op = pParse->eTriggerOp;
                        assert(op == TK_DELETE || op == TK_UPDATE
                               || op == TK_INSERT);
                        struct space_def *space_def = NULL;
                        if (op != TK_DELETE && sqlite3StrICmp("new", zTab) == 0) {
                                pExpr->iTable = 1;
-                               space_def = pParse->updated_space->def;
+                               space_def = pParse->triggered_space->def;
                        } else if (op != TK_INSERT
                                   && sqlite3StrICmp("old", zTab) == 0) {
                                pExpr->iTable = 0;
-                               space_def = pParse->updated_space->def;
+                               space_def = pParse->triggered_space->def;
                        }
 
                        if (space_def != NULL) {
@@ -1616,9 +1616,9 @@ sql_resolve_self_reference(struct Parse *parser, struct space_def *def,
                           int type, struct Expr *expr,
                           struct ExprList *expr_list)
 {
-       /* Fake SrcList for parser->updated_space */
+       /* Fake SrcList for parser->new_space */
        SrcList sSrc;
-       /* Name context for parser->updated_space */
+       /* Name context for parser->new_space */
        NameContext sNC;
 
        assert(type == NC_IsCheck || type == NC_IdxExpr);
diff --git a/src/box/sql/sqliteInt.h b/src/box/sql/sqliteInt.h
index 1352f6efe..5d01b91b2 100644
--- a/src/box/sql/sqliteInt.h
+++ b/src/box/sql/sqliteInt.h
@@ -2755,7 +2755,7 @@ struct Parse {
        VList *pVList;          /* Mapping between variable names and numbers */
        Vdbe *pReprepare;       /* VM being reprepared (sqlite3Reprepare()) */
        const char *zTail;      /* All SQL text past the last semicolon parsed */
-       struct space *updated_space;    /* A space being constructed by CREATE TABLE
+       struct space *new_space;        /* A space being constructed by CREATE TABLE
                                           or space we are coding triggers for */
        TriggerPrg *pTriggerPrg;        /* Linked list of coded triggers */
        With *pWith;            /* Current WITH clause, or NULL */
@@ -3474,8 +3474,8 @@ void sqlite3IdListDelete(sqlite3 *, IdList *);
  * index and tbl_name is the name of the table that is to be
  * indexed.  Both will be NULL for a primary key or an index that
  * is created to satisfy a UNIQUE constraint.  If tbl_name and
- * name are NULL, use parse->updated_space as the table to be indexed.
- * parse->updated_space is a space that is currently being
+ * name are NULL, use parse->new_space as the table to be indexed.
+ * parse->new_space is a space that is currently being
  * constructed by a CREATE TABLE statement.
  *
  * col_list is a list of columns to be indexed.  col_list will be
@@ -3484,7 +3484,7 @@ void sqlite3IdListDelete(sqlite3 *, IdList *);
  *
  * @param parse All information about this parse.
  * @param token Index name. May be NULL.
- * @param tbl_name Table to index. Use pParse->updated_space if NULL.
+ * @param tbl_name Table to index. Use pParse->new_space if NULL.
  * @param col_list A list of columns to be indexed.
  * @param start The CREATE token that begins this statement.
  * @param sort_order Sort order of primary key when pList==NULL.
diff --git a/src/box/sql/tokenize.c b/src/box/sql/tokenize.c
index 9b0f2cf49..fd45413b9 100644
--- a/src/box/sql/tokenize.c
+++ b/src/box/sql/tokenize.c
@@ -421,7 +421,7 @@ sql_token(const char *z, int *type, bool *is_reserved)
  * during table creation. The only objects allocated using
  * malloc are index defs and check constraints.
  * Note that this functions can't be called on ordinary
- * space object. It's purpose is to clean-up parser->updated_space.
+ * space object. It's purpose is to clean-up parser->new_space.
  *
  * @param db Database handler.
  * @param space Space to be deleted.
@@ -470,7 +470,7 @@ sqlite3RunParser(Parse * pParse, const char *zSql, char **pzErrMsg)
                sqlite3OomFault(db);
                return SQLITE_NOMEM_BKPT;
        }
-       assert(pParse->updated_space == NULL);
+       assert(pParse->new_space == NULL);
        assert(pParse->parsed_ast.trigger == NULL);
        assert(pParse->nVar == 0);
        assert(pParse->pVList == 0);
@@ -550,7 +550,7 @@ sqlite3RunParser(Parse * pParse, const char *zSql, char **pzErrMsg)
                sqlite3VdbeDelete(pParse->pVdbe);
                pParse->pVdbe = 0;
        }
-       parser_space_delete(db, pParse->updated_space);
+       parser_space_delete(db, pParse->new_space);
        if (pParse->pWithToFree)
                sqlite3WithDelete(db, pParse->pWithToFree);
        sqlite3DbFree(db, pParse->pVList);
diff --git a/src/box/sql/trigger.c b/src/box/sql/trigger.c
index e3c87c422..46523edd9 100644
--- a/src/box/sql/trigger.c
+++ b/src/box/sql/trigger.c
@@ -614,7 +614,7 @@ codeTriggerProgram(Parse * pParse,  /* The parser context */
        Vdbe *v = pParse->pVdbe;
        sqlite3 *db = pParse->db;
 
-       assert(pParse->updated_space != NULL && pParse->pToplevel != NULL);
+       assert(pParse->triggered_space != NULL && pParse->pToplevel != NULL);
        assert(pStepList);
        assert(v != 0);
 
@@ -799,7 +799,7 @@ sql_row_trigger_program(struct Parse *parser, struct sql_trigger *trigger,
        sql_parser_create(pSubParse, db);
        memset(&sNC, 0, sizeof(sNC));
        sNC.pParse = pSubParse;
-       pSubParse->updated_space = space;
+       pSubParse->triggered_space = space;
        pSubParse->pToplevel = pTop;
        pSubParse->eTriggerOp = trigger->op;
        pSubParse->nQueryLoop = parser->nQueryLoop;
diff --git a/src/box/sql/update.c b/src/box/sql/update.c
index a7affa954..5eb1437ab 100644
--- a/src/box/sql/update.c
+++ b/src/box/sql/update.c
@@ -295,7 +295,7 @@ sqlite3Update(Parse * pParse,               /* The parser context */
        /* Initialize the count of updated rows
         */
        if ((user_session->sql_flags & SQLITE_CountRows)
-           && pParse->updated_space == NULL) {
+           && pParse->triggered_space == NULL) {
                regRowCount = ++pParse->nMem;
                sqlite3VdbeAddOp2(v, OP_Integer, 0, regRowCount);
        }
@@ -503,7 +503,7 @@ sqlite3Update(Parse * pParse,               /* The parser context */
        /* Increment the row counter
         */
        if ((user_session->sql_flags & SQLITE_CountRows)
-           && pParse->updated_space == NULL) {
+           && pParse->triggered_space == NULL) {
                sqlite3VdbeAddOp2(v, OP_AddImm, regRowCount, 1);
        }
 
@@ -525,7 +525,7 @@ sqlite3Update(Parse * pParse,               /* The parser context */
 
        /* Return the number of rows that were changed. */
        if (user_session->sql_flags & SQLITE_CountRows &&
-           pParse->updated_space == NULL) {
+           pParse->triggered_space == NULL) {
                sqlite3VdbeAddOp2(v, OP_ResultRow, regRowCount, 1);
                sqlite3VdbeSetNumCols(v, 1);
                sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows updated",







More information about the Tarantool-patches mailing list