Tarantool development patches archive
 help / color / mirror / Atom feed
From: Kirill Shcherbatov <kshcherbatov@tarantool.org>
To: tarantool-patches@freelists.org, v.shpilevoy@tarantool.org
Cc: Kirill Shcherbatov <kshcherbatov@tarantool.org>
Subject: [tarantool-patches] [PATCH v1 4/6] sql: release OP_Idx{Insert,Replace} p2 argument
Date: Thu, 29 Nov 2018 16:09:48 +0300	[thread overview]
Message-ID: <bf1396dd8a01ba5578811ee11ee04f20dd82f97d.1543496928.git.kshcherbatov@tarantool.org> (raw)
In-Reply-To: <cover.1543496928.git.kshcherbatov@tarantool.org>

Start using p3 argument instead of p2 argument in OP_Insert and
OP_Replace opcodes. The p2 register is typically used for jump
to label and resolveP2Values() is able to patch it. As we
going to support interrupt handler for OP_Insert and OP_Replace
instructions, we need a free p2 register to reuse it by
appointment.

Need for #3691
---
 src/box/sql/delete.c    |  2 +-
 src/box/sql/expr.c      |  4 ++--
 src/box/sql/insert.c    |  2 +-
 src/box/sql/select.c    | 33 +++++++++++++++++++++------------
 src/box/sql/update.c    |  2 +-
 src/box/sql/vdbe.c      | 10 +++++-----
 src/box/sql/where.c     |  2 +-
 src/box/sql/wherecode.c |  5 +++--
 8 files changed, 35 insertions(+), 25 deletions(-)

diff --git a/src/box/sql/delete.c b/src/box/sql/delete.c
index f9c42fdec..9bb38abe8 100644
--- a/src/box/sql/delete.c
+++ b/src/box/sql/delete.c
@@ -342,7 +342,7 @@ sql_table_delete_from(struct Parse *parse, struct SrcList *tab_list,
 			 * by malloc.
 			 */
 			sqlite3VdbeChangeP5(v, 1);
-			sqlite3VdbeAddOp2(v, OP_IdxInsert, reg_key, reg_eph);
+			sqlite3VdbeAddOp3(v, OP_IdxInsert, reg_key, 0, reg_eph);
 		}
 
 		/* If this DELETE cannot use the ONEPASS strategy,
diff --git a/src/box/sql/expr.c b/src/box/sql/expr.c
index b67b22c23..64a13bbb8 100644
--- a/src/box/sql/expr.c
+++ b/src/box/sql/expr.c
@@ -2864,8 +2864,8 @@ sqlite3CodeSubselect(Parse * pParse,	/* Parsing context */
 							  1, r2, &affinity, 1);
 					sqlite3ExprCacheAffinityChange(pParse,
 								       r3, 1);
-					sqlite3VdbeAddOp2(v, OP_IdxInsert, r2,
-							  reg_eph);
+					sqlite3VdbeAddOp3(v, OP_IdxInsert, r2,
+							  0, reg_eph);
 				}
 				sqlite3ReleaseTempReg(pParse, r1);
 				sqlite3ReleaseTempReg(pParse, r2);
diff --git a/src/box/sql/insert.c b/src/box/sql/insert.c
index 6b76bb6da..b099178d7 100644
--- a/src/box/sql/insert.c
+++ b/src/box/sql/insert.c
@@ -492,7 +492,7 @@ sqlite3Insert(Parse * pParse,	/* Parser context */
 					  nColumn + 1, regRec);
 			/* Set flag to save memory allocating one by malloc. */
 			sqlite3VdbeChangeP5(v, 1);
-			sqlite3VdbeAddOp2(v, OP_IdxInsert, regRec, reg_eph);
+			sqlite3VdbeAddOp3(v, OP_IdxInsert, regRec, 0, reg_eph);
 
 			sqlite3VdbeGoto(v, addrL);
 			sqlite3VdbeJumpHere(v, addrL);
