1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-08-08 14:02:16 +03:00

Performance improvement in the OP_Column opcode.

FossilOrigin-Name: dc98a92f32511ee322b0207bd286e967248a8e59b418f11168eb31e34b0fa0fa
This commit is contained in:
drh
2017-08-16 11:04:22 +00:00
parent 6cd8c8c57a
commit 95b225a46d
3 changed files with 30 additions and 14 deletions

View File

@@ -2464,13 +2464,23 @@ case OP_Column: {
rc = SQLITE_CORRUPT_BKPT;
goto abort_due_to_error;
}
}else if( offset>0 ){ /*OPTIMIZATION-IF-TRUE*/
/* The following goto is an optimization. It can be omitted and
** everything will still work. But OP_Column is measurably faster
** by skipping the subsequent conditional, which is always true.
}else{
/* This is an optimization. By skipping over the first few tests
** (ex: pC->nHdrParsed<=p2) in the next section, we achieve a
** measurable performance gain.
**
** This branch is taken even if offset==0. Such a record is never
** generated by SQLite, and could be considered corruption, but we
** accept it for historical reasons. When offset==0, the code this
** branch jumps to reads past the end of the record, but never more
** than a few bytes. Even if the record occurs at the end of the page
** content area, the "page header" comes after the page content and so
** this overread is harmless. Similar overreads can occur for a corrupt
** database file.
*/
zData = pC->aRow;
assert( pC->nHdrParsed<=p2 ); /* Conditional skipped */
testcase( offset==0 );
goto op_column_read_header;
}
}
@@ -2499,6 +2509,7 @@ case OP_Column: {
offset64 = aOffset[i];
zHdr = zData + pC->iHdrOffset;
zEndHdr = zData + aOffset[0];
testcase( zHdr>=zEndHdr );
do{
if( (t = zHdr[0])<0x80 ){
zHdr++;
@@ -2519,9 +2530,14 @@ case OP_Column: {
if( (zHdr>=zEndHdr && (zHdr>zEndHdr || offset64!=pC->payloadSize))
|| (offset64 > pC->payloadSize)
){
if( pC->aRow==0 ) sqlite3VdbeMemRelease(&sMem);
rc = SQLITE_CORRUPT_BKPT;
goto abort_due_to_error;
if( aOffset[0]==0 ){
i = 0;
zHdr = zEndHdr;
}else{
if( pC->aRow==0 ) sqlite3VdbeMemRelease(&sMem);
rc = SQLITE_CORRUPT_BKPT;
goto abort_due_to_error;
}
}
pC->nHdrParsed = i;