I've a db with three tables.
images = wich contains the info
of the image.( id | filename | width | height | private | ... )
nodes = wich contains the image id and the tag id. ( image_id |
tag_id | private )
tags = wich contains tags. ( id | tag )
The user
can select the images seaching by tags using :
SELECT images.* FROM images INNER JOIN nodes ON images.id = nodes.image_id WHERE tag_id IN (SELECT tags.id FROM tags WHERE tags.tag IN ('tag1','tag2')) GROUP BY images.id HAVING COUNT(*) = 2
The
problem is that i've nearly 50,000 entries on images table, the nodes
table contains 452,299 entries and the tags table contains 4,612
entries.
Now, the problem is that i try to retrieve 5000 images
i've to wait almost 7 minutes to have all results :S
The tables
don't have primary keys, only the tags table, because the data is stored
using the ids of the images downloaded from a website, so i cant set
autoincrements on images table or ser a primary key because the user can
download the images and also add his owns setting if it is private on
tables images and nodes (private as char = "n" or "y")...
So how
can i increase the select speed? Increasing pragma? cache? i'm really
new on sqlite and don't have enough knowledge about it.