Skip to content

Commit

Permalink
Disable the skip-scan optimization for DISTINCT queries.
Browse files Browse the repository at this point in the history
Fix for ticket [ced41c7c7d6b4d36]
  • Loading branch information
D. Richard Hipp committed Jul 30, 2019
1 parent 496878e commit 4e64819
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/where.c
Original file line number Diff line number Diff line change
Expand Up @@ -2723,6 +2723,7 @@ static int whereLoopAddBtreeIndex(
&& pProbe->noSkipScan==0
&& OptimizationEnabled(db, SQLITE_SkipScan)
&& pProbe->aiRowLogEst[saved_nEq+1]>=42 /* TUNING: Minimum for skip-scan */
&& (pWInfo->wctrlFlags & (WHERE_WANT_DISTINCT|WHERE_DISTINCTBY))==0
&& (rc = whereLoopResize(db, pNew, pNew->nLTerm+1))==SQLITE_OK
){
LogEst nIter;
Expand Down
17 changes: 17 additions & 0 deletions test/skipscan1.test
Original file line number Diff line number Diff line change
Expand Up @@ -373,4 +373,21 @@ do_execsql_test skipscan1-2.3 {
SELECT a,b,c,d,'|' FROM t6 WHERE d<>99 AND b=345 ORDER BY a DESC;
} {}

# 2019-07-29 Ticket ced41c7c7d6b4d36
# Skip-scan is disabled for DISTINCT queries
#
db close
sqlite3 db :memory:
do_execsql_test skipscan1-3.1 {
CREATE TABLE t1 (c1, c2, c3, c4, PRIMARY KEY(c4, c3));
INSERT INTO t1 VALUES(NULL,0,1,NULL);
INSERT INTO t1 VALUES(0,NULL,1,NULL);
INSERT INTO t1 VALUES(NULL,NULL,1,NULL);
ANALYZE sqlite_master;
INSERT INTO sqlite_stat1 VALUES('t1','sqlite_autoindex_t1_1','18 18 6');
ANALYZE sqlite_master;
SELECT DISTINCT quote(c1), quote(c2), quote(c3), quote(c4), '|'
FROM t1 WHERE t1.c3 = 1;
} {NULL 0 1 NULL | 0 NULL 1 NULL | NULL NULL 1 NULL |}

finish_test

0 comments on commit 4e64819

Please sign in to comment.