]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Change the rtree module to support queries with multiple comparison operators (i...
authordan <dan@noemail.net>
Wed, 23 Mar 2011 10:38:49 +0000 (10:38 +0000)
committerdan <dan@noemail.net>
Wed, 23 Mar 2011 10:38:49 +0000 (10:38 +0000)
FossilOrigin-Name: 387b55aa9bb0f978641f9c2fa40f84fd98662047

ext/rtree/rtree.c
ext/rtree/rtree6.test
manifest
manifest.uuid

index d47c1092ef8ccdbf7c2c73f22434ac34ec2c0f16..13e5ea241c262eeed8f3e34d51168674c1de3927 100644 (file)
@@ -1353,7 +1353,7 @@ static int rtreeFilter(
 */
 static int rtreeBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
   int rc = SQLITE_OK;
-  int ii, cCol;
+  int ii;
 
   int iIdx = 0;
   char zIdxStr[RTREE_MAX_DIMENSIONS*8+1];
@@ -1361,7 +1361,7 @@ static int rtreeBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
   UNUSED_PARAMETER(tab);
 
   assert( pIdxInfo->idxStr==0 );
-  for(ii=0; ii<pIdxInfo->nConstraint; ii++){
+  for(ii=0; ii<pIdxInfo->nConstraint && iIdx<(sizeof(zIdxStr)-1); ii++){
     struct sqlite3_index_constraint *p = &pIdxInfo->aConstraint[ii];
 
     if( p->usable && p->iColumn==0 && p->op==SQLITE_INDEX_CONSTRAINT_EQ ){
@@ -1385,9 +1385,7 @@ static int rtreeBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
     }
 
     if( p->usable && (p->iColumn>0 || p->op==SQLITE_INDEX_CONSTRAINT_MATCH) ){
-      int j, opmsk;
-      static const unsigned char compatible[] = { 0, 0, 1, 1, 2, 2 };
-      u8 op = 0;
+      u8 op;
       switch( p->op ){
         case SQLITE_INDEX_CONSTRAINT_EQ: op = RTREE_EQ; break;
         case SQLITE_INDEX_CONSTRAINT_GT: op = RTREE_GT; break;
@@ -1399,37 +1397,10 @@ static int rtreeBestIndex(sqlite3_vtab *tab, sqlite3_index_info *pIdxInfo){
           op = RTREE_MATCH; 
           break;
       }
-      assert( op!=0 );
-
-      /* Make sure this particular constraint has not been used before.
-      ** If it has been used before, ignore it.
-      **
-      ** A <= or < can be used if there is a prior >= or >.
-      ** A >= or > can be used if there is a prior < or <=.
-      ** A <= or < is disqualified if there is a prior <=, <, or ==.
-      ** A >= or > is disqualified if there is a prior >=, >, or ==.
-      ** A == is disqualifed if there is any prior constraint.
-      */
-      assert( compatible[RTREE_EQ & 7]==0 );
-      assert( compatible[RTREE_LT & 7]==1 );
-      assert( compatible[RTREE_LE & 7]==1 );
-      assert( compatible[RTREE_GT & 7]==2 );
-      assert( compatible[RTREE_GE & 7]==2 );
-      cCol = p->iColumn - 1 + 'a';
-      opmsk = compatible[op & 7];
-      for(j=0; j<iIdx; j+=2){
-        if( zIdxStr[j+1]==cCol && (compatible[zIdxStr[j] & 7] & opmsk)!=0 ){
-          op = 0;
-          break;
-        }
-      }
-      if( op ){
-        assert( iIdx<sizeof(zIdxStr)-1 );
-        zIdxStr[iIdx++] = op;
-        zIdxStr[iIdx++] = cCol;
-        pIdxInfo->aConstraintUsage[ii].argvIndex = (iIdx/2);
-        pIdxInfo->aConstraintUsage[ii].omit = 1;
-      }
+      zIdxStr[iIdx++] = op;
+      zIdxStr[iIdx++] = p->iColumn - 1 + 'a';
+      pIdxInfo->aConstraintUsage[ii].argvIndex = (iIdx/2);
+      pIdxInfo->aConstraintUsage[ii].omit = 1;
     }
   }
 
index 0a29f44165d7d91d7dd56ec778b02f8d013f1f6e..7fe346b0c77e62c6288df1443ec1644f1c0d6140 100644 (file)
@@ -106,4 +106,38 @@ do_eqp_test rtree6.2.5 {
   0 1 1 {SEARCH TABLE t2 USING INTEGER PRIMARY KEY (rowid=?) (~1 rows)}
 }
 
+do_execsql_test rtree6-3.1 {
+  CREATE VIRTUAL TABLE t3 USING rtree(id, x1, x2, y1, y2);
+  INSERT INTO t3 VALUES(NULL, 1, 1, 2, 2);
+  SELECT * FROM t3 WHERE 
+    x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND 
+    x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND 
+    x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND 
+    x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND 
+    x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND 
+    x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5;
+} {1 1.0 1.0 2.0 2.0}
+
+do_test rtree6.3.2 {
+  rtree_strategy {
+    SELECT * FROM t3 WHERE 
+      x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND 
+      x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND 
+      x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND 
+      x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 
+  }
+} {EaEaEaEaEaEaEaEaEaEaEaEaEaEaEaEaEaEaEaEa}
+do_test rtree6.3.4 {
+  rtree_strategy {
+    SELECT * FROM t3 WHERE 
+      x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND 
+      x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND 
+      x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND 
+      x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND 
+      x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND 
+      x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5 AND x1>0.5
+  }
+} {EaEaEaEaEaEaEaEaEaEaEaEaEaEaEaEaEaEaEaEa}
+
+
 finish_test
index 5220ffdf428a25d3958c1468c43daf58fb3ce71d..52f3cbadbd9f3fc3a44f59f726368f223c123c23 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,8 +1,5 @@
------BEGIN PGP SIGNED MESSAGE-----
-Hash: SHA1
-
-C Add\sthe\sability\sto\senable\sand\sdisable\sforeign\skey\sconstraints\sand\striggers\nusing\scalls\sto\ssqlite3_db_config().
-D 2011-03-21T17:15:58.841
+C Change\sthe\srtree\smodule\sto\ssupport\squeries\swith\smultiple\scomparison\soperators\s(i.e.\s>\sor\s<)\sof\sthe\ssame\stype\son\sa\ssingle\scolumn.
+D 2011-03-23T10:38:50
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 27701a1653595a1f2187dc61c8117e00a6c1d50f
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -84,14 +81,14 @@ F ext/icu/README.txt bf8461d8cdc6b8f514c080e4e10dc3b2bbdfefa9
 F ext/icu/icu.c 850e9a36567bbcce6bd85a4b68243cad8e3c2de2
 F ext/icu/sqliteicu.h 728867a802baa5a96de7495e9689a8e01715ef37
 F ext/rtree/README 6315c0d73ebf0ec40dedb5aa0e942bc8b54e3761
-F ext/rtree/rtree.c 115b499415ddef9be75615ced99b11232826e64d
+F ext/rtree/rtree.c 48705ee892c30cc05cd40006d2509ad192530907
 F ext/rtree/rtree.h 834dbcb82dc85b2481cde6a07cdadfddc99e9b9e
 F ext/rtree/rtree1.test dbd4250ac0ad367a262eb9676f7e3080b0368206
 F ext/rtree/rtree2.test acbb3a4ce0f4fbc2c304d2b4b784cfa161856bba
 F ext/rtree/rtree3.test a494da55c30ee0bc9b01a91c80c81b387b22d2dc
 F ext/rtree/rtree4.test 0061e6f464fd3dc6a79f82454c5a1c3dadbe42af
 F ext/rtree/rtree5.test ce3d7ccae2cfd9d2e1052b462424964c9bdcda12
-F ext/rtree/rtree6.test 309806a2a27ef5897d4dd6aee2e8006bf754cc22
+F ext/rtree/rtree6.test 1edf30467ec39b2282874c2175b81b7690d2c706
 F ext/rtree/rtree7.test bcb647b42920b3b5d025846689147778485cc318
 F ext/rtree/rtree8.test 9772e16da71e17e02bdebf0a5188590f289ab37d
 F ext/rtree/rtree9.test df9843d1a9195249c8d3b4ea6aedda2d5c73e9c2
@@ -918,14 +915,7 @@ F tool/speedtest2.tcl ee2149167303ba8e95af97873c575c3e0fab58ff
 F tool/speedtest8.c 2902c46588c40b55661e471d7a86e4dd71a18224
 F tool/speedtest8inst1.c 293327bc76823f473684d589a8160bde1f52c14e
 F tool/vdbe-compress.tcl d70ea6d8a19e3571d7ab8c9b75cba86d1173ff0f
-P eedbcf0a0ba91bb8b9cd3d115081ba297e9959fe
-R 280ad38169dd48b2d9e175160372c567
-U drh
-Z e8e199200b835ba249870038ad2cd6dc
------BEGIN PGP SIGNATURE-----
-Version: GnuPG v1.4.6 (GNU/Linux)
-
-iD8DBQFNh4fToxKgR168RlERAhHRAJ4u99dZIoFOU0P2cr07ePpksHkgggCfST1g
-F/4WAG+YZz9MPVjqi2BaEUo=
-=dT9z
------END PGP SIGNATURE-----
+P 09e167f9c14625924b17bbb1f292f89ac9ddc93a
+R 52342b1b5ec5b2f1eb5941c495729364
+U dan
+Z a3dc1db2deb58c4b0fccde75b160266c
index 4585895670902800f81909164b4b7af41d86078c..1154a5fc3e652394c061880a85e9424fa8896596 100644 (file)
@@ -1 +1 @@
-09e167f9c14625924b17bbb1f292f89ac9ddc93a
\ No newline at end of file
+387b55aa9bb0f978641f9c2fa40f84fd98662047
\ No newline at end of file