diff --git a/src/box/sql/select.c b/src/box/sql/select.c
index ca709b44f..afb60761f 100644
--- a/src/box/sql/select.c
+++ b/src/box/sql/select.c
@@ -780,7 +780,8 @@ pushOntoSorter(Parse * pParse,		/* Parser context */
 		sqlite3VdbeAddOp2(v, OP_SorterInsert, pSort->iECursor,
 				  regRecord);
 	} else {
-		sqlite3VdbeAddOp2(v, OP_IdxInsert, regRecord, pSort->reg_eph);
+		sqlite3VdbeAddOp3(v, OP_IdxInsert, regRecord, 0,
+				  pSort->reg_eph);
 	}
 
 	if (iLimit) {
@@ -862,7 +863,7 @@ vdbe_insert_distinct(struct Parse *parse, int cursor, int reg_eph,
 	int r1 = sqlite3GetTempReg(parse);
 	sqlite3VdbeAddOp4Int(v, OP_Found, cursor, addr_repeat, reg_data, n);
 	sqlite3VdbeAddOp3(v, OP_MakeRecord, reg_data, n, r1);
-	sqlite3VdbeAddOp2(v, OP_IdxInsert, r1, reg_eph);
+	sqlite3VdbeAddOp3(v, OP_IdxInsert, r1, 0, reg_eph);
 	sqlite3ReleaseTempReg(parse, r1);
 }
 
@@ -1099,7 +1100,8 @@ selectInnerLoop(Parse * pParse,		/* The parser context */
 			r1 = sqlite3GetTempReg(pParse);
 			sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult,
 					  nResultCol, r1);
-			sqlite3VdbeAddOp2(v, OP_IdxInsert,  r1, pDest->reg_eph);
+			sqlite3VdbeAddOp3(v, OP_IdxInsert,  r1, 0,
+					  pDest->reg_eph);
 			sqlite3ReleaseTempReg(pParse, r1);
 			break;
 		}
