[sqlite] How to get ORDER BY / LIMIT to stick to the fast-path?

2018-03-22 Thread Jonathan Moules
Hi List, The below query takes just 0.002 seconds to run (sqlite 3.15.0 and 3.23.0 (preview)) despite looking through hundreds of thousands of records in each table, and it returns 86 records in all. This is great! But when I stick an "ORDER BY" on the end (either ASC or DESC), the processin

Re: [sqlite] How to get ORDER BY / LIMIT to stick to the fast-path?

2018-03-22 Thread Simon Slavin
On 22 Mar 2018, at 9:24pm, Jonathan Moules wrote: > But when I stick an "ORDER BY" on the end (either ASC or DESC), the > processing time shoots up to 0.15s. The EXPLAIN between the two is > considerably different so it seems the ORDER BY is getting it to use a > sub-optimal query plan. Hi, J

Re: [sqlite] How to get ORDER BY / LIMIT to stick to the fast-path?

2018-03-22 Thread Richard Hipp
Quick workaround: put a "+" on front of the first term of your ORDER BY clause. On Thursday, March 22, 2018, Jonathan Moules wrote: > Hi List, > > The below query takes just 0.002 seconds to run (sqlite 3.15.0 and 3.23.0 (preview)) despite looking through hundreds of thousands of records in each

Re: [sqlite] How to get ORDER BY / LIMIT to stick to the fast-path?

2018-03-22 Thread Jonathan Moules
Hi Simon, Sure; I didn't include them because the only difference is the last line, and that just seems to be the standard "ordering" line. I figured the explain was more useful as a lot has changed in that. Cheers, Jonathan Fast version: 100SEARCH TABLE lookups USING COVERING IND

Re: [sqlite] How to get ORDER BY / LIMIT to stick to the fast-path?

2018-03-22 Thread Simon Slavin
On 22 Mar 2018, at 10:09pm, Jonathan Moules wrote: > Sure; I didn't include them because the only difference is the last line, and > that just seems to be the standard "ordering" line. I figured the explain was > more useful as a lot has changed in that. I find EXPLAIN QUERY PLANs easier to r

Re: [sqlite] How to get ORDER BY / LIMIT to stick to the fast-path?

2018-03-22 Thread Mark Wagner
When I saw this post I just assumed there wasn't a sufficient index to handle the select and the order by. Curious about the suggestion of adding + to the order by first term. On Thu, Mar 22, 2018 at 3:14 PM Simon Slavin wrote: > On 22 Mar 2018, at 10:09pm, Jonathan Moules > wrote: > > > Sure

Re: [sqlite] How to get ORDER BY / LIMIT to stick to the fast-path?

2018-03-22 Thread Simon Slavin
On 22 Mar 2018, at 10:16pm, Mark Wagner wrote: > Curious about the suggestion of adding + to the order by first term. This stops SQLite from realising it can use an existing index. If you do CREATE INDEX m_s ON members (score) SELECT * FROM members ORDER BY score DESC SQLite cleverly

Re: [sqlite] How to get ORDER BY / LIMIT to stick to the fast-path?

2018-03-22 Thread Jonathan Moules
On 2018-03-22 22:08, Richard Hipp wrote: Quick workaround: put a "+" on front of the first term of your ORDER BY clause. This gives me an ending of: ORDER BY +u.url_id ASC LIMIT 1; Alas it makes no difference to the speed. The sole difference in the EXPLAIN plan when that's added from the

Re: [sqlite] How to get ORDER BY / LIMIT to stick to the fast-path?

2018-03-22 Thread Jonathan Moules
Hi Simon, Yep, I too find the Query Plan's easier to read (sometimes I even think I understand bits of them!) I do expect SQLite to get slower with an Order By - it has more work to do after all, but I thought I'd ask for this one because it's slowing down by almost two orders of magnitude (a

Re: [sqlite] How to get ORDER BY / LIMIT to stick to the fast-path?

2018-03-22 Thread Rowan Worth
On 23 March 2018 at 05:24, Jonathan Moules wrote: > Hi List, > > The below query takes just 0.002 seconds to run (sqlite 3.15.0 and 3.23.0 > (preview)) despite looking through hundreds of thousands of records in each > table, and it returns 86 records in all. This is great! > > But when I stick a