From: drh Date: Wed, 27 Mar 2013 17:20:10 +0000 (+0000) Subject: In order to optimize out the ORDER BY clause, X-Git-Tag: version-3.7.16.1~4 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=d9883570f5970a693613b40310cbb6f42dd4bd7b;p=thirdparty%2Fsqlite.git In order to optimize out the ORDER BY clause, outer loops must generate values for ORDER BY terms that are unique or else the inner loops must generate no more than a single row. Fix for ticket [a179fe7465]. FossilOrigin-Name: 2936f7466e162dfb003bda26d35358d1b3063112 --- d9883570f5970a693613b40310cbb6f42dd4bd7b diff --cc manifest index 007356f176,5f6aa42e1a..d1bf95f820 --- a/manifest +++ b/manifest @@@ -1,5 -1,5 +1,5 @@@ - C Candidate\sfix\sfor\sticket\s[6bfb98dfc0c]:\sMake\ssure\sinvalid\scursors\sdrop\sall\nreferences\sto\sdatabase\spages\sprior\sto\sdoing\sany\sinsert\sor\supdate. - D 2013-03-27T03:15:23.329 -C Restore\sadditional\sORDER\sBY\soptimizations\sthat\swhere\sbroken\sby\sthe\nrecent\sORDER\sBY\sfix. -D 2013-03-27T16:42:21.685 ++C In\sorder\sto\soptimize\sout\sthe\sORDER\sBY\sclause,\s\nouter\sloops\smust\sgenerate\svalues\sfor\sORDER\sBY\sterms\sthat\sare\sunique\sor\selse\nthe\sinner\sloops\smust\sgenerate\sno\smore\sthan\sa\ssingle\srow.\nFix\sfor\sticket\s[a179fe7465]. ++D 2013-03-27T17:20:10.024 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f F Makefile.in df3e48659d80e1b7765785d8d66c86b320f72cc7 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23 @@@ -252,7 -252,7 +252,7 @@@ F src/vtab.c b05e5f1f4902461ba9f5fc49bb F src/wal.c f5c7b5027d0ed0e9bc9afeb4a3a8dfea762ec7d2 F src/wal.h 29c197540b19044e6cd73487017e5e47a1d3dac6 F src/walker.c 3d75ba73de15e0f8cd0737643badbeb0e002f07b - F src/where.c 9a16c0b84bbeb054d11fda96e9e037ae310bd54e -F src/where.c 8179f4c891d2742ff7c00237b2f7b534c826503c ++F src/where.c 4ad2329c439a30ddb915a780f6f80bdffafe3a64 F test/8_3_names.test 631ea964a3edb091cf73c3b540f6bcfdb36ce823 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2 F test/aggnested.test 45c0201e28045ad38a530b5a144b73cd4aa2cfd6 @@@ -1040,7 -1041,7 +1041,7 @@@ F tool/vdbe-compress.tcl f12c884766bd14 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4 F tool/warnings.sh fbc018d67fd7395f440c28f33ef0f94420226381 F tool/win/sqlite.vsix 97894c2790eda7b5bce3cc79cb2a8ec2fde9b3ac - P 5062db672c00c3365d51cd6b39815078f5b6b525 - R 444ec66222f6e3876b5a1bc78bf6602c -P 97e5c70f2f19a1bca70dd2221b757b9e5418fce0 -R 4ded79a01068c5e1c5e1e2eba18cd5f5 ++P 322a5f086d9ee46017f750df81527799a54ae258 c77ee6e20d3a8c91a8bf4c9063c36a95c70e17cf ++R 7a3bcce0c2bcd988dcd25474f2b83a5d U drh - Z 3d135e15ecdab16eb6decd45c9d13940 -Z 80c245e483b26492a6a00ec636bab1bb ++Z 25cf293fe59d9bbc42bbcd9448a91b58 diff --cc manifest.uuid index ed40effb49,ac70cc5249..8b756b3952 --- a/manifest.uuid +++ b/manifest.uuid @@@ -1,1 -1,1 +1,1 @@@ - 322a5f086d9ee46017f750df81527799a54ae258 -c77ee6e20d3a8c91a8bf4c9063c36a95c70e17cf ++2936f7466e162dfb003bda26d35358d1b3063112 diff --cc src/where.c index 9b64fd72fe,5c0f664aec..bd8a7541fa --- a/src/where.c +++ b/src/where.c @@@ -3078,6 -3093,10 +3093,16 @@@ static int isSortingIndex ** index, then show no progress. */ if( pOBItem==&pOrderBy->a[nPriorSat] ) return nPriorSat; - /* */ ++ /* Either the outer queries must generate rows where there are no two ++ ** rows with the same values in all ORDER BY columns, or else this ++ ** loop must generate just a single row of output. Example: Suppose ++ ** the outer loops generate A=1 and A=1, and this loop generates B=3 ++ ** and B=4. Then without the following test, ORDER BY A,B would ++ ** generate the wrong order output: 1,3 1,4 1,3 1,4 ++ */ + if( outerObUnique==0 && uniqueNotNull==0 ) return nPriorSat; + *pbObUnique = uniqueNotNull; + /* Return the necessary scan order back to the caller */ *pbRev = sortOrder & 1;