/ Check-in [fcebca16]
Login

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

Overview
Comment:When determining whether or not a partial index is usable, do not assume that the cursor number assigned to each table in the query is the same as its index in the FROM clause. Fix for ticket [98d973b8f5].
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: fcebca166f15431764b82a8b267f11d28386e975
User & Date: dan 2014-08-27 17:37:20
Context
2014-08-27
17:48
Add a missing ticket number to a comment in index7.test. check-in: d8b1c433 user: dan tags: trunk
17:37
When determining whether or not a partial index is usable, do not assume that the cursor number assigned to each table in the query is the same as its index in the FROM clause. Fix for ticket [98d973b8f5]. check-in: fcebca16 user: dan tags: trunk
14:14
In the sqlite3_context object, keep a pointer to the result value rather than storing the result value in the sqlite3_context object and using memcpy() to move the value back into its register after the function returns. This runs faster and saves over 500 bytes of code space. check-in: 6c1ee3e3 user: drh tags: trunk
Changes
Hide Diffs Side-by-Side Diffs Ignore Whitespace Patch

Changes to src/where.c.

  4709   4709     }
  4710   4710   #endif /* SQLITE_OMIT_AUTOMATIC_INDEX */
  4711   4711   
  4712   4712     /* Loop over all indices
  4713   4713     */
  4714   4714     for(; rc==SQLITE_OK && pProbe; pProbe=pProbe->pNext, iSortIdx++){
  4715   4715       if( pProbe->pPartIdxWhere!=0
  4716         -     && !whereUsablePartialIndex(pNew->iTab, pWC, pProbe->pPartIdxWhere) ){
         4716  +     && !whereUsablePartialIndex(pSrc->iCursor, pWC, pProbe->pPartIdxWhere) ){
         4717  +      testcase( pNew->iTab!=pSrc->iCursor );  /* See ticket [98d973b8f5] */
  4717   4718         continue;  /* Partial index inappropriate for this query */
  4718   4719       }
  4719   4720       rSize = pProbe->aiRowLogEst[0];
  4720   4721       pNew->u.btree.nEq = 0;
  4721   4722       pNew->u.btree.nSkip = 0;
  4722   4723       pNew->nLTerm = 0;
  4723   4724       pNew->iSortIdx = 0;

Changes to test/index7.test.

   243    243   do_execsql_test index7-5.0 {
   244    244     CREATE INDEX t3b ON t3(b) WHERE xyzzy.t3.b BETWEEN 5 AND 10;
   245    245                                  /* ^^^^^-- ignored */
   246    246     ANALYZE;
   247    247     SELECT count(*) FROM t3 WHERE t3.b BETWEEN 5 AND 10;
   248    248     SELECT stat+0 FROM sqlite_stat1 WHERE idx='t3b';
   249    249   } {6 6}
          250  +
          251  +# Verify that the problem identified by ticket [] has been fixed.
          252  +#
          253  +do_execsql_test index7-6.1 {
          254  +  CREATE TABLE t5(a, b);
          255  +  CREATE TABLE t4(c, d);
          256  +  INSERT INTO t5 VALUES(1, 'xyz');
          257  +  INSERT INTO t4 VALUES('abc', 'not xyz');
          258  +  SELECT * FROM (SELECT * FROM t5 WHERE a=1 AND b='xyz'), t4 WHERE c='abc';
          259  +} {
          260  +  1 xyz abc {not xyz}
          261  +}
          262  +do_execsql_test index7-6.2 {
          263  +  CREATE INDEX i4 ON t4(c) WHERE d='xyz';
          264  +  SELECT * FROM (SELECT * FROM t5 WHERE a=1 AND b='xyz'), t4 WHERE c='abc';
          265  +} {
          266  +  1 xyz abc {not xyz}
          267  +}
          268  +do_execsql_test index7-6.3 {
          269  +  CREATE VIEW v4 AS SELECT * FROM t4;
          270  +  INSERT INTO t4 VALUES('def', 'xyz');
          271  +  SELECT * FROM v4 WHERE d='xyz' AND c='def'
          272  +} {
          273  +  def xyz
          274  +}
          275  +do_eqp_test index7-6.4 {
          276  +  SELECT * FROM v4 WHERE d='xyz' AND c='def'
          277  +} {
          278  +  0 0 0 {SEARCH TABLE t4 USING INDEX i4 (c=?)}
          279  +}
   250    280   
   251    281   finish_test