Reputation: 5962
I have a query where I'm trying to find a null field from millions of records. There will only be one or two.
The query looks like this:
SELECT *
FROM “table”
WHERE “id” = $1
AND “end_time” IS NULL
ORDER BY “start_time” DESC LIMIT 1
How can I make this query more performant eg using indexes in the database.
Upvotes: 1
Views: 41
Reputation: 51599
try a partial index, smth like:
create index iname on "table" (id, start_time) where end_time is null;
Upvotes: 1