Abhinav Moudgil
Abhinav Moudgil

Reputation: 25

SQL table with lot of records how to select row with where clause against a string

I have a SQL table with millions of records. I'm saving device tokens in this table. When I run a select query against this table and device token column which is string like 1d3b9b5ecd9dd9ddd4539555cee58395ggeeec61d42986ajjwd5394ddc34216cf84e898390dfdf19

It consumes lot of memory and CPU. Is there any efficient way of doing this?

Upvotes: 0

Views: 112

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1269693

It sounds like you have a query like this:

SELECT T.*
FROM TABLEWITHMILLIONSOFRECORDS T
WHERE DEVICETOKEN = '1d3b9b5ecd9dd9ddd4539555cee58395ggeeec61d42986ajjwd5394ddc34216cf84e898390dfdf19'; 

If so, you can improve performance by building an index on the devicetoken field:

CREATE INDEX IDX_TABLEWITHMILLIONSOFRECORDS_DEVICETOKEN 
    ON TABLEWITHMILLIONSOFRECORDS(DEVICETOKEN);

This should speed your query.

Upvotes: 3

Related Questions