Re: [sqlite] Missed index opportunities with sorting?

2019-12-09 Thread Graham Holden
Monday, December 09, 2019, 1:32:40 PM, Digital Dog wrote: > On Sat, Dec 7, 2019 at 3:50 AM Simon Slavin wrote: >> On 7 Dec 2019, at 2:26am, Shawn Wagner wrote: >> >> > The first one uses the index for all sorting, but the second one only >> uses it for sorting a, not b. I feel like the

Re: [sqlite] Missed index opportunities with sorting?

2019-12-09 Thread Digital Dog
On Sat, Dec 7, 2019 at 3:50 AM Simon Slavin wrote: > On 7 Dec 2019, at 2:26am, Shawn Wagner wrote: > > > The first one uses the index for all sorting, but the second one only > uses it for sorting a, not b. I feel like the descending sort could make > use of the index too, just reading the b

Re: [sqlite] Missed index opportunities with sorting?

2019-12-06 Thread Simon Slavin
On 7 Dec 2019, at 2:26am, Shawn Wagner wrote: > The first one uses the index for all sorting, but the second one only uses it > for sorting a, not b. I feel like the descending sort could make use of the > index too, just reading the b sections backwards to get the right order. Is > there

[sqlite] Missed index opportunities with sorting?

2019-12-06 Thread Shawn Wagner
Consider: sqlite> CREATE TABLE test1(a, b); sqlite> CREATE INDEX test1_idx ON test1(a, b ASC); sqlite> EXPLAIN QUERY PLAN SELECT * FROM test1 ORDER BY a, b; QUERY PLAN `--SCAN TABLE test1 USING COVERING INDEX test1_idx sqlite> EXPLAIN QUERY PLAN SELECT * FROM test1 ORDER BY a, b DESC; QUERY PLAN