aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrh <drh@noemail.net>2019-06-28 07:08:13 +0000
committerdrh <drh@noemail.net>2019-06-28 07:08:13 +0000
commit00a6153fafe01c9dde8f84a70f1cb810256300dd (patch)
tree25f5de0db59156bb9e488ab4a5977d047f6506ba /src
parent855b5d144aaa7ff9e52741a039e53ffcaaac7d65 (diff)
downloadsqlite-00a6153fafe01c9dde8f84a70f1cb810256300dd.tar.gz
sqlite-00a6153fafe01c9dde8f84a70f1cb810256300dd.zip
Use the OP_Sequence opcode for generating unique rowid values for an
autoindex on a co-routine implementation of a subquery. FossilOrigin-Name: eab4297577e4d325fed4757867fc77860de7448998d86f098c8a50272e17d35e
Diffstat (limited to 'src')
-rw-r--r--src/where.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/src/where.c b/src/where.c
index b421e4ae9..f2ab125d2 100644
--- a/src/where.c
+++ b/src/where.c
@@ -562,17 +562,17 @@ static LogEst estLog(LogEst N){
** opcodes into OP_Copy when the table is being accessed via co-routine
** instead of via table lookup.
**
-** If the bIncrRowid parameter is 0, then any OP_Rowid instructions on
-** cursor iTabCur are transformed into OP_Null. Or, if bIncrRowid is non-zero,
-** then each OP_Rowid is transformed into an instruction to increment the
-** value stored in its output register.
+** If the iAutoidxCur is not zero, then any OP_Rowid instructions on
+** cursor iTabCur are transformed into OP_Sequence opcode for the
+** iAutoidxCur cursor, in order to generate unique rowids for the
+** automatic index being generated.
*/
static void translateColumnToCopy(
Parse *pParse, /* Parsing context */
int iStart, /* Translate from this opcode to the end */
int iTabCur, /* OP_Column/OP_Rowid references to this table */
int iRegister, /* The first column is in this register */
- int bIncrRowid /* If non-zero, transform OP_rowid to OP_AddImm(1) */
+ int iAutoidxCur /* If non-zero, cursor of autoindex being generated */
){
Vdbe *v = pParse->pVdbe;
VdbeOp *pOp = sqlite3VdbeGetOp(v, iStart);
@@ -586,11 +586,9 @@ static void translateColumnToCopy(
pOp->p2 = pOp->p3;
pOp->p3 = 0;
}else if( pOp->opcode==OP_Rowid ){
- if( bIncrRowid ){
- /* Increment the value stored in the P2 operand of the OP_Rowid. */
- pOp->opcode = OP_AddImm;
- pOp->p1 = pOp->p2;
- pOp->p2 = 1;
+ if( iAutoidxCur ){
+ pOp->opcode = OP_Sequence;
+ pOp->p1 = iAutoidxCur;
}else{
pOp->opcode = OP_Null;
pOp->p1 = 0;
@@ -864,8 +862,9 @@ static void constructAutomaticIndex(
if( pTabItem->fg.viaCoroutine ){
sqlite3VdbeChangeP2(v, addrCounter, regBase+n);
testcase( pParse->db->mallocFailed );
+ assert( pLevel->iIdxCur>0 );
translateColumnToCopy(pParse, addrTop, pLevel->iTabCur,
- pTabItem->regResult, 1);
+ pTabItem->regResult, pLevel->iIdxCur);
sqlite3VdbeGoto(v, addrTop);
pTabItem->fg.viaCoroutine = 0;
}else{