[sqlite] Possible substr() optimization?

2015-07-23 Thread R.Smith
On 2015-07-23 04:56 PM, Igor Tandetnik wrote: > On 7/23/2015 10:47 AM, Bernardo Sulzbach wrote: >>> select * from tbl1 where substr(col1,1,1) in ('A','a') and col1 like >>> 'a_c%'; >> >> Just adding to Igor's answer: >> col1 between 'a' and 'b' or col1 between 'A' and 'B' > > That's not quite

[sqlite] Possible substr() optimization?

2015-07-23 Thread Staffan Tylen
Since Igor's response I've been studying "The SQLite Query Planner" with great interest. Staffan On Thu, Jul 23, 2015 at 4:59 PM, Bernardo Sulzbach < mafagafogigante at gmail.com> wrote: > > That's not quite the same. BETWEEN is inclusive of both ends. ('b' > BETWEEN 'a' and 'b') is true. > >

[sqlite] Possible substr() optimization?

2015-07-23 Thread Staffan Tylen
Thanks, I wasn't aware. On Thu, Jul 23, 2015 at 4:21 PM, Igor Tandetnik wrote: > On 7/23/2015 10:17 AM, Staffan Tylen wrote: > >> Please consider this: >> >> create table tbl1 (col1 text primary key); >> insert ... >> select * from tbl1 where substr(col1,1,1)='a'; >> > > Make it > > WHERE

[sqlite] Possible substr() optimization?

2015-07-23 Thread Staffan Tylen
Please consider this: create table tbl1 (col1 text primary key); insert ... select * from tbl1 where substr(col1,1,1)='a'; select * from tbl1 where col1='a'; According to explain (I'm on 3.8.6), the first select above causes a scan of the entire table, while the second select uses the index. My

[sqlite] Possible substr() optimization?

2015-07-23 Thread Bernardo Sulzbach
> That's not quite the same. BETWEEN is inclusive of both ends. ('b' BETWEEN > 'a' and 'b') is true. Yes, you are right. I'm sorry for that, just wanted to point out that (as most would expect) .. >= 'a' and .. < 'b' would not match uppercase beginnings.

[sqlite] Possible substr() optimization?

2015-07-23 Thread Bernardo Sulzbach
> select * from tbl1 where substr(col1,1,1) in ('A','a') and col1 like 'a_c%'; Just adding to Igor's answer: col1 between 'a' and 'b' or col1 between 'A' and 'B' if you need this case sensitive behavior

[sqlite] Possible substr() optimization?

2015-07-23 Thread Igor Tandetnik
On 7/23/2015 10:47 AM, Bernardo Sulzbach wrote: >> select * from tbl1 where substr(col1,1,1) in ('A','a') and col1 like 'a_c%'; > > Just adding to Igor's answer: > col1 between 'a' and 'b' or col1 between 'A' and 'B' That's not quite the same. BETWEEN is inclusive of both ends. ('b' BETWEEN

[sqlite] Possible substr() optimization?

2015-07-23 Thread p...@arbolone.ca
: Bernardo Sulzbach Sent: Thursday, July 23, 2015 10:47 AM To: General Discussion of SQLite Database Subject: Re: [sqlite] Possible substr() optimization? > select * from tbl1 where substr(col1,1,1) in ('A','a') and col1 like > 'a_c%'; Just adding to Igor's answer: col1 between 'a' and 'b' o

[sqlite] Possible substr() optimization?

2015-07-23 Thread Igor Tandetnik
On 7/23/2015 10:17 AM, Staffan Tylen wrote: > Please consider this: > > create table tbl1 (col1 text primary key); > insert ... > select * from tbl1 where substr(col1,1,1)='a'; Make it WHERE col1>='a' and col1 < 'b' This should use the index. -- Igor Tandetnik