]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Make sure the min() and max() optimizations work on empty indexed tables.
authordrh <drh@noemail.net>
Thu, 17 Apr 2003 12:44:23 +0000 (12:44 +0000)
committerdrh <drh@noemail.net>
Thu, 17 Apr 2003 12:44:23 +0000 (12:44 +0000)
Ticket #296. (CVS 914)

FossilOrigin-Name: 98ef6110068e5ed3cd77a14b004f890b79b731f7

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

index d02b4703f0a9bc7f8c2fd959500efdc72bf6c8a3..53008cbe407402b53d21919c2180a189b6245404 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Change\sthe\sshell\sto\suse\sthe\ssqliteIsNumber()\sroutine\sfor\sdetermining\sif\nvalues\sare\snumeric.\s\sModified\sos.c\sso\sthat\sit\sshould\snow\swork\swith\sDJGPP\s-\nthough\sI\shave\sno\sway\sof\stesting\sthis.\s(CVS\s913)
-D 2003-04-17T02:54:14
+C Make\ssure\sthe\smin()\sand\smax()\soptimizations\swork\son\sempty\sindexed\stables.\nTicket\s#296.\s(CVS\s914)
+D 2003-04-17T12:44:24
 F Makefile.in df3a4db41a7450468b5fe934d9dd8f723b631249
 F Makefile.linux-gcc b86a99c493a5bfb402d1d9178dcdc4bd4b32f906
 F README f1de682fbbd94899d50aca13d387d1b3fd3be2dd
@@ -43,7 +43,7 @@ F src/parse.y 3be47fa18323aa2e3364fc42bf7a6ba5b3cc0a81
 F src/pragma.c aef327bd597e15f0d31f45b042bd2797cca65039
 F src/printf.c fc5fdef6e92ad205005263661fe9716f55a49f3e
 F src/random.c 19e8e00fe0df32a742f115773f57651be327cabe
-F src/select.c 14e2e2a512f4edfc75fb310ebcb502ff3ee87402
+F src/select.c 84168d6ef8deac8436179a0219393572e0b84517
 F src/shell.c 6980eadda7506f741ab42fd9d32613e2fdabafa9
 F src/shell.tcl 27ecbd63dd88396ad16d81ab44f73e6c0ea9d20e
 F src/sqlite.h.in f49c2cdec7d24cb03e496a1ca519e16306495ee1
@@ -59,7 +59,7 @@ F src/trigger.c 4ca4499d367548385b8e9fc67eb360cd1ca95b8a
 F src/update.c a60470d07cdd4ff3c11c5418f8055f2f41b3d751
 F src/util.c 13c338a7d0e1e6290ca227edb0d6d7be6a7c7127
 F src/vacuum.c ac65e9578506a0cdf70ece2668e5b22f4895477c
-F src/vdbe.c ef99c9f6189218ccf7e19a45bf7de637f970c999
+F src/vdbe.c d453e8c95c9fac5a5e067c5c58243b3ae75699fc
 F src/vdbe.h 985c24f312d10f9ef8f9a8b8ea62fcdf68e82f21
 F src/where.c e5733f7d5e9cc4ed3590dc3401f779e7b7bb8127
 F test/all.test 569a92a8ee88f5300c057cc4a8f50fbbc69a3242
@@ -92,7 +92,7 @@ F test/lock.test 388a3a10962d2d571c0c1821cc35bf069ee73473
 F test/main.test 8108ac48302027bbe4296c30b913adbe6d5d984b
 F test/malloc.test 7ba32a9ebd3aeed52ae4aaa6d42ca37e444536fd
 F test/memleak.test a18e6810cae96d2f6f5136920267adbefc8e1e90
-F test/minmax.test 29bc5727c3e4c792d5c4745833dd4b505905819e
+F test/minmax.test b54ac3bc45460a4976b08ef363e05c032418726e
 F test/misc1.test 865c907df58195364eaf2e69426e9674bc8d1a8c
 F test/misuse.test a3aa2b18a97e4c409a1fcaff5151a4dd804a0162
 F test/notnull.test 7a08117a71e74b0321aaa937dbeb41a09d6eb1d0
@@ -126,7 +126,7 @@ F test/update.test 198360dfa14e65354dbcc66d5b98d8070780e42b
 F test/vacuum.test 059871b312eb910bbe49dafde1d01490cc2c6bbe
 F test/version.test 605fd0d7e7d571370c32b12dbf395b58953de246
 F test/view.test c64fa39ea57f3c2066c854290f032ad13b23b83d
-F test/where.test ffaa91611edb8961d887d02492aa13f82782ff66
+F test/where.test c473910ac79aaff49ba1f4d832a6f6a27db0cda3
 F tool/diffdb.c 7524b1b5df217c20cd0431f6789851a4e0cb191b
 F tool/lemon.c 14fedcde9cf70aa6040b89de164cf8f56f92a4b9
 F tool/lempar.c 73a991cc3017fb34804250fa901488b5147b3717
@@ -162,7 +162,7 @@ F www/speed.tcl cb4c10a722614aea76d2c51f32ee43400d5951be
 F www/sqlite.tcl ae3dcfb077e53833b59d4fcc94d8a12c50a44098
 F www/tclsqlite.tcl 1db15abeb446aad0caf0b95b8b9579720e4ea331
 F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218
-P 5cea7554ae9d36434cd7261b5b40f3d467b836f1
-R 02865a72582f56772c59d063e3ecf5aa
+P 35caefe31750fd103b5f0231ad36f375771063eb
+R 863a74a305f0c2f82dcca28addb978eb
 U drh
