/ Check-in [eba95ead]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix the generation of sqlite3_rtree_query_info.iRowid and add test cases to verify that it is fixed.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | rtree-enhancements
Files: files | file ages | folders
SHA1: eba95ead49f8f8ce45d400186562ff0066537c5c
User & Date: drh 2014-04-21 18:13:37
Context
2014-04-25
16:29
Enhance the sqlite3_rtree_query_info object to report on the number of elements in the priority queue at each level. Closed-Leaf check-in: f7dad408 user: drh tags: rtree-enhancements
2014-04-21
18:13
Fix the generation of sqlite3_rtree_query_info.iRowid and add test cases to verify that it is fixed. check-in: eba95ead user: drh tags: rtree-enhancements
15:53
Be sure to initialize the sqlite3_rtree_query_info.iRowid field for the leaves of the R-Tree when doing a query callback search. check-in: 43946938 user: drh tags: rtree-enhancements
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to ext/rtree/rtree.c.

   958    958     int nCoord = pInfo->nCoord;                           /* No. of coordinates */
   959    959     int rc;                                             /* Callback return code */
   960    960     sqlite3_rtree_dbl aCoord[RTREE_MAX_DIMENSIONS*2];   /* Decoded coordinates */
   961    961   
   962    962     assert( pConstraint->op==RTREE_MATCH || pConstraint->op==RTREE_QUERY );
   963    963     assert( nCoord==2 || nCoord==4 || nCoord==6 || nCoord==8 || nCoord==10 );
   964    964   
   965         -  if( pConstraint->op==RTREE_MATCH && pSearch->iLevel==1 ){
          965  +  if( pConstraint->op==RTREE_QUERY && pSearch->iLevel==1 ){
   966    966       pInfo->iRowid = readInt64(pCellData);
   967    967     }
   968    968     pCellData += 8;
   969    969     for(i=0; i<nCoord; i++, pCellData += 4){
   970    970       RTREE_DECODE_COORD(eInt, pCellData, aCoord[i]);
   971    971     }
   972    972     if( pConstraint->op==RTREE_MATCH ){

Changes to ext/rtree/rtreeE.test.

    63     63   # This causes the 200s to sort before the 100s and the 0s to sort before
    64     64   # last.
    65     65   #
    66     66   do_execsql_test rtreeE-1.4 {
    67     67     SELECT id FROM rt1 WHERE id MATCH Qcircle(0,0,1000,3) AND id%100==0
    68     68   } {200 100 0}
    69     69   
           70  +# Exclude odd rowids on a depth-first search
           71  +do_execsql_test rtreeE-1.5 {
           72  +  SELECT id FROM rt1 WHERE id MATCH Qcircle(0,0,1000,4) ORDER BY +id
           73  +} {0 2 4 6 8 10 12 14 16 18 20 22 24 100 102 104 106 108 110 112 114 116 118 120 122 124 200 202 204 206 208 210 212 214 216 218 220 222 224}
           74  +
           75  +# Exclude odd rowids on a breadth-first search.
           76  +do_execsql_test rtreeE-1.6 {
           77  +  SELECT id FROM rt1 WHERE id MATCH Qcircle(0,0,1000,5) ORDER BY +id
           78  +} {0 2 4 6 8 10 12 14 16 18 20 22 24 100 102 104 106 108 110 112 114 116 118 120 122 124 200 202 204 206 208 210 212 214 216 218 220 222 224}
           79  +
    70     80   # Construct a large 2-D RTree with thousands of random entries.
    71     81   #
    72     82   do_test rtreeE-2.1 {
    73     83     db eval {
    74     84       CREATE TABLE t2(id,x0,x1,y0,y1);
    75     85       CREATE VIRTUAL TABLE rt2 USING rtree(id,x0,x1,y0,y1);
    76     86       BEGIN;

Changes to src/test_rtree.c.

   251    251   
   252    252     if( pCircle->eScoreType==1 ){
   253    253       /* Depth first search */
   254    254       p->rScore = p->iLevel;
   255    255     }else if( pCircle->eScoreType==2 ){
   256    256       /* Breadth first search */
   257    257       p->rScore = 100 - p->iLevel;
   258         -  }else{
          258  +  }else if( pCircle->eScoreType==3 ){
   259    259       /* Depth-first search, except sort the leaf nodes by area with
   260    260       ** the largest area first */
   261    261       if( p->iLevel==1 ){
   262    262         p->rScore = 1.0 - (xmax-xmin)*(ymax-ymin)/pCircle->mxArea;
   263    263         if( p->rScore<0.01 ) p->rScore = 0.01;
   264    264       }else{
   265    265         p->rScore = 0.0;
   266    266       }
          267  +  }else if( pCircle->eScoreType==4 ){
          268  +    /* Depth-first search, except exclude odd rowids */
          269  +    p->rScore = p->iLevel;
          270  +    if( p->iRowid&1 ) nWithin = 0;
          271  +  }else{
          272  +    /* Breadth-first search, except exclude odd rowids */
          273  +    p->rScore = 100 - p->iLevel;
          274  +    if( p->iRowid&1 ) nWithin = 0;
   267    275     }
   268    276     if( nWithin==0 ){
   269    277       p->eWithin = NOT_WITHIN;
   270    278     }else if( nWithin>=4 ){
   271    279       p->eWithin = FULLY_WITHIN;
   272    280     }else{
   273    281       p->eWithin = PARTLY_WITHIN;