SQLite4
Check-in [d5abe1bca0]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix the RowDecoder caching logic by adding new cache clears to opcodes that move the cursor.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: d5abe1bca006ae2468e9fbb165b9305db4be84bd
User & Date: drh 2013-07-25 01:12:32
Context
2013-07-25
02:52
Update comments on OP_MakeRecord. No changes to code. check-in: 70d85ff051 user: drh tags: trunk
01:12
Fix the RowDecoder caching logic by adding new cache clears to opcodes that move the cursor. check-in: d5abe1bca0 user: drh tags: trunk
00:55
Enhance the RowDecoder object so that it persists on a VdbeCursor and can be reused for multiple OP_Column operations. This opens the possibility of adding caching of header information and/or values in a later check-in. check-in: 6ed358511b user: drh tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/vdbe.c.

3037
3038
3039
3040
3041
3042
3043

3044
3045
3046
3047
3048
3049
3050
....
3180
3181
3182
3183
3184
3185
3186

3187
3188
3189
3190
3191
3192
3193
....
3438
3439
3440
3441
3442
3443
3444

3445
3446
3447
3448
3449
3450
3451
....
3718
3719
3720
3721
3722
3723
3724

3725
3726
3727
3728
3729
3730
3731
....
3895
3896
3897
3898
3899
3900
3901

3902
3903
3904
3905
3906
3907
3908
....
3921
3922
3923
3924
3925
3926
3927

3928
3929
3930
3931
3932
3933
3934
  VdbeCursor *pC;
  KVCursor *pKVCur;
  KVByteArray *aKey;
  KVSize nKey;

  assert( pOp->p1>=0 && pOp->p1<p->nCursor );
  pC = p->apCsr[pOp->p1];

  assert( pC!=0 );
  pKVCur = pC->pKVCur;
  rc = sqlite4VdbeEncodeKey(db, aMem+pOp->p2, 1, 1, pC->iRoot, 0,
                            &aKey, &nKey, 0);
  if( rc==SQLITE4_OK ){
    rc = sqlite4KVCursorSeek(pKVCur, aKey, nKey, 0);
    if( rc==SQLITE4_NOTFOUND ) rc = SQLITE4_CORRUPT_BKPT;
................................................................................
  KVByteArray const *aKey;        /* Key read from cursor */
  KVSize nKey;                    /* Size of aKey in bytes */

  assert( pOp->p4type==P4_INT32 );

  pProbe = &aMem[pOp->p3];
  pC = p->apCsr[pOp->p1];

  pOut = (pOp->p4.i==0 ? 0 : &aMem[pOp->p4.i]);
  assert( pOut==0 || (pOut->flags & MEM_Blob) );

  nShort = sqlite4VdbeShortKey((u8 *)pProbe->z, pProbe->n, 
      pC->pKeyInfo->nField - pC->pKeyInfo->nPK, 0
  );
  assert( nShort<=pProbe->n );
................................................................................
  }else{
    assert( pData->flags & (MEM_Blob|MEM_Str) );
  }
  n = sqlite4PutVarint64(aKey, pC->iRoot);
  n += sqlite4VdbeEncodeIntKey(&aKey[n], iKey);
  rc = sqlite4KVStoreReplace(pC->pKVCur->pStore, aKey, n,
                             (const KVByteArray*)pData->z, pData->n);


  break;
}

/* Opcode: Delete P1 P2 * * *
**
** Delete the record at which the P1 cursor is currently pointing.
................................................................................
case OP_NullRow: {
  VdbeCursor *pC;

  assert( pOp->p1>=0 && pOp->p1<p->nCursor );
  pC = p->apCsr[pOp->p1];
  assert( pC!=0 );
  pC->nullRow = 1;

  break;
}

/* Opcode: Last P1 P2 * * *
**
** The next use of the Rowid or Column or Next instruction for P1 
** will refer to the last entry in the database table or index.
................................................................................
  if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;

  rc = sqlite4KVStoreReplace(
     pC->pKVCur->pStore,
     (u8 *)pKey->z, pKey->n,
     (u8 *)(pData ? pData->z : 0), (pData ? pData->n : 0)
  );


  break;
}

/* Opcode: IdxDelete P1 * P3 * *
**
** P1 is a cursor open on a database index. P3 contains a key suitable for
................................................................................

  rc = sqlite4KVCursorSeek(pC->pKVCur, (u8 *)pKey->z, pKey->n, 0);
  if( rc==SQLITE4_OK ){
    rc = sqlite4KVCursorDelete(pC->pKVCur);
  }else if( rc==SQLITE4_NOTFOUND ){
    rc = SQLITE4_OK;
  }


  break;
}

/* Opcode: IdxRowkey P1 P2 P3 * *
**
** Cursor P1 points to an index entry. Extract the encoded primary key 







>







 







>







 







>







 







>







 







>







 







>







3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
....
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
....
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
....
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
....
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
....
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
  VdbeCursor *pC;
  KVCursor *pKVCur;
  KVByteArray *aKey;
  KVSize nKey;

  assert( pOp->p1>=0 && pOp->p1<p->nCursor );
  pC = p->apCsr[pOp->p1];
  pC->rowChnged = 1;
  assert( pC!=0 );
  pKVCur = pC->pKVCur;
  rc = sqlite4VdbeEncodeKey(db, aMem+pOp->p2, 1, 1, pC->iRoot, 0,
                            &aKey, &nKey, 0);
  if( rc==SQLITE4_OK ){
    rc = sqlite4KVCursorSeek(pKVCur, aKey, nKey, 0);
    if( rc==SQLITE4_NOTFOUND ) rc = SQLITE4_CORRUPT_BKPT;
................................................................................
  KVByteArray const *aKey;        /* Key read from cursor */
  KVSize nKey;                    /* Size of aKey in bytes */

  assert( pOp->p4type==P4_INT32 );

  pProbe = &aMem[pOp->p3];
  pC = p->apCsr[pOp->p1];
  pC->rowChnged = 1;
  pOut = (pOp->p4.i==0 ? 0 : &aMem[pOp->p4.i]);
  assert( pOut==0 || (pOut->flags & MEM_Blob) );

  nShort = sqlite4VdbeShortKey((u8 *)pProbe->z, pProbe->n, 
      pC->pKeyInfo->nField - pC->pKeyInfo->nPK, 0
  );
  assert( nShort<=pProbe->n );
