]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Improved testing of the min/max optimization. (CVS 5373)
authordrh <drh@noemail.net>
Tue, 8 Jul 2008 18:05:26 +0000 (18:05 +0000)
committerdrh <drh@noemail.net>
Tue, 8 Jul 2008 18:05:26 +0000 (18:05 +0000)
FossilOrigin-Name: fa07c360b708324c47c8e9931f1e2b1b24e4faf8

manifest
manifest.uuid
src/select.c
src/where.c
test/minmax.test

index 2efb93e714a35b91a1113c6f063104adc78c4218..2b2ffdf2998e68aec6ede78c8c924999e31dab4b 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Prevent\sthe\sflattening\soptimization\sfrom\stransforming\sa\sto\sa\squery\swith\san\sillegal\sORDER\sBY\sclause.\s(CVS\s5372)
-D 2008-07-08T17:43:57
+C Improved\stesting\sof\sthe\smin/max\soptimization.\s(CVS\s5373)
+D 2008-07-08T18:05:26
 F Makefile.arm-wince-mingw32ce-gcc fcd5e9cd67fe88836360bb4f9ef4cb7f8e2fb5a0
 F Makefile.in 325dfac0a0dd1cb4d975f1ace6453157892e6042
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -140,7 +140,7 @@ F src/pragma.c 6fad83fbcc7ec6e76d91fe2805fe972ff3af6a0c
 F src/prepare.c aba51dad52308e3d9d2074d8ff4e612e7f1cab51
 F src/printf.c 8b063da9dcde26b7c500a01444b718d86f21bc6e
 F src/random.c 5c754319d38abdd6acd74601ee0105504adc508a
-F src/select.c 183a68a0af4ce20c8ebe684dd1581ce898c9f48f
+F src/select.c 46997b3399166b3c4b0d8db25c35ca099c277a50
 F src/shell.c 484e7297e066f22830f9c15d7abbcdd2acb097b0
 F src/sqlite.h.in 22c32cedf7e435d5b3bb8564ce0a640c40dbbfb1
 F src/sqlite3ext.h 1e3887c9bd3ae66cb599e922824b04cd0d0f2c3e
@@ -190,7 +190,7 @@ F src/vdbeblob.c 9345f6dcd675fdcfdb537d2d2f487542d9ea136a
 F src/vdbefifo.c c46dae1194e4277bf007144d7e5b0c0b1c24f136
 F src/vdbemem.c ee1a032b44ab59bd83a064544a0895003eecaec1
 F src/vtab.c 2096c03ec5540a43c8c73a8f43407dfd3549a982
-F src/where.c 6a22ceb86d774c4428ac53196f721bb14e6cbdfa
+F src/where.c 1422d95647c6f3ca7b8e9cf4c44ed3f255fa2637
 F tclinstaller.tcl 4356d9d94d2b5ed5e68f9f0c80c4df3048dd7617
 F test/aggerror.test a867e273ef9e3d7919f03ef4f0e8c0d2767944f2
 F test/all.test ed6849e7a425620d5d4388409f3b15901b5bc2e7
@@ -403,7 +403,7 @@ F test/manydb.test 8de36b8d33aab5ef295b11d9e95310aeded31af8
 F test/memdb.test a67bda4ff90a38f2b19f6c7f95aa7289e051d893
 F test/memleak.test d2d2a1ff7105d32dc3fdf691458cf6cba58c7217
 F test/memsubsys1.test 209156a07aaf99d095ef2e3a3a0acd5d55c978f6
-F test/minmax.test 5d56f08a7765dfb5c1fb303333f7444dacb37bef
+F test/minmax.test 722d80816f7e096bf2c04f4111f1a6c1ba65453d
 F test/minmax2.test 33504c01a03bd99226144e4b03f7631a274d66e0
 F test/minmax3.test 05110398e065875b3d9315892889d3c87fccfe2b
 F test/misc1.test 1b89c02c4a33b49dee4cd1d20d161aaaba719075
