A
A
Artem00712021-07-28 12:17:56
PostgreSQL
Artem0071, 2021-07-28 12:17:56

How to create indexes correctly?

Good afternoon
There is a large table on which frequent sampling should be made

Table structure:
id, parent_id, custom_name, released_at, ....

And the query:
select *
from cards
where ("parent_id" is null or "custom_name" is not null or " released_at" > now()) and ...

Did explain as requested and there:

->  Seq Scan on cards  (cost=0.00..233142.26 rows=325284 width=8)
            Filter: ((parent_id IS NULL) OR (custom_lang IS NOT NULL) OR (released_at > now()))


I made indexes for these fields - I found out that they do not work with null
I also made a composite index cards(parent_id, custom_lang, released_at) - it became a little faster, but explain has not changed, the same Filter in Seq Scan

has also been made cards(parent_id, custom_lang, released_at) where parent_id is null and custom_lang is not null - a little faster, but still not enough. Still the same Filter in Seq Scan

How can I optimize the query somehow?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question