................................................................................
  }else{
    assert( pData->flags & (MEM_Blob|MEM_Str) );
  }
  n = sqlite4PutVarint64(aKey, pC->iRoot);
  n += sqlite4VdbeEncodeIntKey(&aKey[n], iKey);
  rc = sqlite4KVStoreReplace(pC->pKVCur->pStore, aKey, n,
                             (const KVByteArray*)pData->z, pData->n);
  pC->rowChnged = 1;

  break;
}

/* Opcode: Delete P1 P2 * * *
**
** Delete the record at which the P1 cursor is currently pointing.
................................................................................
case OP_NullRow: {
  VdbeCursor *pC;

  assert( pOp->p1>=0 && pOp->p1<p->nCursor );
  pC = p->apCsr[pOp->p1];
  assert( pC!=0 );
  pC->nullRow = 1;
  pC->rowChnged = 1;
  break;
}

/* Opcode: Last P1 P2 * * *
**
** The next use of the Rowid or Column or Next instruction for P1 
** will refer to the last entry in the database table or index.
................................................................................
  if( pOp->p5 & OPFLAG_NCHANGE ) p->nChange++;

  rc = sqlite4KVStoreReplace(
     pC->pKVCur->pStore,
     (u8 *)pKey->z, pKey->n,
     (u8 *)(pData ? pData->z : 0), (pData ? pData->n : 0)
  );
  pC->rowChnged = 1;

  break;
}

/* Opcode: IdxDelete P1 * P3 * *
**
** P1 is a cursor open on a database index. P3 contains a key suitable for
................................................................................

  rc = sqlite4KVCursorSeek(pC->pKVCur, (u8 *)pKey->z, pKey->n, 0);
  if( rc==SQLITE4_OK ){
    rc = sqlite4KVCursorDelete(pC->pKVCur);
  }else if( rc==SQLITE4_NOTFOUND ){
    rc = SQLITE4_OK;
  }
  pC->rowChnged = 1;

  break;
}

/* Opcode: IdxRowkey P1 P2 P3 * *
**
** Cursor P1 points to an index entry. Extract the encoded primary key 

Changes to src/vdbecodec.c.

82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
static int decoderFetchData(RowDecoder *p){
  VdbeCursor *pCur = p->pCur;
  int rc;
  if( pCur==0 ){
    rc = sqlite4KVCursorData(p->pKVCur, 0, -1, &p->a, &p->n);
    return rc;
  }
  if( 1 /*pCur->rowChnged*/ ){  /* FIXME:  Row cache not always cleared */
    p->a = 0;
    p->aKey = 0;
    pCur->rowChnged = pCur->pPseudoTab!=0;
  }
  if( p->a ) return SQLITE4_OK;
  rc = sqlite4VdbeCursorMoveto(pCur);
  if( rc ) return rc;







|







82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
static int decoderFetchData(RowDecoder *p){
  VdbeCursor *pCur = p->pCur;
  int rc;
  if( pCur==0 ){
    rc = sqlite4KVCursorData(p->pKVCur, 0, -1, &p->a, &p->n);
    return rc;
  }
  if( pCur->rowChnged ){
    p->a = 0;
    p->aKey = 0;
    pCur->rowChnged = pCur->pPseudoTab!=0;
  }
  if( p->a ) return SQLITE4_OK;
  rc = sqlite4VdbeCursorMoveto(pCur);
  if( rc ) return rc;