]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Allow an index paired with a NOT NULL constraint to be used for sorting
authordrh <drh@noemail.net>
Fri, 11 Feb 2011 03:56:11 +0000 (03:56 +0000)
committerdrh <drh@noemail.net>
Fri, 11 Feb 2011 03:56:11 +0000 (03:56 +0000)
under the condition that the index be treated as a non-unique index.

FossilOrigin-Name: d78949fc93077e1aa7f05cf9f7e947727939cc96

manifest
manifest.uuid
src/where.c
test/tkt3824.test

index 0538467c2958d9aa28c2e597c6d3b799d0200fd1..e16afa35bb917453a1181fcfaf0b25849ac05410 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,8 +1,8 @@
 -----BEGIN PGP SIGNED MESSAGE-----
 Hash: SHA1
 
-C Disable\sunused\sNULL\stests\swhen\sSQLITE_ENABLE_STAT2\sis\snot\sin\suse.
-D 2011-02-11T02:43:14.522
+C Allow\san\sindex\spaired\swith\sa\sNOT\sNULL\sconstraint\sto\sbe\sused\sfor\ssorting\nunder\sthe\scondition\sthat\sthe\sindex\sbe\streated\sas\sa\snon-unique\sindex.
+D 2011-02-11T03:56:11.449
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 27701a1653595a1f2187dc61c8117e00a6c1d50f
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -244,7 +244,7 @@ F src/vtab.c b297e8fa656ab5e66244ab15680d68db0adbec30
 F src/wal.c aca10a60655e103fc8630a75345000f43c6d47ca
 F src/wal.h 7a5fbb00114b7f2cd40c7e1003d4c41ce9d26840
 F src/walker.c 3112bb3afe1d85dc52317cb1d752055e9a781f8f
-F src/where.c 612ca339d1d1d076ff7d933ec86bb8548f978892
+F src/where.c 96d634b85310cfcfe89f004aa8525b57d8898315
 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
 F test/alias.test 4529fbc152f190268a15f9384a5651bbbabc9d87
 F test/all.test 51756962d522e474338e9b2ebb26e7364d4aa125
@@ -780,7 +780,7 @@ F test/tkt3773.test 430b06567ce40285dfd2c4834a2a61816403efeb
 F test/tkt3791.test a6624b9a80b216a26cf473607f42f3e51898c267
 F test/tkt3793.test 754b73f0e6a9349c70dc57e522cf3247272ecd5d
 F test/tkt3810.test 90fa0635dfa7da9680c8cd3513350a49b3a8ae12
-F test/tkt3824.test 3da2f5c81b057e3ff355f5dfc9aa0cf0a92e0206
+F test/tkt3824.test 150aa00bb6220672e5f0eb14dc8eaa36750425f0
 F test/tkt3832.test 2300d10d57562b89875b72148338ac3e14f8847d
 F test/tkt3838.test f956f0719b5f805b12dd1dbf19f19d298bacebc3
 F test/tkt3841.test 4659845bc53f809a5932c61c6ce8c5bb9d6b947f
@@ -909,14 +909,14 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P f85afa0ecc7b31d32659ae53e70771cd42abda38
-R 6c9f8fa6a95f1c6416ba30a2f337f141
+P 5ecd11788269e78dc26639b2503a10b7e25b2483
+R efe2bc1def692179832d1c52a5f44bf5
 U drh
-Z 031fc29c45bc927547b928a448afa15e
+Z 7fabc9263a982330a71ce326ddcb4d5b
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.6 (GNU/Linux)
 
-iD8DBQFNVKJGoxKgR168RlERAhU0AKCBT4jzm3Kj7UEwq0dWnN39SWVL6gCffkF9
-sYAMWWqE055NfvfyH8VwD8g=
-=sVIn
+iD8DBQFNVLNeoxKgR168RlERAnOpAKCHCIoShZYXHuUaFypK9VIeAKx74QCfeuXj
+wxJDR+7h4QKi3fBF3WRZCW4=
+=fdWc
 -----END PGP SIGNATURE-----
index a33f4acee01b9da15e5ed7ac9e33979f520c2fd7..073b551de94b0ae43e877d086dc60db3a0aa8cfc 100644 (file)
@@ -1 +1 @@
-5ecd11788269e78dc26639b2503a10b7e25b2483
\ No newline at end of file
+d78949fc93077e1aa7f05cf9f7e947727939cc96
\ No newline at end of file
index 7710225bb8c197b07cefce411b9cf81deb87fc0d..c6f0cbe3f5c9424f511e2a7d3776f264bd0f1f61 100644 (file)
@@ -1419,6 +1419,7 @@ static int isSortingIndex(
   int base,               /* Cursor number for the table to be sorted */
   ExprList *pOrderBy,     /* The ORDER BY clause */
   int nEqCol,             /* Number of index columns with == constraints */
+  int wsFlags,            /* Index usages flags */
   int *pbRev              /* Set to 1 if ORDER BY is DESC */
 ){
   int i, j;                       /* Loop counters */
@@ -1524,11 +1525,14 @@ static int isSortingIndex(
     return 1;
   }
   if( pIdx->onError!=OE_None && i==pIdx->nColumn
+      && (wsFlags & WHERE_COLUMN_NULL)==0
       && !referencesOtherTables(pOrderBy, pMaskSet, j, base) ){
     /* All terms of this index match some prefix of the ORDER BY clause
     ** and the index is UNIQUE and no terms on the tail of the ORDER BY
     ** clause reference other tables in a join.  If this is all true then
-    ** the order by clause is superfluous. */
+    ** the order by clause is superfluous.  Not that if the matching
+    ** condition is IS NULL then the result is not necessarily unique
+    ** even on a UNIQUE index, so disallow those cases. */
     return 1;
   }
   return 0;
@@ -2881,8 +2885,9 @@ static void bestBtreeIndex(
     ** in wsFlags. Otherwise, if there is an ORDER BY clause but the index
     ** will scan rows in a different order, set the bSort variable.  */
     if( pOrderBy ){
-      if( (wsFlags & (WHERE_COLUMN_IN|WHERE_COLUMN_NULL))==0
-        && isSortingIndex(pParse,pWC->pMaskSet,pProbe,iCur,pOrderBy,nEq,&rev)
+      if( (wsFlags & WHERE_COLUMN_IN)==0
+        && isSortingIndex(pParse, pWC->pMaskSet, pProbe, iCur, pOrderBy,
+                          nEq, wsFlags, &rev)
       ){
         wsFlags |= WHERE_ROWID_RANGE|WHERE_COLUMN_RANGE|WHERE_ORDERBY;
         wsFlags |= (rev ? WHERE_REVERSE : 0);
index 5b447bff4ade2aedacf52ef69cf406037b8f6743..3198abbdd3afbd17b801727cfb6c73c97649284e 100644 (file)
@@ -72,7 +72,7 @@ do_test tkt3824-2.3 {
   lsort [execsql_status {
     SELECT a FROM t2 WHERE b=2 AND c IS NULL ORDER BY b;
   }]
-} {5 9 sort}
+} {5 9 nosort}
 
 do_test tkt3824-3.1 {
   db eval {