-Z e1cf076e54a9004f700a5082c4a00108
+Z ff7113cb2286f12309cb08ea1daacc5c
index 005615a0144017f03c117f86e769aae27a91f27c..a54a60ce48759c62f8f45608d11ccb73e8470a7a 100644 (file)
@@ -1 +1 @@
-35caefe31750fd103b5f0231ad36f375771063eb
\ No newline at end of file
+98ef6110068e5ed3cd77a14b004f890b79b731f7
\ No newline at end of file
index 92efa61e9bd2485689d6c87d98f731f23127e923..013db333989045980e61a08f4f701f73d4e2b3ec 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.130 2003/03/31 13:36:09 drh Exp $
+** $Id: select.c,v 1.131 2003/04/17 12:44:24 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -1820,6 +1820,7 @@ static int simpleMinMaxQuery(Parse *pParse, Select *p, int eDest, int iParm){
   sqliteVdbeAddOp(v, OP_Integer, pTab->iDb, 0);
   sqliteVdbeAddOp(v, OP_OpenRead, base, pTab->tnum);
   sqliteVdbeChangeP3(v, -1, pTab->zName, P3_STATIC);
+  cont = sqliteVdbeMakeLabel(v);
   if( pIdx==0 ){
     sqliteVdbeAddOp(v, seekOp, base, 0);
   }else{
@@ -1835,7 +1836,6 @@ static int simpleMinMaxQuery(Parse *pParse, Select *p, int eDest, int iParm){
   memset(&eListItem, 0, sizeof(eListItem));
   eList.a = &eListItem;
   eList.a[0].pExpr = pExpr;
-  cont = sqliteVdbeMakeLabel(v);
   selectInnerLoop(pParse, p, &eList, 0, 0, 0, -1, eDest, iParm, cont, cont);
   sqliteVdbeResolveLabel(v, cont);
   sqliteVdbeAddOp(v, OP_Close, base, 0);
index 5b4fa2d6c2c14d69900ec558ce1ed50d27c424bd..127a6fae2ee339ab3f3b2a71cdb8dd6d3b63c081 100644 (file)
@@ -36,7 +36,7 @@
 ** in this file for details.  If in doubt, do not deviate from existing
 ** commenting and indentation practices when changing or adding code.
 **
-** $Id: vdbe.c,v 1.217 2003/04/16 21:03:14 drh Exp $
+** $Id: vdbe.c,v 1.218 2003/04/17 12:44:25 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -4505,10 +4505,14 @@ case OP_IdxRecno: {
     int v;
     int sz;
     sqliteBtreeKeySize(pCrsr, &sz);
-    sqliteBtreeKey(pCrsr, sz - sizeof(u32), sizeof(u32), (char*)&v);
-    v = keyToInt(v);
-    aStack[tos].i = v;
-    aStack[tos].flags = STK_Int;
+    if( sz<sizeof(u32) ){
+      aStack[tos].flags = STK_Null;
+    }else{
+      sqliteBtreeKey(pCrsr, sz - sizeof(u32), sizeof(u32), (char*)&v);
+      v = keyToInt(v);
+      aStack[tos].i = v;
+      aStack[tos].flags = STK_Int;
+    }
   }
   break;
 }
index 86ec8a60ad347d3e25074c5dfa8b85e5c97f0f0b..551fd3e53bdff47461e51cfc1e761fe4fcba4984 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.4 2002/05/31 15:51:26 drh Exp $
+# $Id: minmax.test,v 1.5 2003/04/17 12:44:25 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -143,4 +143,35 @@ do_test minmax-4.3 {
   }
 } {1 1 1 2 2 3 3 4 5 4 8 9 5 5 6 6 0 1}
 
+# Make sure the min(x) and max(x) optimizations work on empty tables
+# including empty tables with indices. Ticket #296.
+#
+do_test minmax-5.1 {
+  execsql {
+    CREATE TABLE t3(x INTEGER UNIQUE NOT NULL);
+    SELECT coalesce(min(x),999) FROM t3;
+  }
+} {999}
+do_test minmax-5.2 {
+  execsql {
+    SELECT coalesce(min(rowid),999) FROM t3;
+  }
+} {999}
+do_test minmax-5.3 {
+  execsql {
+    SELECT coalesce(max(x),999) FROM t3;
+  }
+} {999}
+do_test minmax-5.4 {
+  execsql {
+    SELECT coalesce(max(rowid),999) FROM t3;
+  }
+} {999}
+do_test minmax-5.5 {
+  execsql {
+    SELECT coalesce(max(rowid),999) FROM t3 WHERE rowid<25;
+  }
+} {999}
+
+
 finish_test
index 32bd0d139b0a3dadfd3ba7274b01f5d711300c69..3afa5d0fb0ec63e7ba665b315bd99ca4a3d1e484 100644 (file)
@@ -11,7 +11,7 @@
 # This file implements regression tests for SQLite library.  The
 # focus of this file is testing the use of indices in WHERE clases.
 #
-# $Id: where.test,v 1.13 2002/12/04 22:29:29 drh Exp $
+# $Id: where.test,v 1.14 2003/04/17 12:44:25 drh Exp $
 
 set testdir [file dirname $argv0]
 source $testdir/tester.tcl
@@ -687,5 +687,25 @@ do_test where-8.2 {
   }
 } {nosort}
 
+# Make sure searches with an index work with an empty table.
+#
+do_test where-9.1 {
+  execsql {
+    CREATE TABLE t5(x PRIMARY KEY);
+    SELECT * FROM t5 WHERE x<10;
+  }
+} {}
+do_test where-9.2 {
+  execsql {
+    SELECT * FROM t5 WHERE x<10 ORDER BY x DESC;
+  }
+} {}
+do_test where-9.3 {
+  execsql {
+    SELECT * FROM t5 WHERE x=10;
+  }
+} {}
+
+
 
 finish_test