@@ -600,7 +600,7 @@ F tool/speedtest16.c c8a9c793df96db7e4933f0852abb7a03d48f2e81
 F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 1dbced29de5f59ba2ebf877edcadf171540374d1
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
-P d74fbb81ca3f973ac46534344e5076afc5dd5491
-R e1ce45277dc48c16e1fe351ba15bc433
-U danielk1977
-Z 27ce1f86b9768bde4d591564b2a9be66
+P 6c2adade34fdbe344cf73f6bac951e0c37dd003b
+R f6042400124ac27240401c0ca180db80
+U drh
+Z fc19ef422ff146e4058b15fdc6559cae
index 2e6e390c8aec1ab714f9cbc31855cd192d46d84f..d6428cc83147338509d044f60c7ad0fbe6ad660d 100644 (file)
@@ -1 +1 @@
-6c2adade34fdbe344cf73f6bac951e0c37dd003b
\ No newline at end of file
+fa07c360b708324c47c8e9931f1e2b1b24e4faf8
\ No newline at end of file
index 9275c47d5cbbe43b178779b3de9b8871696dff0e..6effc49d541dd84e2896159bcc34cdc4ac859586 100644 (file)
@@ -12,7 +12,7 @@
 ** This file contains C code routines that are called by the parser
 ** to handle SELECT statements in SQLite.
 **
