dimanche 4 janvier 2015

SQLite sqlite3_step() hangs with big database

I'm writing a small Objective-C library that works with an embedded SQLite database.


The SQLite version I'm using is 3.7.13 (checked with SELECT sqlite_version())


My query is:



SELECT ROUND(AVG(difference), 5) as distance
FROM (
SELECT (
SELECT A.timestamp - B.timestamp
FROM ExampleTable as B
WHERE B.timestamp = (
SELECT MAX(timestamp)
FROM ExampleTable as C
WHERE C.timestamp < A.timestamp
)
) as difference
FROM ExampleTable as A
ORDER BY timestamp)


Basically it outputs the average timestamp difference between rows ordered by timestamp.


I tried the query on a sample database with 35k rows and it runs in around 100ms. So far so good.


I then tried the query on another sample database with 100k rows and it hangs at sqlite3_step() taking up 100% of CPU usage.


Since I cannot step into sqlite3_step() with the debugger, is there another way I can get a grasp of where is the function hanging or a debug log of what is the issue here?


I also tried running other queries from my library on the 100k rows database and there is no issue, but it's also true that these are simple queries with no subquery. Maybe this is the issue?


Thanks


Aucun commentaire:

Enregistrer un commentaire