/ 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 Unified Diffs Ignore Whitespace Patch

Changes to src/where.c.

4709
4710
4711
4712
4713
4714
4715
4716

4717
4718
4719
4720
4721
4722
4723
  }
#endif /* SQLITE_OMIT_AUTOMATIC_INDEX */

  /* Loop over all indices
  */
  for(; rc==SQLITE_OK && pProbe; pProbe=pProbe->pNext, iSortIdx++){
    if( pProbe->pPartIdxWhere!=0
     && !whereUsablePartialIndex(pNew->iTab, pWC, pProbe->pPartIdxWhere) ){

      continue;  /* Partial index inappropriate for this query */
    }
    rSize = pProbe->aiRowLogEst[0];
    pNew->u.btree.nEq = 0;
    pNew->u.btree.nSkip = 0;
    pNew->nLTerm = 0;
    pNew->iSortIdx = 0;







|
>







4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
  }
#endif /* SQLITE_OMIT_AUTOMATIC_INDEX */

  /* Loop over all indices
  */
  for(; rc==SQLITE_OK && pProbe; pProbe=pProbe->pNext, iSortIdx++){
    if( pProbe->pPartIdxWhere!=0
     && !whereUsablePartialIndex(pSrc->iCursor, pWC, pProbe->pPartIdxWhere) ){
      testcase( pNew->iTab!=pSrc->iCursor );  /* See ticket [98d973b8f5] */
      continue;  /* Partial index inappropriate for this query */
    }
    rSize = pProbe->aiRowLogEst[0];
    pNew->u.btree.nEq = 0;
    pNew->u.btree.nSkip = 0;
    pNew->nLTerm = 0;
    pNew->iSortIdx = 0;

Changes to test/index7.test.

243
244
245
246
247
248
249
250






























251
do_execsql_test index7-5.0 {
  CREATE INDEX t3b ON t3(b) WHERE xyzzy.t3.b BETWEEN 5 AND 10;
                               /* ^^^^^-- ignored */
  ANALYZE;
  SELECT count(*) FROM t3 WHERE t3.b BETWEEN 5 AND 10;
  SELECT stat+0 FROM sqlite_stat1 WHERE idx='t3b';
} {6 6}































finish_test








>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
do_execsql_test index7-5.0 {
  CREATE INDEX t3b ON t3(b) WHERE xyzzy.t3.b BETWEEN 5 AND 10;
                               /* ^^^^^-- ignored */
  ANALYZE;
  SELECT count(*) FROM t3 WHERE t3.b BETWEEN 5 AND 10;
  SELECT stat+0 FROM sqlite_stat1 WHERE idx='t3b';
} {6 6}

# Verify that the problem identified by ticket [] has been fixed.
#
do_execsql_test index7-6.1 {
  CREATE TABLE t5(a, b);
  CREATE TABLE t4(c, d);
  INSERT INTO t5 VALUES(1, 'xyz');
  INSERT INTO t4 VALUES('abc', 'not xyz');
  SELECT * FROM (SELECT * FROM t5 WHERE a=1 AND b='xyz'), t4 WHERE c='abc';
} {
  1 xyz abc {not xyz}
}
do_execsql_test index7-6.2 {
  CREATE INDEX i4 ON t4(c) WHERE d='xyz';
  SELECT * FROM (SELECT * FROM t5 WHERE a=1 AND b='xyz'), t4 WHERE c='abc';
} {
  1 xyz abc {not xyz}
}
do_execsql_test index7-6.3 {
  CREATE VIEW v4 AS SELECT * FROM t4;
  INSERT INTO t4 VALUES('def', 'xyz');
  SELECT * FROM v4 WHERE d='xyz' AND c='def'
} {
  def xyz
}
do_eqp_test index7-6.4 {
  SELECT * FROM v4 WHERE d='xyz' AND c='def'
} {
  0 0 0 {SEARCH TABLE t4 USING INDEX i4 (c=?)}
}

finish_test