-** $Id: select.c,v 1.448 2008/07/08 17:43:57 danielk1977 Exp $
+** $Id: select.c,v 1.449 2008/07/08 18:05:26 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -4241,7 +4241,7 @@ int sqlite3Select(
       if( flag ){
         pDel = pMinMax = sqlite3ExprListDup(db, p->pEList->a[0].pExpr->pList);
         if( pMinMax && !db->mallocFailed ){
-          pMinMax->a[0].sortOrder = ((flag==WHERE_ORDERBY_MIN)?0:1);
+          pMinMax->a[0].sortOrder = flag!=WHERE_ORDERBY_MIN;
           pMinMax->a[0].pExpr->op = TK_COLUMN;
         }
       }
index 009dd4848dd3e7de918267b38d5bc7d9191b78c8..97edf5be77caed4e05f3601d2eee93abd7b0595e 100644 (file)
@@ -16,7 +16,7 @@
 ** so is applicable.  Because this module is responsible for selecting
 ** indices, you might also think of this module as the "query optimizer".
 **
-** $Id: where.c,v 1.311 2008/06/26 18:04:03 danielk1977 Exp $
+** $Id: where.c,v 1.312 2008/07/08 18:05:26 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -2157,7 +2157,8 @@ WhereInfo *sqlite3WhereBegin(
                                 ppIdxInfo);
         flags = WHERE_VIRTUALTABLE;
         pIndex = *ppIdxInfo;
-        if( pIndex && pIndex->orderByConsumed ){
+        assert( pIndex!=0 );
+        if( pIndex->orderByConsumed ){
           flags = WHERE_VIRTUALTABLE | WHERE_ORDERBY;
         }
         pIdx = 0;
@@ -2546,8 +2547,9 @@ WhereInfo *sqlite3WhereBegin(
       if( (wflags&WHERE_ORDERBY_MIN)!=0
        && (pLevel->flags&WHERE_ORDERBY)
        && (pIdx->nColumn>nEq)
-       && (pOrderBy->a[0].pExpr->iColumn==pIdx->aiColumn[nEq])
       ){
+        assert( pOrderBy->nExpr==1 );
+        assert( pOrderBy->a[0].pExpr->iColumn==pIdx->aiColumn[nEq] );
         isMinQuery = 1;
       }
 
index 74c207f14aae247574b1f5f7376b25b54ebf3585..599024508cda660cd3bcb1d031e1784aae516e2f 100644 (file)
@@ -13,7 +13,7 @@
 # aggregate min() and max() functions and which are handled as
 # as a special case.
 #
-# $Id: minmax.test,v 1.20 2008/01/05 17:39:30 danielk1977 Exp $
+# $Id: minmax.test,v 1.21 2008/07/08 18:05:26 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -84,6 +84,19 @@ do_test minmax-1.10 {
   set sqlite_search_count
 } {19}
 
+do_test minmax-1.21 {
+  execsql {SELECT min(x) FROM t1 WHERE x=5}
+} {5}
+do_test minmax-1.22 {
+  execsql {SELECT min(x) FROM t1 WHERE x>=5}
+} {5}
+do_test minmax-1.23 {
+  execsql {SELECT min(x) FROM t1 WHERE x>=4.5}
+} {5}
+do_test minmax-1.24 {
+  execsql {SELECT min(x) FROM t1 WHERE x<4.5}
+} {1}
+
 do_test minmax-2.0 {
   execsql {
     CREATE TABLE t2(a INTEGER PRIMARY KEY, b);
@@ -381,4 +394,149 @@ do_test minmax-10.12 {
 } {{} {}}
 
 
+do_test minmax-11.1 {
+  execsql {
+    CREATE INDEX t1i2 ON t1(y,x);
+    SELECT min(x) FROM t1 WHERE y=5;
+  }
+} {16}
+do_test minmax-11.2 {
+  execsql {
+    SELECT max(x) FROM t1 WHERE y=5;
+  }
+} {20}
+do_test minmax-11.3 {
+  execsql {
+    SELECT min(x) FROM t1 WHERE y=6;
+  }
+} {{}}
+do_test minmax-11.4 {
+  execsql {
+    SELECT max(x) FROM t1 WHERE y=6;
+  }
+} {{}}
+do_test minmax-11.5 {
+  execsql {
+    SELECT min(x) FROM t1 WHERE y=1;
+  }
+} {1}
+do_test minmax-11.6 {
+  execsql {
+    SELECT max(x) FROM t1 WHERE y=1;
+  }
+} {1}
+do_test minmax-11.7 {
+  execsql {
+    SELECT min(x) FROM t1 WHERE y=0;
+  }
+} {{}}
+do_test minmax-11.8 {
+  execsql {
+    SELECT max(x) FROM t1 WHERE y=0;
+  }
+} {{}}
+do_test minmax-11.9 {
+  execsql {
+    SELECT min(x) FROM t1 WHERE y=5 AND x>=17.5;
+  }
+} {18}
+do_test minmax-11.10 {
+  execsql {
+    SELECT max(x) FROM t1 WHERE y=5 AND x>=17.5;
+  }
+} {20}
+
+do_test minmax-12.1 {
+  execsql {
+    CREATE TABLE t7(a,b,c);
+    INSERT INTO t7 SELECT y, x, x*y FROM t1;
+    INSERT INTO t7 SELECT y, x, x*y+1000 FROM t1;
+    CREATE INDEX t7i1 ON t7(a,b,c);
+    SELECT min(a) FROM t7;
+  }
+} {1}
+do_test minmax-12.2 {
+  execsql {
+    SELECT max(a) FROM t7;
+  }
+} {5}
+do_test minmax-12.3 {
+  execsql {
+    SELECT max(a) FROM t7 WHERE a=5;
+  }
+} {5}
+do_test minmax-12.4 {
+  execsql {
+    SELECT min(b) FROM t7 WHERE a=5;
+  }
+} {16}
+do_test minmax-12.5 {
+  execsql {
+    SELECT max(b) FROM t7 WHERE a=5;
+  }
+} {20}
+do_test minmax-12.6 {
+  execsql {
+    SELECT min(b) FROM t7 WHERE a=4;
+  }
+} {8}
+do_test minmax-12.7 {
+  execsql {
+    SELECT max(b) FROM t7 WHERE a=4;
+  }
+} {15}
+do_test minmax-12.8 {
+  execsql {
+    SELECT min(c) FROM t7 WHERE a=4 AND b=10;
+  }
+} {40}
+do_test minmax-12.9 {
+  execsql {
+    SELECT max(c) FROM t7 WHERE a=4 AND b=10;
+  }
+} {1040}
+do_test minmax-12.10 {
+  execsql {
+    SELECT min(rowid) FROM t7;
+  }
+} {1}
+do_test minmax-12.11 {
+  execsql {
+    SELECT max(rowid) FROM t7;
+  }
+} {40}
+do_test minmax-12.12 {
+  execsql {
+    SELECT min(rowid) FROM t7 WHERE a=3;
+  }
+} {4}
+do_test minmax-12.13 {
+  execsql {
+    SELECT max(rowid) FROM t7 WHERE a=3;
+  }
+} {27}
+do_test minmax-12.14 {
+  execsql {
+    SELECT min(rowid) FROM t7 WHERE a=3 AND b=5;
+  }
+} {5}
+do_test minmax-12.15 {
+  execsql {
+    SELECT max(rowid) FROM t7 WHERE a=3 AND b=5;
+  }
+} {25}
+do_test minmax-12.16 {
+  execsql {
+    SELECT min(rowid) FROM t7 WHERE a=3 AND b=5 AND c=1015;
+  }
+} {25}
+do_test minmax-12.17 {
+  execsql {
+    SELECT max(rowid) FROM t7 WHERE a=3 AND b=5 AND c=15;
+  }
+} {5}
+
+
+
+
 finish_test