1
0
mirror of https://github.com/sqlite/sqlite.git synced 2025-07-29 08:01:23 +03:00

Fix the count-optimization so that it honors the NOT INDEXED clause.

FossilOrigin-Name: 0d23a0b209900f4d7c6c13f75d4364f19afc23db72f9cfdb11e05b81502e8040
This commit is contained in:
drh
2020-05-08 18:22:00 +00:00
parent 91d4c374e2
commit 98aa1d735e
4 changed files with 55 additions and 15 deletions

View File

@ -196,4 +196,42 @@ do_catchsql_test count-6.1 {
SELECT count(DISTINCT) FROM t6 GROUP BY x;
} {1 {DISTINCT aggregates must have exactly one argument}}
# 2020-05-08.
# The count() optimization should honor the NOT INDEXED clause
#
reset_db
do_execsql_test count-7.1 {
CREATE TABLE t1(a INTEGER PRIMARY KEY, b INT, c VARCHAR(1000));
CREATE INDEX t1b ON t1(b);
INSERT INTO t1(a,b,c) values(1,2,'count.test cases for NOT INDEXED');
ANALYZE;
UPDATE sqlite_stat1 SET stat='1000000 10' WHERE idx='t1b';
ANALYZE sqlite_master;
}
do_eqp_test count-7.2 {
SELECT count(1) FROM t1;
} {
QUERY PLAN
`--SCAN TABLE t1 USING COVERING INDEX t1b
}
do_eqp_test count-7.3 {
SELECT count(1) FROM t1 NOT INDEXED
} {
QUERY PLAN
`--SCAN TABLE t1
}
do_eqp_test count-7.3 {
SELECT count(*) FROM t1;
} {
QUERY PLAN
`--SCAN TABLE t1 USING COVERING INDEX t1b
}
do_eqp_test count-7.4 {
SELECT count(*) FROM t1 NOT INDEXED
} {
QUERY PLAN
`--SCAN TABLE t1
}
finish_test