I have a table with ~35M rows, and trying to find "processed" records to remove from time to time. There are 14 valid statuses, and 10 of them are processed.
id uuid default uuid_generate_v4() not null primary key,
fk_id uuid not null references fk_table,
-- ... other columns
created_date timestamptz default now() not null,
status varchar(128) not null
Values for status can be one of a,b,c,d,e,f,g,h,i,j,k,l,m,n (14)
The index is on (status,created_date).
A query like:
select id from table
where created_date < 'somedate'
and status = ANY('{a,b,c,d,e,f,g,h,i,j}') -- one of first 10 values
The query planner insists on using a full seq_scan, instead of the index.
Is there a trick to make Postgres use the index for the status = ANY part of the predicate?
explain(analyze, verbose, buffers, settingsand the complete DDL for all tables and indexes involved? All in plain text, as an update of the original question.IN ( … )syntax?