From: drh Date: Tue, 8 Mar 2016 23:18:51 +0000 (+0000) Subject: Improved comments on virtual table query planning. Added many new X-Git-Tag: version-3.12.0~85 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3349d9bea956eaf1a2d9554ce3e4c9e1d5b34075;p=thirdparty%2Fsqlite.git Improved comments on virtual table query planning. Added many new WHERETRACE() macros. FossilOrigin-Name: 4c89c2534abcf67bc486d5a900a84a6c4f59537e --- diff --git a/manifest b/manifest index bb6f77ee42..25c4175d4a 100644 --- a/manifest +++ b/manifest @@ -1,5 +1,5 @@ -C In\smemjournal.c,\sreuse\sthe\ssame\ssqlite3_file\sobject\sfor\sboth\sthe\sin-memory\nphase\sand\sthe\son-disk\sphase. -D 2016-03-08T17:59:19.784 +C Improved\scomments\son\svirtual\stable\squery\splanning.\s\sAdded\smany\snew\nWHERETRACE()\smacros. +D 2016-03-08T23:18:51.182 F Makefile.in f53429fb2f313c099283659d0df6f20f932c861f F Makefile.linux-gcc 7bc79876b875010e8c8f9502eb935ca92aa3c434 F Makefile.msc df0bf9ff7f8b3f4dd9fb4cc43f92fe58f6ec5c66 @@ -429,7 +429,7 @@ F src/vxworks.h d2988f4e5a61a4dfe82c6524dd3d6e4f2ce3cdb9 F src/wal.c 10deb6b43887662691e5f53d10b3c171c401169b F src/wal.h 2f7c831cf3b071fa548bf2d5cac640846a7ff19c F src/walker.c 0f142b5bd3ed2041fc52d773880748b212e63354 -F src/where.c dff52f7f0842430f80a7017c7859124685b08453 +F src/where.c a3f6db088f335a9217fe53d976f9441610061a2f F src/whereInt.h 93297d56edd137b7ea004490690fb6e2ce028a34 F src/wherecode.c 863aedf086131743763c1960637fde904eadc442 F src/whereexpr.c fb87944b1254234e5bba671aaf6dee476241506a @@ -1455,8 +1455,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0 -P f6d3156ba9af1da517dd77c1df03fa7869888463 d99ac4154812065eef26c298de52954d7ee0bd75 -R bec56382cb26d93b90f8b590f852c457 -T +closed d99ac4154812065eef26c298de52954d7ee0bd75 +P e7fbbdc25c0991d4e58d78a5fcb7386e1aa7f3af +R 624279792742522c1a4793f09c7ca2f6 U drh -Z 55dc3dcac976fd228dc3d62385f9ab1a +Z ab3adc4bc8a1b11824c36206a5455ed4 diff --git a/manifest.uuid b/manifest.uuid index 45d67c3642..572a4db2fb 100644 --- a/manifest.uuid +++ b/manifest.uuid @@ -1 +1 @@ -e7fbbdc25c0991d4e58d78a5fcb7386e1aa7f3af \ No newline at end of file +4c89c2534abcf67bc486d5a900a84a6c4f59537e \ No newline at end of file diff --git a/src/where.c b/src/where.c index 2d7272a742..364bfca3c5 100644 --- a/src/where.c +++ b/src/where.c @@ -2892,6 +2892,9 @@ static int whereLoopAddVirtualOne( sqlite3_free(pNew->u.vtab.idxStr); pNew->u.vtab.needFree = 0; } + WHERETRACE(0xffff, (" bIn=%d prereqIn=%04llx prereqOut=%04llx\n", + *pbIn, (sqlite3_uint64)mPrereq, + (sqlite3_uint64)(pNew->prereq & ~mPrereq))); return SQLITE_OK; } @@ -2958,15 +2961,15 @@ static int whereLoopAddVirtual( } /* First call xBestIndex() with all constraints usable. */ + WHERETRACE(0x40, (" VirtualOne: all usable\n")); rc = whereLoopAddVirtualOne(pBuilder, mPrereq, ALLBITS, 0, p, &bIn); - mBest = pNew->prereq & ~mPrereq; /* If the call to xBestIndex() with all terms enabled produced a plan - ** that does not require any source tables, there is no point in making - ** any further calls - if the xBestIndex() method is sane they will all - ** return the same plan anyway. - */ - if( mBest ){ + ** that does not require any source tables (IOW: a plan with mBest==0), + ** then there is no point in making any further calls to xBestIndex() + ** since they will all return the same result (if the xBestIndex() + ** implementation is sane). */ + if( rc==SQLITE_OK && (mBest = (pNew->prereq & ~mPrereq))!=0 ){ int seenZero = 0; /* True if a plan with no prereqs seen */ int seenZeroNoIN = 0; /* Plan with no prereqs and no IN(...) seen */ Bitmask mPrev = 0; @@ -2974,7 +2977,8 @@ static int whereLoopAddVirtual( /* If the plan produced by the earlier call uses an IN(...) term, call ** xBestIndex again, this time with IN(...) terms disabled. */ - if( rc==SQLITE_OK && bIn ){ + if( bIn ){ + WHERETRACE(0x40, (" VirtualOne: all usable w/o IN\n")); rc = whereLoopAddVirtualOne(pBuilder, mPrereq, ALLBITS, WO_IN, p, &bIn); assert( bIn==0 ); mBestNoIn = pNew->prereq & ~mPrereq; @@ -2999,6 +3003,8 @@ static int whereLoopAddVirtual( mPrev = mNext; if( mNext==ALLBITS ) break; if( mNext==mBest || mNext==mBestNoIn ) continue; + WHERETRACE(0x40, (" VirtualOne: mPrev=%04llx mNext=%04llx\n", + (sqlite3_uint64)mPrev, (sqlite3_uint64)mNext)); rc = whereLoopAddVirtualOne(pBuilder, mPrereq, mNext|mPrereq, 0, p, &bIn); if( pNew->prereq==mPrereq ){ seenZero = 1; @@ -3010,6 +3016,7 @@ static int whereLoopAddVirtual( ** that requires no source tables at all (i.e. one guaranteed to be ** usable), make a call here with all source tables disabled */ if( rc==SQLITE_OK && seenZero==0 ){ + WHERETRACE(0x40, (" VirtualOne: all disabled\n")); rc = whereLoopAddVirtualOne(pBuilder, mPrereq, mPrereq, 0, p, &bIn); if( bIn==0 ) seenZeroNoIN = 1; } @@ -3018,6 +3025,7 @@ static int whereLoopAddVirtual( ** that requires no source tables at all and does not use an IN(...) ** operator, make a final call to obtain one here. */ if( rc==SQLITE_OK && seenZeroNoIN==0 ){ + WHERETRACE(0x40, (" VirtualOne: all disabled and w/o IN\n")); rc = whereLoopAddVirtualOne(pBuilder, mPrereq, mPrereq, WO_IN, p, &bIn); } }