Index: src/vdbe.c ================================================================== --- src/vdbe.c +++ src/vdbe.c @@ -2163,22 +2163,20 @@ /* Opcode: MakeIdxKey P1 P2 P3 P4 P5 ** ** P1 is an open cursor. P2 is the first register in a contiguous array ** of N registers containing values to encode into a database key. Normally, -** N is equal to the number of columns indexed by P1, plus the number of -** trailing primary key columns (if any). -** -** Or, if P4 is a non-zero integer, then it contains the value for N. +** N is taken from the KeyInfo object of P1. However, of P4 is a positive +** integer, P4 is used for N instead. ** ** This instruction encodes the N values into a database key and writes ** the result to register P3. No affinity transformations are applied to ** the input values before they are encoded. ** ** If the OPFLAG_SEQCOUNT bit of P5 is set, then a sequence number ** (unique within the cursor) is appended to the record. The sole purpose -** of this is to ensure that the key blob is unique within the cursors table. +** of this is to ensure that the key blob is unique within the cursor table. ** ** If the OPFLAG_PARTIALKEY bit of P5 is set, that means the value supplied ** for N is not the true number of values in the key, only the number that ** need to be encoded for this operation. This effects the encoding of ** final BLOBs. @@ -2198,13 +2196,15 @@ pKeyInfo = pC->pKeyInfo; pData0 = &aMem[pOp->p2]; pOut = &aMem[pOp->p3]; aRec = 0; - /* If pOp->p5 is non-zero, encode the sequence number blob to append to - ** the end of the key. Variable nSeq is set to the number of bytes in - ** the encoded key. + /* If P4 contains OPFLAG_SEQCOUNT, encode the sequence number blob to be + ** appended to the end of the key. Variable nSeq is set to the number + ** of bytes in the encoded key. A non-standard encoding is used (not + ** the usual varint encoding) so that the OP_GrpCompare opcode can easily + ** back up over the sequence count to find the true end of the key. */ nSeq = 0; if( pOp->p5 & OPFLAG_SEQCOUNT ){ iSeq = pC->seqCount++; do { @@ -2215,16 +2215,18 @@ aSeq[sizeof(aSeq)-nSeq] |= 0x80; } memAboutToChange(p, pOut); - nField = pOp->p4.i; - if( nField==0 ) nField = pKeyInfo->nField; +// nField = pOp->p4.i; +// if( nField==0 ) nField = pKeyInfo->nField; if( pOp->p4type==P4_INT32 && pOp->p4.i ){ nField = pOp->p4.i; assert( nField<=pKeyInfo->nField ); + }else{ + nField = pKeyInfo->nField; } rc = sqlite4VdbeEncodeKey( db, pData0, nField, pKeyInfo->nField, pC->iRoot, pKeyInfo, &aRec, &nRec, nSeq );