/ Check-in [292a0408]
Login

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

Overview
Comment:Fix a problem causing an INDEXED BY specifying an unusable partial index to be mishandled.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 292a04086a902634fc514b379a2b245eb2681c1b84d9bb950b6ecb9aab28b468
User & Date: dan 2017-11-07 18:20:15
Context
2017-11-07
19:02
Fix handling of partial indexes in checkindex.c (sqlite3_checker). check-in: 31932a9e user: dan tags: trunk
18:20
Fix a problem causing an INDEXED BY specifying an unusable partial index to be mishandled. check-in: 292a0408 user: dan tags: trunk
16:54
Add the --trace option to the sqlite3_checker utility program. check-in: dc217b7c user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/where.c.

  2865   2865           pNew->prereq = mPrereq | pTerm->prereqRight;
  2866   2866           rc = whereLoopInsert(pBuilder, pNew);
  2867   2867         }
  2868   2868       }
  2869   2869     }
  2870   2870   #endif /* SQLITE_OMIT_AUTOMATIC_INDEX */
  2871   2871   
  2872         -  /* Loop over all indices
  2873         -  */
  2874         -  for(; rc==SQLITE_OK && pProbe; pProbe=pProbe->pNext, iSortIdx++){
         2872  +  /* Loop over all indices. If there was an INDEXED BY clause, then only 
         2873  +  ** consider index pProbe.  */
         2874  +  for(; rc==SQLITE_OK && pProbe; 
         2875  +      pProbe=(pSrc->pIBIndex ? 0 : pProbe->pNext), iSortIdx++
         2876  +  ){
  2875   2877       if( pProbe->pPartIdxWhere!=0
  2876   2878        && !whereUsablePartialIndex(pSrc->iCursor, pWC, pProbe->pPartIdxWhere) ){
  2877   2879         testcase( pNew->iTab!=pSrc->iCursor );  /* See ticket [98d973b8f5] */
  2878   2880         continue;  /* Partial index inappropriate for this query */
  2879   2881       }
  2880   2882       rSize = pProbe->aiRowLogEst[0];
  2881   2883       pNew->u.btree.nEq = 0;
................................................................................
  2977   2979         pTab->tabFlags |= TF_StatsUsed;
  2978   2980       }
  2979   2981   #ifdef SQLITE_ENABLE_STAT3_OR_STAT4
  2980   2982       sqlite3Stat4ProbeFree(pBuilder->pRec);
  2981   2983       pBuilder->nRecValid = 0;
  2982   2984       pBuilder->pRec = 0;
  2983   2985   #endif
  2984         -
  2985         -    /* If there was an INDEXED BY clause, then only that one index is
  2986         -    ** considered. */
  2987         -    if( pSrc->pIBIndex ) break;
  2988   2986     }
  2989   2987     return rc;
  2990   2988   }
  2991   2989   
  2992   2990   #ifndef SQLITE_OMIT_VIRTUALTABLE
  2993   2991   
  2994   2992   /*

Changes to test/indexedby.test.

   359    359   } {1 1 3}
   360    360   do_execsql_test 11.9 {
   361    361     SELECT a,b,c FROM x2 INDEXED BY x2i WHERE a=1 AND b=1 AND c='3.0';
   362    362   } {1 1 3}
   363    363   do_eqp_test 11.10 {
   364    364     SELECT a,b,c FROM x2 INDEXED BY x2i WHERE a=1 AND b=1 AND c='3.0';
   365    365   } {0 0 0 {SEARCH TABLE x2 USING COVERING INDEX x2i (a=? AND b=? AND rowid=?)}}
          366  +
          367  +#-------------------------------------------------------------------------
          368  +# Check INDEXED BY works (throws an exception) with partial indexes that 
          369  +# cannot be used.
          370  +do_execsql_test 12.1 {
          371  +  CREATE TABLE o1(x INTEGER PRIMARY KEY, y, z);
          372  +  CREATE INDEX p1 ON o1(z);
          373  +  CREATE INDEX p2 ON o1(y) WHERE z=1;
          374  +}
          375  +do_catchsql_test 12.2 {
          376  +  SELECT * FROM o1 INDEXED BY p2 ORDER BY 1;
          377  +} {1 {no query solution}}
          378  +do_execsql_test 12.3 {
          379  +  DROP INDEX p1;
          380  +  DROP INDEX p2;
          381  +  CREATE INDEX p2 ON o1(y) WHERE z=1;
          382  +  CREATE INDEX p1 ON o1(z);
          383  +}
          384  +do_catchsql_test 12.4 {
          385  +  SELECT * FROM o1 INDEXED BY p2 ORDER BY 1;
          386  +} {1 {no query solution}}
   366    387   
   367    388   finish_test