From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 27A4F22FF2 for ; Mon, 11 Feb 2019 12:58:17 -0500 (EST) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id spvM4o-SG2HU for ; Mon, 11 Feb 2019 12:58:17 -0500 (EST) Received: from smtpng1.m.smailru.net (smtpng1.m.smailru.net [94.100.181.251]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 0E05C20B0E for ; Mon, 11 Feb 2019 12:58:15 -0500 (EST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.2 \(3445.102.3\)) Subject: [tarantool-patches] Re: [PATCH] sql: remove struct Table From: "n.pettik" In-Reply-To: Date: Mon, 11 Feb 2019 20:58:13 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: <7CB3BC6E-B4CF-4EE0-BFB7-F5E7CFF89947@tarantool.org> References: <4c2b87b5-9e83-f96f-4350-edf7a12e5593@tarantool.org> <9f612f00-6222-e3cb-642c-04bfec116fd4@tarantool.org> <3438F900-EF6D-4475-B3F1-BD4971F78186@tarantool.org> Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org Cc: Ivan Koptelov > On 6 Feb 2019, at 20:17, i.koptelov = wrote: >=20 >>> On 1 Feb 2019, at 14:05, Ivan Koptelov = wrote: >>>=20 >>> 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=E2=80=99t 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=E2=80=99t 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=E2=80=99t be compiled.=20 You forgot to add forward declaration of space_def. I fixed that and a couple of minor issues more. Here is a diff (I=E2=80=99ve squashed your commits and pushed on top of your branch). Please, check it out. If it is OK, squash them and then patch LGTM. =20 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; =20 /** * 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); =20 /** * 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) =20 /** * 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] !=3D 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) =3D=3D = NULL) @@ -598,9 +608,9 @@ sqlite3AddPrimaryKey(Parse * pParse, /* = Parsing context */ { int iCol =3D -1, i; int nTerm; - if (pParse->updated_space =3D=3D NULL) - goto primary_key_exit; struct space *space =3D pParse->updated_space; + if (space =3D=3D NULL) + goto primary_key_exit; if (sql_space_primary_key(space) !=3D 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 =3D 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 =3D=3D NULL || space_index(space, 0) =3D=3D NULL) { + if (space =3D=3D NULL) { + assert(def->opts.is_temporary); assert(column < (uint32_t)def->field_count); *coll_id =3D def->fields[column].coll_id; struct coll_id *collation =3D coll_by_id(*coll_id); @@ -1157,10 +1164,9 @@ sqlite3EndTable(Parse * pParse, /* Parse context = */ return; } assert(!db->mallocFailed); - if (pParse->updated_space =3D=3D NULL) - return; - struct space *new_space =3D pParse->updated_space; + if (new_space =3D=3D NULL) + return; assert(!db->init.busy); =20 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 =3D=3D NULL || = parse_context->nErr !=3D 0) - goto create_view_fail; struct space *space =3D parse_context->updated_space; + if (space =3D=3D NULL || parse_context->nErr !=3D 0) + goto create_view_fail; =20 struct space *select_res_space =3D 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 =3D 0; i < expr_list->nExpr; i++) { struct Expr *expr =3D 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 =3D sql_lookup_space(parse, tab_list->a); if (space =3D=3D NULL) goto delete_from_cleanup; - assert(space !=3D NULL); trigger_list =3D sql_triggers_exist(space->def, TK_DELETE, NULL, = NULL); - bool is_complex =3D trigger_list !=3D NULL || - fkey_is_required(space, NULL); + bool is_complex =3D trigger_list !=3D NULL || = fkey_is_required(space, NULL); bool is_view =3D space->def->opts.is_view; =20 /* 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 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 =3D sqlite3GetVdbe(parser); int last_instr =3D 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 !=3D NULL || vdbe_has_table_read(pParse, = space_def)) + if (trigger !=3D NULL || vdbe_has_space_read(pParse, = space_def)) useTempTable =3D 1; =20 if (useTempTable) { @@ -1210,9 +1210,7 @@ xferOptimization(Parse * pParse, /* Parser = context */ /* Affinity must be the same on all columns. */ if (dest_affinity !=3D src_affinity) return 0; - uint32_t id; - if (sql_column_collation(dest->def, i, &id) !=3D - sql_column_collation(src->def, i, &id)) + if (dest->def->fields[i].coll_id !=3D = 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 =3D 0; /* The matching = pSrcList item */ NameContext *pTopNC =3D pNC; /* First namecontext in the = list */ int isTrigger =3D 0; /* True if resolved to a trigger = column */ - struct space_def *space_def; =20 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 !=3D NULL && cntTab =3D=3D 0 - && pParse->updated_space !=3D NULL) { + if (zTab !=3D NULL && cntTab =3D=3D 0 && + pParse->updated_space !=3D NULL) { int op =3D pParse->eTriggerOp; assert(op =3D=3D TK_DELETE || op =3D=3D = TK_UPDATE || op =3D=3D TK_INSERT); + struct space_def *space_def =3D NULL; if (op !=3D TK_DELETE && sqlite3StrICmp("new", = zTab) =3D=3D 0) { pExpr->iTable =3D 1; space_def =3D = pParse->updated_space->def; @@ -323,8 +323,6 @@ lookupName(Parse * pParse, /* The parsing context = */ && sqlite3StrICmp("old", zTab) =3D=3D = 0) { pExpr->iTable =3D 0; space_def =3D = pParse->updated_space->def; - } else { - space_def =3D NULL; } =20 if (space_def !=3D NULL) { @@ -1614,8 +1612,9 @@ sqlite3ResolveSelectNames(Parse * pParse, /* The = parser context */ } =20 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 =3D 0; i < (int)def->field_count; i++) { + for (uint32_t i =3D 0; i < def->field_count; i++) { if (strcmp(def->fields[i].name, zCol) =3D=3D 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 =3D pParse->db; NameContext sNC; @@ -4021,7 +4021,8 @@ flattenSubquery(Parse * pParse, /* = Parsing context */ return 1; } =20 - /* 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 =3D pSub1 =3D pSubitem->pSelect; @@ -4599,7 +4600,7 @@ withExpand(Walker * pWalker, struct SrcList_item = *pFrom) /* Check if this is a recursive CTE. */ pSel =3D pFrom->pSelect; bMayRecursive =3D (pSel->op =3D=3D TK_ALL || pSel->op =3D=3D= TK_UNION); - int ref_counter =3D 0; + uint32_t ref_counter =3D 0; if (bMayRecursive) { int i; SrcList *pSrc =3D pFrom->pSelect->pSrc; @@ -4770,13 +4771,12 @@ selectExpander(Walker * pWalker, Select * p) * unique identifier. */ const char *name =3D = "sqlite_sq_DEADBEAFDEADBEAF"; - pFrom->space =3D - = sql_ephemeral_space_new(sqlite3ParseToplevel(pParse), - name); - struct space *space =3D pFrom->space; - + struct space *space =3D + = sql_ephemeral_space_new(sqlite3ParseToplevel(pParse), + name); if (space =3D=3D NULL) return WRC_Abort; + pFrom->space =3D space; /* * Rewrite old name with correct pointer. */ @@ -4786,7 +4786,7 @@ selectExpander(Walker * pWalker, Select * p) pSel =3D 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 =3D select; sqlite3SelectSetName(pFrom->pSelect, space->def->name); - int columns =3D space->def->field_count; - space->def->field_count =3D -1; sqlite3WalkSelect(pWalker, = pFrom->pSelect); - space->def->field_count =3D 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=3D=3DNULL. @@ -3510,7 +3514,7 @@ Select *sqlite3SelectNew(Parse *, ExprList *, = SrcList *, Expr *, ExprList *, Expr *, ExprList *, u32, Expr *, Expr *); =20 /** - * 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=E2=80=99t 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]); =20 - assert(pParse->updated_space =3D=3D NULL); - pParse->updated_space =3D new_space; + assert(pParse->new_space =3D=3D NULL); + pParse->new_space =3D new_space; =20 if (!db->init.busy && (v =3D sqlite3GetVdbe(pParse)) !=3D 0) sql_set_multi_write(pParse, true); @@ -446,9 +446,9 @@ sqlite3AddColumn(Parse * pParse, Token * pName, = struct type_def *type_def) assert(type_def !=3D NULL); char *z; sqlite3 *db =3D pParse->db; - if (pParse->updated_space =3D=3D NULL) + if (pParse->new_space =3D=3D NULL) return; - struct space_def *def =3D pParse->updated_space->def; + struct space_def *def =3D pParse->new_space->def; =20 #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 =3D=3D NULL || - NEVER(parser->updated_space->def->field_count < 1)) + if (parser->new_space =3D=3D NULL || + NEVER(parser->new_space->def->field_count < 1)) return; - struct space_def *def =3D parser->updated_space->def; + struct space_def *def =3D parser->new_space->def; struct field_def *field =3D &def->fields[def->field_count - 1]; if (field->nullable_action !=3D ON_CONFLICT_ACTION_DEFAULT && nullable_action !=3D field->nullable_action) { @@ -538,9 +538,9 @@ void sqlite3AddDefaultValue(Parse * pParse, ExprSpan * pSpan) { sqlite3 *db =3D pParse->db; - assert(pParse->updated_space->def->opts.is_temporary); - if (pParse->updated_space !=3D NULL) { - struct space_def *def =3D pParse->updated_space->def; + assert(pParse->new_space->def->opts.is_temporary); + if (pParse->new_space !=3D NULL) { + struct space_def *def =3D pParse->new_space->def; if (!sqlite3ExprIsConstantOrFunction (pSpan->pExpr, db->init.busy)) { sqlite3ErrorMsg(pParse, @@ -608,7 +608,7 @@ sqlite3AddPrimaryKey(Parse * pParse, /* = Parsing context */ { int iCol =3D -1, i; int nTerm; - struct space *space =3D pParse->updated_space; + struct space *space =3D pParse->new_space; if (space =3D=3D NULL) goto primary_key_exit; if (sql_space_primary_key(space) !=3D NULL) { @@ -688,8 +688,8 @@ void sql_add_check_constraint(struct Parse *parser, struct ExprSpan *span) { struct Expr *expr =3D span->pExpr; - if (parser->updated_space !=3D NULL) { - struct space *space =3D parser->updated_space; + if (parser->new_space !=3D NULL) { + struct space *space =3D parser->new_space; expr->u.zToken =3D 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 =3D=3D NULL) + if (pParse->new_space =3D=3D NULL) return; - struct space *space =3D pParse->updated_space; + struct space *space =3D pParse->new_space; uint32_t i =3D space->def->field_count - 1; sqlite3 *db =3D pParse->db; char *zColl =3D 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 =3D raw; =20 - if (parse->updated_space !=3D NULL) { + if (parse->new_space !=3D 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 =3D (pParse->nMem +=3D 7); struct region *region =3D &pParse->region; uint32_t table_opts_stmt_sz =3D 0; - struct space *space =3D pParse->updated_space; + struct space *space =3D pParse->new_space; char *table_opts_stmt =3D sql_encode_table_opts(region, = space->def, zStmt, = &table_opts_stmt_sz); if (table_opts_stmt =3D=3D NULL) @@ -1029,14 +1029,14 @@ vdbe_emit_fkey_create(struct Parse = *parse_context, const struct fkey_def *fk) * of statement, we don't have child * id, but we know register where it will be stored. */ - if (parse_context->updated_space !=3D NULL) { + if (parse_context->new_space !=3D 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 !=3D NULL && = fkey_is_self_referenced(fk)) { + if (parse_context->new_space !=3D 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 =3D=3D NULL) + if (parse_context->new_space =3D=3D 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 =3D pParse->updated_space; + struct space *new_space =3D pParse->new_space; if (new_space =3D=3D 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 =3D parse_context->updated_space; + struct space *space =3D parse_context->new_space; if (space =3D=3D NULL || parse_context->nErr !=3D 0) goto create_view_fail; =20 @@ -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 =3D parse_context->updated_space; + struct space *space =3D parse_context->new_space; bool is_alter =3D space =3D=3D NULL; =20 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 =3D=3D NULL) + if (parse->new_space =3D=3D NULL) goto exit_create_index; assert(token =3D=3D NULL); assert(start =3D=3D NULL); - space =3D parse->updated_space; + space =3D parse->new_space; } struct space_def *def =3D space->def; =20 @@ -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 !=3D NULL) { + if (parse->new_space !=3D NULL) { for (uint32_t i =3D 0; i < space->index_count; ++i) { struct index *existing_idx =3D space->index[i]; uint32_t iid =3D 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, =20 /* Return the number of rows that were deleted. */ if ((user_session->sql_flags & SQLITE_CountRows) !=3D 0 && - parse->updated_space !=3D NULL) { + parse->triggered_space !=3D 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 =3D=3D NULL) { + if (pParse->triggered_space =3D=3D 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 */ =20 /* Return the number of rows inserted. */ if ((user_session->sql_flags & SQLITE_CountRows) !=3D 0 && - pParse->updated_space =3D=3D NULL) { + pParse->triggered_space =3D=3D 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 !=3D NULL && cntTab =3D=3D 0 && - pParse->updated_space !=3D NULL) { + pParse->triggered_space !=3D NULL) { int op =3D pParse->eTriggerOp; assert(op =3D=3D TK_DELETE || op =3D=3D = TK_UPDATE || op =3D=3D TK_INSERT); struct space_def *space_def =3D NULL; if (op !=3D TK_DELETE && sqlite3StrICmp("new", = zTab) =3D=3D 0) { pExpr->iTable =3D 1; - space_def =3D = pParse->updated_space->def; + space_def =3D = pParse->triggered_space->def; } else if (op !=3D TK_INSERT && sqlite3StrICmp("old", zTab) =3D=3D = 0) { pExpr->iTable =3D 0; - space_def =3D = pParse->updated_space->def; + space_def =3D = pParse->triggered_space->def; } =20 if (space_def !=3D 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; =20 assert(type =3D=3D NC_IsCheck || type =3D=3D 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=3D=3DNULL. 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 =3D=3D NULL); + assert(pParse->new_space =3D=3D NULL); assert(pParse->parsed_ast.trigger =3D=3D NULL); assert(pParse->nVar =3D=3D 0); assert(pParse->pVList =3D=3D 0); @@ -550,7 +550,7 @@ sqlite3RunParser(Parse * pParse, const char *zSql, = char **pzErrMsg) sqlite3VdbeDelete(pParse->pVdbe); pParse->pVdbe =3D 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 =3D pParse->pVdbe; sqlite3 *db =3D pParse->db; =20 - assert(pParse->updated_space !=3D NULL && pParse->pToplevel !=3D = NULL); + assert(pParse->triggered_space !=3D NULL && pParse->pToplevel !=3D= NULL); assert(pStepList); assert(v !=3D 0); =20 @@ -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 =3D pSubParse; - pSubParse->updated_space =3D space; + pSubParse->triggered_space =3D space; pSubParse->pToplevel =3D pTop; pSubParse->eTriggerOp =3D trigger->op; pSubParse->nQueryLoop =3D 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 =3D=3D NULL) { + && pParse->triggered_space =3D=3D NULL) { regRowCount =3D ++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 =3D=3D NULL) { + && pParse->triggered_space =3D=3D NULL) { sqlite3VdbeAddOp2(v, OP_AddImm, regRowCount, 1); } =20 @@ -525,7 +525,7 @@ sqlite3Update(Parse * pParse, /* The = parser context */ =20 /* Return the number of rows that were changed. */ if (user_session->sql_flags & SQLITE_CountRows && - pParse->updated_space =3D=3D NULL) { + pParse->triggered_space =3D=3D NULL) { sqlite3VdbeAddOp2(v, OP_ResultRow, regRowCount, 1); sqlite3VdbeSetNumCols(v, 1); sqlite3VdbeSetColName(v, 0, COLNAME_NAME, "rows = updated",