Answer the question
In order to leave comments, you need to log in
PostgreSQL, how to speed up checking if a column has a unique value?
There is a simple table:
CREATE TABLE public.notices (
id TEXT NOT NULL,
json TEXT,
CONSTRAINT notices_idx PRIMARY KEY(id)
)
WITH (oids = false);
select * from notices where id = '123' limit 1);
select exists(select 1 from notices where id = '123');
(SELECT id FROM notices WHERE id='123' LIMIT 1) UNION ALL (SELECT id FROM notices WHERE id='234' LIMIT 1) UNION ALL ...
Answer the question
In order to leave comments, you need to log in
There is an index for the id field, is it the primary key?
3 check - in my horror. Better like this:
SELECT id FROM notices WHERE id='123' OR id='234'...
You actually have access by key, store in key-value storage simply, for example in Redis.
Probably in most cases the objects are already there, so what's the best way to get the missing ones?
select "id" from "notices" where "id" not in ('1', '2', ...)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question