I am creating a table where I will have a large volume of data and the search will always be based on a date, or a date + an ID. I want to create an index to support the queries, but I have no idea how to create this index for date.
My query:
create table if not exists example_table (
id serial primary key,
original_created_at timestamp with time zone not null default now(),
external_id text not null,
category text NOT NULL,
user_id uuid not null,
data jsonb not null default '{}'::jsonb,
constraint external_id_uq unique (external_id)
);
Example:
Most of the searches will be for the original_created_at
or original_created_at
+ user_id
field. I want to optimize performance for the search to only get values from that date.
create index
syntax? Something else?bigserial
would be much better choice thanserial
. Max int is not really big - just a bit greater than 2 billions , and you can reach it relatively quickly.