krishna
krishna

Reputation: 31

How to go directly into a row in sqlite

I have a huge sqlite database with 800,000 rows and it takes a long time if the row is near the end like select * from tbl where id=578511. This is because the query runs from the beginning of the database, but is it possible to go just directly to that row as the id equals the rowcount.

Upvotes: 1

Views: 42

Answers (2)

lqhcpsgbl
lqhcpsgbl

Reputation: 3782

Maybe you can try to add the index of the table to make the query faster:

 CREATE INDEX tbl_id ON tbl(id);

or if the data is frequently read, you can also keep them in memory.

Upvotes: 1

user1561346
user1561346

Reputation: 502

Make id a primary key. It should help.

Upvotes: 2

Related Questions