database - Android SQLite fast Date between search -


i have huge performance issue when comes sqlite query date ranges.

in application have database couple of thousands of records of sites. these sites visitable not whole year. each of sites can define 3 ranges in is visitable. therefore created sqlite table following columns: open1, close1, open2, close2, open3 , close3 (amongst others)

application users can enter time range in want visit site, e.g. 2014.01.01 - 2014.01.07

now when perform search without restricting time pretty fast. when use opening time search criteria, search takes 7 seconds on fast emulator. not want test on real device :)

the entries in columns open , close of type datetime , like: 2014-01-01

my current query follows:

    select open1,close1,open2,close2,open3,close3 sites (       ( ( strftime('%y-%m-%d', '2014-01-01') between open1 , close1 ) , ( strftime('%y-%m-%d', '2014-01-07') between open1 , close1 ) )       or       ( ( strftime('%y-%m-%d', '2014-01-01') between open2 , close2 ) , ( strftime('%y-%m-%d', '2014-01-07') between open2 , close2 ) )       or       ( ( strftime('%y-%m-%d', '2014-01-01') between open3 , close3 ) , ( strftime('%y-%m-%d', '2014-01-07') between open3 , close3 ) )     ) 

is there simple way improve performance?

notice: tried using utc values in long format open , close not debuggable.

thanks in advance help!

i not sure if more efficient can not hurt simplify query :

( ( strftime('%y-%m-%d', '2014-01-01') between open1 , close1 ) , ( strftime('%y-%m-%d', '2014-01-07') between open1 , close1 ) ) 

is equivalent :

( strftime('%y-%m-%d', '2014-01-01') >= open1 , strftime('%y-%m-%d', '2014-01-07') <= close1 ) 

as long first date ('2014-01-01' in case) before second ('2014-01-07'), i.e. have :

open* <= first <= second <= close*


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -