From: Nikita Pettik <korablev@tarantool.org> To: tarantool-patches@freelists.org Cc: v.shpilevoy@tarantool.org, kostja@tarantool.org, Nikita Pettik <korablev@tarantool.org> Subject: [tarantool-patches] [PATCH v2 3/5] sql: refactor getNewIid() function Date: Wed, 23 Jan 2019 20:56:16 +0300 [thread overview] Message-ID: <0ffc48deb63d5c5f65ee133c72a8f51c35339307.1548265148.git.korablev@tarantool.org> (raw) In-Reply-To: <cover.1548265148.git.korablev@tarantool.org> In-Reply-To: <cover.1548265148.git.korablev@tarantool.org> This commit includes no functional changes. Lets simply rewrite getNewIid() function according to Tarantool codestyle. Part of #3914 --- src/box/sql/build.c | 73 ++++++++++++++++++++++++++--------------------------- 1 file changed, 36 insertions(+), 37 deletions(-) diff --git a/src/box/sql/build.c b/src/box/sql/build.c index d0e19407a..d7dcc5cb4 100644 --- a/src/box/sql/build.c +++ b/src/box/sql/build.c @@ -2064,45 +2064,43 @@ sql_drop_foreign_key(struct Parse *parse_context) sqlite3VdbeChangeP5(sqlite3GetVdbe(parse_context), OPFLAG_NCHANGE); } -/* - * Generate code to determine next free Iid in the space identified by - * the iSpaceId. Return register number holding the result. +/** + * Generate code to determine next free index id in + * the space identified by the @space_id. + * Return register holding the result. + * + * Overall VDBE program logic is following: + * + * 1 Seek for space id in _index, goto l1 if seeks fails. + * 2 Goto l2. + * 3 l1: Halt. + * 4 l2: Fetch index id from _index record. */ static int -getNewIid(Parse * pParse, int iSpaceId, int iCursor) +generate_index_id(struct Parse *parse, uint32_t space_id, int cursor) { - Vdbe *v = sqlite3GetVdbe(pParse); - int iRes = ++pParse->nMem; - int iKey = ++pParse->nMem; - int iSeekInst, iGotoInst; - - sqlite3VdbeAddOp2(v, OP_Integer, iSpaceId, iKey); - iSeekInst = sqlite3VdbeAddOp4Int(v, OP_SeekLE, iCursor, 0, iKey, 1); - sqlite3VdbeAddOp4Int(v, OP_IdxLT, iCursor, 0, iKey, 1); - - /* - * If SeekLE succeeds, the control falls through here, skipping - * IdxLt. - * - * If it fails (no entry with the given key prefix: invalid spaceId) - * VDBE jumps to the next code block (jump target is IMM, fixed up - * later with sqlite3VdbeJumpHere()). - */ - iGotoInst = sqlite3VdbeAddOp0(v, OP_Goto); /* Jump over Halt */ - - /* Invalid spaceId detected. Halt now. */ - sqlite3VdbeJumpHere(v, iSeekInst); - sqlite3VdbeJumpHere(v, iSeekInst + 1); - sqlite3VdbeAddOp4(v, - OP_Halt, SQLITE_ERROR, ON_CONFLICT_ACTION_FAIL, 0, - sqlite3MPrintf(pParse->db, "Invalid space id: %d", - iSpaceId), P4_DYNAMIC); - - /* Fetch iid from the row and ++it. */ - sqlite3VdbeJumpHere(v, iGotoInst); - sqlite3VdbeAddOp3(v, OP_Column, iCursor, 1, iRes); - sqlite3VdbeAddOp2(v, OP_AddImm, iRes, 1); - return iRes; + struct Vdbe *v = sqlite3GetVdbe(parse); + int key_reg = ++parse->nMem; + + sqlite3VdbeAddOp2(v, OP_Integer, space_id, key_reg); + int seek_adr = sqlite3VdbeAddOp4Int(v, OP_SeekLE, cursor, 0, + key_reg, 1); + sqlite3VdbeAddOp4Int(v, OP_IdxLT, cursor, 0, key_reg, 1); + /* Jump over Halt block. */ + int goto_succ_addr = sqlite3VdbeAddOp0(v, OP_Goto); + /* Invalid space id handling block starts here. */ + sqlite3VdbeJumpHere(v, seek_adr); + sqlite3VdbeJumpHere(v, seek_adr + 1); + sqlite3VdbeAddOp4(v, OP_Halt, SQLITE_ERROR, ON_CONFLICT_ACTION_FAIL, 0, + sqlite3MPrintf(parse->db, "Invalid space id: %d", + space_id), P4_DYNAMIC); + + sqlite3VdbeJumpHere(v, goto_succ_addr); + /* Fetch iid from the row and increment it. */ + int iid_reg = ++parse->nMem; + sqlite3VdbeAddOp3(v, OP_Column, cursor, BOX_INDEX_FIELD_ID, iid_reg); + sqlite3VdbeAddOp2(v, OP_AddImm, iid_reg, 1); + return iid_reg; } /** @@ -2552,7 +2550,8 @@ sql_create_index(struct Parse *parse) { (void *)space_by_id(BOX_INDEX_ID), P4_SPACEPTR); sqlite3VdbeChangeP5(vdbe, OPFLAG_SEEKEQ); - int index_id = getNewIid(parse, def->id, cursor); + + int index_id = generate_index_id(parse, def->id, cursor); sqlite3VdbeAddOp1(vdbe, OP_Close, cursor); vdbe_emit_create_index(parse, def, index->def, def->id, index_id); -- 2.15.1
next prev parent reply other threads:[~2019-01-23 17:56 UTC|newest] Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-01-23 17:56 [tarantool-patches] [PATCH v2 0/5] Introduce ALTER TABLE ADD CONSTRAINT UNIQUE/PK Nikita Pettik 2019-01-23 17:56 ` [tarantool-patches] [PATCH v2 1/5] sql: introduce structs assembling DDL arguments during parsing Nikita Pettik 2019-01-24 8:36 ` [tarantool-patches] " Konstantin Osipov 2019-01-24 10:47 ` n.pettik 2019-01-24 12:30 ` Konstantin Osipov 2019-01-29 19:03 ` n.pettik 2019-01-29 19:29 ` Vladislav Shpilevoy 2019-01-29 20:04 ` n.pettik 2019-01-29 20:20 ` Vladislav Shpilevoy 2019-01-29 21:25 ` n.pettik 2019-01-31 19:32 ` n.pettik 2019-02-04 15:25 ` Vladislav Shpilevoy 2019-02-08 14:25 ` n.pettik 2019-02-15 20:13 ` Vladislav Shpilevoy 2019-02-27 22:56 ` n.pettik 2019-03-12 12:50 ` Vladislav Shpilevoy 2019-03-14 18:13 ` n.pettik 2019-03-25 11:25 ` Vladislav Shpilevoy 2019-03-26 18:01 ` n.pettik 2019-03-26 18:06 ` Vladislav Shpilevoy 2019-03-27 13:00 ` n.pettik 2019-03-27 13:29 ` Vladislav Shpilevoy 2019-03-27 13:44 ` n.pettik 2019-03-27 14:03 ` Vladislav Shpilevoy 2019-03-27 14:11 ` n.pettik 2019-01-23 17:56 ` [tarantool-patches] [PATCH v2 2/5] sql: rework ALTER TABLE grammar Nikita Pettik 2019-01-23 17:56 ` Nikita Pettik [this message] 2019-01-23 17:56 ` [tarantool-patches] [PATCH v2 4/5] sql: fix error message for improperly created index Nikita Pettik 2019-02-08 17:14 ` [tarantool-patches] " Konstantin Osipov 2019-01-23 17:56 ` [tarantool-patches] [PATCH v2 5/5] sql: introduce ALTER TABLE ADD CONSTRAINT UNIQUE/PRIMARY KEY Nikita Pettik 2019-01-24 8:31 ` [tarantool-patches] " Konstantin Osipov 2019-01-29 19:29 ` Vladislav Shpilevoy 2019-02-08 17:16 ` Konstantin Osipov 2019-02-08 17:36 ` n.pettik
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=0ffc48deb63d5c5f65ee133c72a8f51c35339307.1548265148.git.korablev@tarantool.org \ --to=korablev@tarantool.org \ --cc=kostja@tarantool.org \ --cc=tarantool-patches@freelists.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [tarantool-patches] [PATCH v2 3/5] sql: refactor getNewIid() function' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox