Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 380d685

Browse files
author
drh
committed
Improved comments on the OP_Column changes. Optimize out loading of overflow
pages for content with zero length. Add test cases for the latter. FossilOrigin-Name: 0e05679db7aa302a49e087a81f85203844b98cbe
1 parent c8606e4 commit 380d685

File tree

4 files changed

+51
-29
lines changed

4 files changed

+51
-29
lines changed

manifest

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
C Further\sperformance\stweaks\sto\sOP_Column.
2-
D 2013-11-20T19:28:03.982
1+
C Improved\scomments\son\sthe\sOP_Column\schanges.\s\sOptimize\sout\sloading\sof\soverflow\npages\sfor\scontent\swith\szero\slength.\s\sAdd\stest\scases\sfor\sthe\slatter.
2+
D 2013-11-20T20:58:00.360
33
F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
44
F Makefile.in 8a07bebafbfda0eb67728f4bd15a36201662d1a1
55
F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -280,7 +280,7 @@ F src/update.c c05a0ee658f1a149e0960dfd110f3b8bd846bcb0
280280
F src/utf.c 6fc6c88d50448c469c5c196acf21617a24f90269
281281
F src/util.c 2fa6c821d28bbdbeec1b2a7b091a281c9ef8f918
282282
F src/vacuum.c 3728d74919d4fb1356f9e9a13e27773db60b7179
283-
F src/vdbe.c 1a6e2c9413fca3b2d00c49e85a861e0adc8b6c6a
283+
F src/vdbe.c 987f375b8ba5b5c3d0ded64191f72706221f76f9
284284
F src/vdbe.h c06f0813f853566457ce9cfb1a4a4bc39a5da644
285285
F src/vdbeInt.h fbae1c449049a1a26ebbdf44e1beb08344072b72
286286
F src/vdbeapi.c 93a22a9ba2abe292d5c2cf304d7eb2e894dde0ed
@@ -573,7 +573,7 @@ F test/fts4merge4.test c19c85ca1faa7b6d536832b49c12e1867235f584
573573
F test/fts4noti.test aed33ba44808852dcb24bf70fa132e7bf530f057
574574
F test/fts4unicode.test e28ba1a14181e709dcdf47455f207adf14c7cfe0
575575
F test/full.test 6b3c8fb43c6beab6b95438c1675374b95fab245d
576-
F test/func.test c7e80a44eebac8604397eb2ad83d0d5d9d541237
576+
F test/func.test 00667bbeac044d007f6f021af1b9f6150f0c7ff8
577577
F test/func2.test 772d66227e4e6684b86053302e2d74a2500e1e0f
578578
F test/func3.test dbccee9133cfef1473c59ec07b5f0262b9d72f9a
579579
F test/func4.test 6beacdfcb0e18c358e6c2dcacf1b65d1fa80955f
@@ -1140,7 +1140,7 @@ F tool/vdbe-compress.tcl f12c884766bd14277f4fcedcae07078011717381
11401140
F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
11411141
F tool/warnings.sh d1a6de74685f360ab718efda6265994b99bbea01
11421142
F tool/win/sqlite.vsix 030f3eeaf2cb811a3692ab9c14d021a75ce41fff
1143-
P 7c914e3997d2b28164a2fa7eb4398262b6ddb4b2
1144-
R 72749b37eba95a49879e9308fdcd90bb
1143+
P 0e3f5df695216a27602a53eed5d25231b055adc8
1144+
R 7b4a6a3b4e08d369fabb1ea696a3ba02
11451145
U drh
1146-
Z 441207295dddfadd80f4cc85b77f0a53
1146+
Z a02194f256e2495862011254263d6e91

manifest.uuid

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0e3f5df695216a27602a53eed5d25231b055adc8
1+
0e05679db7aa302a49e087a81f85203844b98cbe

src/vdbe.c

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2284,11 +2284,11 @@ case OP_Column: {
22842284
aType = pC->aType;
22852285
aOffset = pC->aOffset;
22862286
#ifndef SQLITE_OMIT_VIRTUALTABLE
2287-
assert( pC->pVtabCursor==0 );
2287+
assert( pC->pVtabCursor==0 ); /* OP_Column never called on virtual table */
22882288
#endif
22892289
pCrsr = pC->pCursor;
2290-
assert( pCrsr!=0 || pC->pseudoTableReg>0 );
2291-
assert( pC->pseudoTableReg==0 || pC->nullRow );
2290+
assert( pCrsr!=0 || pC->pseudoTableReg>0 ); /* pCrsr NULL on PseudoTables */
2291+
assert( pCrsr!=0 || pC->nullRow ); /* pC->nullRow on PseudoTables */
22922292

22932293
/* If the cursor cache is stale, bring it up-to-date */
22942294
rc = sqlite3VdbeCursorMoveto(pC);
@@ -2339,12 +2339,15 @@ case OP_Column: {
23392339
goto too_big;
23402340
}
23412341
}
2342-
23432342
pC->cacheStatus = p->cacheCtr;
23442343
pC->iHdrOffset = getVarint32(pC->aRow, offset);
23452344
pC->nHdrParsed = 0;
23462345
aOffset[0] = offset;
23472346
if( avail<offset ){
2347+
/* pC->aRow does not have to hold the entire row, but it does at least
2348+
** need to cover the header of the record. If pC->aRow does not contain
2349+
** the complete header, then set it to zero, forcing the header to be
2350+
** dynamically allocated. */
23482351
pC->aRow = 0;
23492352
pC->szRow = 0;
23502353
}
@@ -2368,8 +2371,8 @@ case OP_Column: {
23682371
** parsed and valid information is in aOffset[] and aType[].
23692372
*/
23702373
if( pC->nHdrParsed<=p2 ){
2371-
/* If there is more header available for parsing, try to extract
2372-
** additional fields up through the p2-th field
2374+
/* If there is more header available for parsing in the record, try
2375+
** to extract additional fields up through the p2+1-th field
23732376
*/
23742377
if( pC->iHdrOffset<aOffset[0] ){
23752378
/* Make sure zData points to enough of the record to cover the header. */
@@ -2430,9 +2433,10 @@ case OP_Column: {
24302433
}
24312434
}
24322435

2433-
/* If after nHdrParsed is still not up to p2, that means that the record
2434-
** has fewer than p2 columns. So the result will be either the default
2435-
** value or a NULL. */
2436+
/* If after trying to extra new entries from the header, nHdrParsed is
2437+
** still not up to p2, that means that the record has fewer than p2
2438+
** columns. So the result will be either the default value or a NULL.
2439+
*/
24362440
if( pC->nHdrParsed<=p2 ){
24372441
if( pOp->p4type==P4_MEM ){
24382442
sqlite3VdbeMemShallowCopy(pDest, pOp->p4.pMem, MEM_Static);
@@ -2443,33 +2447,33 @@ case OP_Column: {
24432447
}
24442448
}
24452449

2446-
/* Get the column information. If aOffset[p2] is non-zero, then
2447-
** deserialize the value from the record. If aOffset[p2] is zero,
2448-
** then there are not enough fields in the record to satisfy the
2449-
** request. In this case, set the value NULL or to P4 if P4 is
2450-
** a pointer to a Mem object.
2450+
/* Extract the content for the p2+1-th column. Control can only
2451+
** reach this point if aOffset[p2], aOffset[p2+1], and aType[p2] are
2452+
** all valid.
24512453
*/
24522454
assert( p2<pC->nHdrParsed );
24532455
assert( rc==SQLITE_OK );
24542456
if( pC->szRow>=aOffset[p2+1] ){
2455-
/* This is the common case where the whole row fits on a single page */
2457+
/* This is the common case where the desired content fits on the original
2458+
** page - where the content is not on an overflow page */
24562459
VdbeMemRelease(pDest);
24572460
sqlite3VdbeSerialGet(pC->aRow+aOffset[p2], aType[p2], pDest);
24582461
}else{
2459-
/* This branch happens only when the row overflows onto multiple pages */
2462+
/* This branch happens only when content is on overflow pages */
24602463
t = aType[p2];
2461-
if( (pOp->p5 & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG))!=0
2462-
&& ((t>=12 && (t&1)==0) || (pOp->p5 & OPFLAG_TYPEOFARG)!=0)
2464+
if( ((pOp->p5 & (OPFLAG_LENGTHARG|OPFLAG_TYPEOFARG))!=0
2465+
&& ((t>=12 && (t&1)==0) || (pOp->p5 & OPFLAG_TYPEOFARG)!=0))
2466+
|| (len = sqlite3VdbeSerialTypeLen(t))==0
24632467
){
24642468
/* Content is irrelevant for the typeof() function and for
24652469
** the length(X) function if X is a blob. So we might as well use
24662470
** bogus content rather than reading content from disk. NULL works
24672471
** for text and blob and whatever is in the payloadSize64 variable
2468-
** will work for everything else. */
2469-
zData = t<12 ? (u8*)&payloadSize64 : 0;
2472+
** will work for everything else. Content is also irrelevant if
2473+
** the content length is 0. */
2474+
zData = t<=13 ? (u8*)&payloadSize64 : 0;
24702475
sMem.zMalloc = 0;
24712476
}else{
2472-
len = sqlite3VdbeSerialTypeLen(t);
24732477
memset(&sMem, 0, sizeof(sMem));
24742478
sqlite3VdbeMemMove(&sMem, pDest);
24752479
rc = sqlite3VdbeMemFromBtree(pCrsr, aOffset[p2], len, pC->isIndex,

test/func.test

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,6 +1319,24 @@ do_test func-29.6 {
13191319
set x
13201320
} {1}
13211321

1322+
# The OP_Column opcode has an optimization that avoids loading content
1323+
# for fields with content-length=0 when the content offset is on an overflow
1324+
# page. Make sure the optimization works.
1325+
#
1326+
do_execsql_test func-29.10 {
1327+
CREATE TABLE t29b(a,b,c,d,e,f,g,h,i);
1328+
INSERT INTO t29b
1329+
VALUES(1, hex(randomblob(2000)), null, 0, 1, '', zeroblob(0),'x',x'01');
1330+
SELECT typeof(c), typeof(d), typeof(e), typeof(f),
1331+
typeof(g), typeof(h), typeof(i) FROM t29b;
1332+
} {null integer integer text blob text blob}
1333+
do_execsql_test func-29.11 {
1334+
SELECT length(f), length(g), length(h), length(i) FROM t29b;
1335+
} {0 0 1 1}
1336+
do_execsql_test func-29.12 {
1337+
SELECT quote(f), quote(g), quote(h), quote(i) FROM t29b;
1338+
} {'' X'' 'x' X'01'}
1339+
13221340
# EVIDENCE-OF: R-29701-50711 The unicode(X) function returns the numeric
13231341
# unicode code point corresponding to the first character of the string
13241342
# X.

0 commit comments

Comments
 (0)