The question is really about optimization of sql queries. Let us say we have the table so defined.
CREATE TYPE record_type AS ENUM (
'TRANSFER',
'TRADE',
'VOUCHER'
);
CREATE TYPE record_status AS ENUM (
'NEW',
'VALIDATED',
'EXPIRED'
);
CREATE TABLE good_records (
id uuid PRIMARY KEY,
user_id uuid NOT NULL,
type record_type NOT NULL,
status record_status NOT NULL,
amount numeric(36,18) NOT NULL DEFAULT 0,
expired_at timestamp WITH TIME ZONE NOT NULL,
notification_sent boolean DEFAULT false,
);
I want to run an expiration check every 10 min, namely, I would run SELECT * FROM good_records
where record_status = 'NEW' and notification_sent = false
(and SELECT * FROM good_records where record_status = 'VALIDATED' and notification_sent = false
). But as I monitor the db resources usage, it comes with no surprise that that two queries costs a lot.
My question is whether it is possible to put indexing on the table somehow so that I can fasten the queries and save db resources.
I have briefly read the postgresql docs but with no good solution.