@@ -1142,7 +1144,7 @@ selectInnerLoop(Parse * pParse,		/* The parser context */
 				sqlite3VdbeAddOp4Int(v, OP_Found, iParm + 1,
 						     addr, r1, 0);
 				VdbeCoverage(v);
-				sqlite3VdbeAddOp2(v, OP_IdxInsert, r1,
+				sqlite3VdbeAddOp3(v, OP_IdxInsert, r1, 0,
 						  pDest->reg_eph + 1);
 				assert(pSort == 0);
 			}
@@ -1167,7 +1169,8 @@ selectInnerLoop(Parse * pParse,		/* The parser context */
 				sqlite3VdbeAddOp3(v, OP_MakeRecord, regCopy, nResultCol + 1, regRec);
 				/* Set flag to save memory allocating one by malloc. */
 				sqlite3VdbeChangeP5(v, 1);
-				sqlite3VdbeAddOp2(v, OP_IdxInsert, regRec, pDest->reg_eph);
+				sqlite3VdbeAddOp3(v, OP_IdxInsert, regRec, 0,
+						  pDest->reg_eph);
 				sqlite3ReleaseTempReg(pParse, regRec);
 				sqlite3ReleaseTempRange(pParse, regCopy, nResultCol + 1);
 			}
@@ -1197,7 +1200,8 @@ selectInnerLoop(Parse * pParse,		/* The parser context */
 				sqlite3ExprCacheAffinityChange(pParse,
 							       regResult,
 							       nResultCol);
-				sqlite3VdbeAddOp2(v, OP_IdxInsert, r1, pDest->reg_eph);
+				sqlite3VdbeAddOp3(v, OP_IdxInsert, r1, 0,
+						  pDest->reg_eph);
 				sqlite3ReleaseTempReg(pParse, r1);
 			}
 			break;
@@ -1280,7 +1284,7 @@ selectInnerLoop(Parse * pParse,		/* The parser context */
 			sqlite3VdbeAddOp3(v, OP_MakeRecord, regResult,
 					  nResultCol, r3);
 			if (eDest == SRT_DistQueue) {
-				sqlite3VdbeAddOp2(v, OP_IdxInsert, r3,
+				sqlite3VdbeAddOp3(v, OP_IdxInsert, r3, 0,
 						  pDest->reg_eph + 1);
 			}
 			for (i = 0; i < nKey; i++) {
@@ -1291,7 +1295,8 @@ selectInnerLoop(Parse * pParse,		/* The parser context */
 			}
 			sqlite3VdbeAddOp2(v, OP_Sequence, iParm, r2 + nKey);
 			sqlite3VdbeAddOp3(v, OP_MakeRecord, r2, nKey + 2, r1);
-			sqlite3VdbeAddOp2(v, OP_IdxInsert, r1, pDest->reg_eph);
+			sqlite3VdbeAddOp3(v, OP_IdxInsert, r1, 0,
+					  pDest->reg_eph);
 			if (addrTest)
 				sqlite3VdbeJumpHere(v, addrTest);
 			sqlite3ReleaseTempReg(pParse, r1);
@@ -1606,7 +1611,8 @@ generateSortTail(Parse * pParse,	/* Parsing context */
 					  regTupleid);
 			sqlite3VdbeAddOp3(v, OP_Copy, regRow, regCopy, nSortData - 1);
 			sqlite3VdbeAddOp3(v, OP_MakeRecord, regCopy, nColumn + 1, regRow);
-			sqlite3VdbeAddOp2(v, OP_IdxInsert, regRow, pDest->reg_eph);
+			sqlite3VdbeAddOp3(v, OP_IdxInsert, regRow, 0,
+					  pDest->reg_eph);
 			sqlite3ReleaseTempReg(pParse, regCopy);
 			break;
 		}
@@ -1616,7 +1622,8 @@ generateSortTail(Parse * pParse,	/* Parsing context */
 			sqlite3VdbeAddOp4(v, OP_MakeRecord, regRow, nColumn,
 					  regTupleid, pDest->zAffSdst, nColumn);
 			sqlite3ExprCacheAffinityChange(pParse, regRow, nColumn);
-			sqlite3VdbeAddOp2(v, OP_IdxInsert, regTupleid, pDest->reg_eph);
+			sqlite3VdbeAddOp3(v, OP_IdxInsert, regTupleid, 0,
+					  pDest->reg_eph);
 			break;
 		}
 	case SRT_Mem:{
@@ -3039,7 +3046,8 @@ generateOutputSubroutine(struct Parse *parse, struct Select *p,
 					  in->nSdst + 1, regRec);
 			/* Set flag to save memory allocating one by malloc. */
 			sqlite3VdbeChangeP5(v, 1);
-			sqlite3VdbeAddOp2(v, OP_IdxInsert, regRec, dest->reg_eph);
+			sqlite3VdbeAddOp3(v, OP_IdxInsert, regRec, 0,
+					  dest->reg_eph);
 			sqlite3ReleaseTempRange(parse, regCopy, in->nSdst + 1);
 			sqlite3ReleaseTempReg(parse, regRec);
 			break;
@@ -3055,7 +3063,8 @@ generateOutputSubroutine(struct Parse *parse, struct Select *p,
 					  in->nSdst);
 			sqlite3ExprCacheAffinityChange(parse, in->iSdst,
 						       in->nSdst);
-			sqlite3VdbeAddOp2(v, OP_IdxInsert, r1, dest->reg_eph);
+			sqlite3VdbeAddOp3(v, OP_IdxInsert, r1, 0,
+					  dest->reg_eph);
 			sqlite3ReleaseTempReg(parse, r1);
 			break;
 		}
diff --git a/src/box/sql/update.c b/src/box/sql/update.c
index 0e2d0fde8..cc69e2f30 100644
--- a/src/box/sql/update.c
+++ b/src/box/sql/update.c
@@ -284,7 +284,7 @@ sqlite3Update(Parse * pParse,		/* The parser context */
 		 * malloc.
 		 */
 		sqlite3VdbeChangeP5(v, 1);
-		sqlite3VdbeAddOp2(v, OP_IdxInsert, regKey, reg_eph);
+		sqlite3VdbeAddOp3(v, OP_IdxInsert, regKey, 0, reg_eph);
 	}
 	/* End the database scan loop.
 	 */
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index bf6f4cdd1..8fdabc212 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -4392,12 +4392,12 @@ case OP_SorterInsert: {      /* in2 */
 	break;
 }
 
-/* Opcode: IdxInsert P1 P2 * P4 P5
+/* Opcode: IdxInsert P1 * P3 P4 P5
  * Synopsis: key=r[P1]
  *
  * @param P1 Index of a register with MessagePack data to insert.
- * @param P2 If P4 is not set, then P2 is register containing pointer
- *           to space to insert into.
+ * @param P3 If P4 is not set, then P3 is register containing
+ *           pointer to space to insert into.
  * @param P4 Pointer to the struct space to insert to.
  * @param P5 Flags. If P5 contains OPFLAG_NCHANGE, then VDBE
  *        accounts the change in a case of successful insertion in
@@ -4405,7 +4405,7 @@ case OP_SorterInsert: {      /* in2 */
  *        we are processing INSERT OR INGORE statement. Thus, in
  *        case of conflict we don't raise an error.
  */
-/* Opcode: IdxReplace2 P1 * * P4 P5
+/* Opcode: IdxReplace2 P1 * P3 P4 P5
  * Synopsis: key=r[P1]
  *
  * This opcode works exactly as IdxInsert does, but in Tarantool
@@ -4424,7 +4424,7 @@ case OP_IdxInsert: {
 	if (pOp->p4type == P4_SPACEPTR)
 		space = pOp->p4.space;
 	else
-		space = aMem[pOp->p2].u.p;
+		space = aMem[pOp->p3].u.p;
 	assert(space != NULL);
 	if (space->def->id != 0) {
 		/* Make sure that memory has been allocated on region. */
diff --git a/src/box/sql/where.c b/src/box/sql/where.c
index 9c3462bc0..9b0652357 100644
--- a/src/box/sql/where.c
+++ b/src/box/sql/where.c
@@ -878,7 +878,7 @@ constructAutomaticIndex(Parse * pParse,			/* The parsing context */
 	regRecord = sqlite3GetTempReg(pParse);
 	regBase = sql_generate_index_key(pParse, pIdx, pLevel->iTabCur,
 					 regRecord, NULL, 0);
-	sqlite3VdbeAddOp2(v, OP_IdxInsert, pLevel->iIdxCur, regRecord);
+	sqlite3VdbeAddOp3(v, OP_IdxInsert, pLevel->iIdxCur, 0, regRecord);
 	if (pTabItem->fg.viaCoroutine) {
 		sqlite3VdbeChangeP2(v, addrCounter, regBase + n);
 		translateColumnToCopy(v, addrTop, pLevel->iTabCur,
diff --git a/src/box/sql/wherecode.c b/src/box/sql/wherecode.c
index b124a1d53..fee13cde3 100644
--- a/src/box/sql/wherecode.c
+++ b/src/box/sql/wherecode.c
@@ -1550,9 +1550,10 @@ sqlite3WhereCodeOneLoopStart(WhereInfo * pWInfo,	/* Complete information about t
 							sqlite3VdbeAddOp3
 								(v, OP_MakeRecord,
 								 r, pk_part_count, regPk);
-							sqlite3VdbeAddOp2
+							sqlite3VdbeAddOp3
 								(v, OP_IdxInsert,
-								 regPk, reg_row_set);
+								 regPk, 0,
+								 reg_row_set);
 						}
 
 						/* Release the array of temp registers */
-- 
2.19.2

  parent reply	other threads:[~2018-11-29 13:10 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-29 13:09 [tarantool-patches] [PATCH v1 0/6] sql: Checks on server side Kirill Shcherbatov
2018-11-29 13:09 ` [tarantool-patches] [PATCH v1 1/6] box: rename space->opts checks to checks_ast Kirill Shcherbatov
2018-11-29 13:09 ` [tarantool-patches] [PATCH v1 2/6] sql: disallow use of TYPEOF in Check Kirill Shcherbatov
2018-11-29 13:09 ` [tarantool-patches] [PATCH v1 3/6] box: exported sql_bind structure and API Kirill Shcherbatov
2018-11-29 13:09 ` Kirill Shcherbatov [this message]
2018-11-29 13:09 ` [tarantool-patches] [PATCH v1 5/6] sql: fix incomplete UPDATE on IdxInsert failured Kirill Shcherbatov
2018-11-29 13:09 ` [tarantool-patches] [PATCH v1 6/6] sql: make sql checks on server side Kirill Shcherbatov
2018-11-29 14:09   ` [tarantool-patches] " Kirill Shcherbatov
2018-11-29 18:41   ` Kirill Shcherbatov

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=bf1396dd8a01ba5578811ee11ee04f20dd82f97d.1543496928.git.kshcherbatov@tarantool.org \
    --to=kshcherbatov@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [tarantool-patches] [PATCH v1 4/6] sql: release OP_Idx{Insert,Replace} p2 argument' \
    /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