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 2F86224E99 for ; Tue, 10 Jul 2018 09:45:27 -0400 (EDT) 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 MyHyJRpCEzfU for ; Tue, 10 Jul 2018 09:45:27 -0400 (EDT) Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (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 B9A7921971 for ; Tue, 10 Jul 2018 09:45:26 -0400 (EDT) From: Kirill Shcherbatov Subject: [tarantool-patches] [PATCH v1 2/2] sql: remove OP_LoadPtr Date: Tue, 10 Jul 2018 16:45:21 +0300 Message-Id: <837b569e130ba06fdf2e6c8cd5554adcb4a66b1a.1531230100.git.kshcherbatov@tarantool.org> In-Reply-To: <94a3289e26898b8f779450bf620d8fef454844c7.1531140049.git.kshcherbatov@tarantool.org> References: <94a3289e26898b8f779450bf620d8fef454844c7.1531140049.git.kshcherbatov@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: v.shpilevoy@tarantool.org From: Vladislav Shpilevoy This opcode was used when Vdbe had to store key_def in P4 for OP_OpenRead/Write, so P4 was occupied and OP_LoadPtr was used to store space pointer in another opcode. But now P4 is free for OpenRead/Write and space pointer can be stored here. Alongside, some useless key_def duplications are removed. --- src/box/sql/analyze.c | 8 ++------ src/box/sql/build.c | 20 ++++++-------------- src/box/sql/delete.c | 16 ++-------------- src/box/sql/insert.c | 18 ++++-------------- src/box/sql/pragma.c | 15 +++++++++++---- src/box/sql/vdbe.c | 41 ++++++----------------------------------- 6 files changed, 31 insertions(+), 87 deletions(-) diff --git a/src/box/sql/analyze.c b/src/box/sql/analyze.c index ff3e735..d84f1c0 100644 --- a/src/box/sql/analyze.c +++ b/src/box/sql/analyze.c @@ -794,7 +794,6 @@ analyzeOneTable(Parse * pParse, /* Parser context */ int iTabCur; /* Table cursor */ Vdbe *v; /* The virtual machine being built up */ int i; /* Loop counter */ - int space_ptr_reg = iMem++; int regStat4 = iMem++; /* Register to hold Stat4Accum object */ int regChng = iMem++; /* Index of changed index field */ int regKey = iMem++; /* Key argument passed to stat_push() */ @@ -893,11 +892,8 @@ analyzeOneTable(Parse * pParse, /* Parser context */ struct space *space = space_by_id(SQLITE_PAGENO_TO_SPACEID(pIdx->tnum)); assert(space != NULL); - sqlite3VdbeAddOp4(v, OP_LoadPtr, 0, space_ptr_reg, 0, - (void*)space, P4_SPACEPTR); - sqlite3VdbeAddOp3(v, OP_OpenRead, iIdxCur, pIdx->tnum, - space_ptr_reg); - sql_vdbe_set_p4_key_def(pParse, pIdx); + sqlite3VdbeAddOp4(v, OP_OpenRead, iIdxCur, pIdx->tnum, + 0, (void *) space, P4_SPACEPTR); VdbeComment((v, "%s", pIdx->zName)); /* Invoke the stat_init() function. The arguments are: diff --git a/src/box/sql/build.c b/src/box/sql/build.c index 5f7a35a..26af0fe 100644 --- a/src/box/sql/build.c +++ b/src/box/sql/build.c @@ -1108,12 +1108,8 @@ vdbe_emit_open_cursor(struct Parse *parse_context, int cursor, int index_id, struct space *space) { assert(space != NULL); - struct Vdbe *vdbe = parse_context->pVdbe; - int space_ptr_reg = ++parse_context->nMem; - sqlite3VdbeAddOp4(vdbe, OP_LoadPtr, 0, space_ptr_reg, 0, (void*)space, - P4_SPACEPTR); - return sqlite3VdbeAddOp3(vdbe, OP_OpenWrite, cursor, index_id, - space_ptr_reg); + return sqlite3VdbeAddOp4(parse_context->pVdbe, OP_OpenWrite, cursor, + index_id, 0, (void *) space, P4_SPACEPTR); } /* * Generate code that will increment the schema cookie. @@ -2961,7 +2957,6 @@ sql_create_index(struct Parse *parse, struct Token *token, Vdbe *v; char *zStmt; int iCursor = parse->nTab++; - int index_space_ptr_reg = parse->nTab++; int iSpaceId, iIndexId, iFirstSchemaCol; v = sqlite3GetVdbe(parse); @@ -2969,12 +2964,9 @@ sql_create_index(struct Parse *parse, struct Token *token, goto exit_create_index; sql_set_multi_write(parse, true); - - - sqlite3VdbeAddOp2(v, OP_SIDtoPtr, BOX_INDEX_ID, - index_space_ptr_reg); - sqlite3VdbeAddOp4Int(v, OP_OpenWrite, iCursor, 0, - index_space_ptr_reg, 6); + sqlite3VdbeAddOp4(v, OP_OpenWrite, iCursor, 0, 0, + (void *)space_by_id(BOX_INDEX_ID), + P4_SPACEPTR); sqlite3VdbeChangeP5(v, OPFLAG_SEEKEQ); /* @@ -3943,7 +3935,7 @@ vdbe_emit_halt_with_presence_test(struct Parse *parser, int space_id, int cursor = parser->nTab++; vdbe_emit_open_cursor(parser, cursor, index_id, space_by_id(space_id)); - int name_reg = parser->nMem++; + int name_reg = ++parser->nMem; int label = sqlite3VdbeAddOp4(v, OP_String8, 0, name_reg, 0, name, P4_DYNAMIC); sqlite3VdbeAddOp4Int(v, cond_opcode, cursor, label + 3, name_reg, 1); diff --git a/src/box/sql/delete.c b/src/box/sql/delete.c index 66dc0fc..24122e8 100644 --- a/src/box/sql/delete.c +++ b/src/box/sql/delete.c @@ -335,23 +335,11 @@ sql_table_delete_from(struct Parse *parse, struct SrcList *tab_list, iAddrOnce = sqlite3VdbeAddOp0(v, OP_Once); VdbeCoverage(v); } - - int space_ptr_reg = ++parse->nMem; - sqlite3VdbeAddOp4(v, OP_LoadPtr, 0, space_ptr_reg, 0, - (void *)space, P4_SPACEPTR); - int tnum = SQLITE_PAGENO_FROM_SPACEID_AND_INDEXID(space_id, 0); - sqlite3VdbeAddOp3(v, OP_OpenWrite, tab_cursor, - tnum, space_ptr_reg); - struct key_def *def = key_def_dup(pk_def); - if (def == NULL) { - sqlite3OomFault(parse->db); - goto delete_from_cleanup; - } - sqlite3VdbeAppendP4(v, def, P4_KEYDEF); - + sqlite3VdbeAddOp4(v, OP_OpenWrite, tab_cursor, tnum, 0, + (void *) space, P4_SPACEPTR); VdbeComment((v, "%s", space->index[0]->def->name)); if (one_pass == ONEPASS_MULTI) diff --git a/src/box/sql/insert.c b/src/box/sql/insert.c index ca194e6..bb1a225 100644 --- a/src/box/sql/insert.c +++ b/src/box/sql/insert.c @@ -204,13 +204,8 @@ vdbe_has_table_read(struct Parse *parser, const struct Table *table) * and Write cursors. */ if (op->opcode == OP_OpenRead || op->opcode == OP_OpenWrite) { - assert(i > 1); - struct VdbeOp *space_var_op = - sqlite3VdbeGetOp(v, i - 1); - assert(space_var_op != NULL); - assert(space_var_op->opcode == OP_LoadPtr); - struct space *space = space_var_op->p4.space; - + assert(op->p4type == P4_SPACEPTR); + struct space *space = op->p4.space; if (space->def->id == table->def->id) return true; @@ -1581,10 +1576,6 @@ sqlite3OpenTableAndIndices(Parse * pParse, /* Parsing context */ *piIdxCur = iBase; struct space *space = space_by_id(SQLITE_PAGENO_TO_SPACEID(pTab->tnum)); assert(space != NULL); - int space_ptr_reg = ++pParse->nMem; - sqlite3VdbeAddOp4(v, OP_LoadPtr, 0, space_ptr_reg, 0, (void*)space, - P4_SPACEPTR); - /* One iteration of this cycle adds OpenRead/OpenWrite which * opens cursor for current index. * @@ -1631,9 +1622,8 @@ sqlite3OpenTableAndIndices(Parse * pParse, /* Parsing context */ p5 = 0; } if (aToOpen == 0 || aToOpen[i + 1]) { - sqlite3VdbeAddOp3(v, op, iIdxCur, pIdx->tnum, - space_ptr_reg); - sql_vdbe_set_p4_key_def(pParse, pIdx); + sqlite3VdbeAddOp4(v, op, iIdxCur, pIdx->tnum, 0, + (void *) space, P4_SPACEPTR); sqlite3VdbeChangeP5(v, p5); VdbeComment((v, "%s", pIdx->zName)); } diff --git a/src/box/sql/pragma.c b/src/box/sql/pragma.c index 31581b1..eea6a0b 100644 --- a/src/box/sql/pragma.c +++ b/src/box/sql/pragma.c @@ -685,14 +685,21 @@ sqlite3Pragma(Parse * pParse, Token * pId, /* First part of [schema.]id field */ pParent, OP_OpenRead); } else { - sqlite3VdbeAddOp3(v, + struct space *space = + space_cache_find( + pIdx-> + pTable-> + def->id); + assert(space != NULL); + sqlite3VdbeAddOp4(v, OP_OpenRead, i, pIdx-> tnum, - 0); - sql_vdbe_set_p4_key_def(pParse, - pIdx); + 0, + (void *)space, + P4_SPACEPTR); + } } else { k = 0; diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c index 7a4d376..734d8cc 100644 --- a/src/box/sql/vdbe.c +++ b/src/box/sql/vdbe.c @@ -1077,19 +1077,6 @@ case OP_Int64: { /* out2 */ break; } -/* Opcode: LoadPtr * P2 * P4 * - * Synopsis: r[P2] = P4 - * - * P4 is a generic or space pointer. Copy it into register P2. - */ -case OP_LoadPtr: { - pOut = out2Prerelease(p, pOp); - assert(pOp->p4type == P4_PTR || pOp->p4type == P4_SPACEPTR ); - pOut->u.p = pOp->p4.space; - pOut->flags = MEM_Ptr; - break; -} - #ifndef SQLITE_OMIT_FLOATING_POINT /* Opcode: Real * P2 * P4 * * Synopsis: r[P2]=P4 @@ -3137,26 +3124,15 @@ case OP_SetCookie: { } /* Opcode: OpenRead P1 P2 P3 P4 P5 - * Synopsis: index id = P2, space ptr = P3 + * Synopsis: index id = P2, space ptr = P4 * - * Open a cursor for a space specified by pointer in P3 and index + * Open a cursor for a space specified by pointer in P4 and index * id in P2. Give the new cursor an identifier of P1. The P1 * values need not be contiguous but all P1 values should be * small integers. It is an error for P1 to be negative. - * - * The P4 value may be a pointer to a key_def structure. - * If it is a pointer to a key_def structure, then said structure - * defines the content and collatining sequence of the index - * being opened. Otherwise, P4 is NULL. - * - * If schema has changed since compile time, VDBE ends execution - * with appropriate error message. The only exception is - * when P5 is set to OPFLAG_FRESH_PTR, which means that - * space pointer has been fetched in runtime right before - * this opcode. */ /* Opcode: ReopenIdx P1 P2 P3 P4 P5 - * Synopsis: index id = P2, space ptr = P3 + * Synopsis: index id = P2, space ptr = P4 * * The ReopenIdx opcode works exactly like OpenRead except that * it first checks to see if the cursor on P1 is already open @@ -3166,7 +3142,7 @@ case OP_SetCookie: { * The ReopenIdx opcode may only be used with P5 == 0. */ /* Opcode: OpenWrite P1 P2 P3 P4 P5 - * Synopsis: index id = P2, space ptr = P3 + * Synopsis: index id = P2, space ptr = P4 * * For now, OpenWrite is an alias for OpenRead. * It exists just due legacy reasons and should be removed: @@ -3182,9 +3158,7 @@ case OP_ReopenIdx: { assert(pOp->p5==0 || pOp->p5==OPFLAG_SEEKEQ); pCur = p->apCsr[pOp->p1]; p2 = pOp->p2; - pIn3 = &aMem[pOp->p3]; - assert(pIn3->flags & MEM_Ptr); - if (pCur && pCur->uc.pCursor->space == (struct space *) pIn3->u.p && + if (pCur && pCur->uc.pCursor->space == pOp->p4.space && pCur->uc.pCursor->index->def->iid == SQLITE_PAGENO_TO_INDEXID(p2)) { goto open_cursor_set_hints; } @@ -3209,10 +3183,7 @@ case OP_OpenWrite: goto abort_due_to_error; } p2 = pOp->p2; - pIn3 = &aMem[pOp->p3]; - assert(pIn3->flags & MEM_Ptr); - struct space *space = ((struct space *) pIn3->u.p); - assert(space != NULL); + struct space *space = pOp->p4.space; struct index *index = space_index(space, SQLITE_PAGENO_TO_INDEXID(p2)); assert(index != NULL); /* -- 2.7.4