1

three is date column, oscar_alpha is integer.

I have this result from Postgres explain. On 16 row I want to prevent acces to table to find in filter condition

Filter: ((three >= '15.04.2010 00:00'::date) AND (three <= '15.04.2016 00:00'::date) AND (oscar_alpha = 341)).

And I want to check this condition via indexes. I created indexes:

create index index1 on table_name (three , oscar_alpha);
create index index2 on table_name (three);
create index index3 on table_name (oscar_alpha);

But they are not using.

Yes, some data anonymised.

1 Answer 1

1

You need to create a composite index on (oscar_alpha, three), in that order.

An index is sorted in lexicographic order, first on the value of the first column, then, that being equal, on the second etc, like a phonebook: surnames first, then names.

It's easy to get all Smiths from John to Mary from a phonebook, but not that easy to get all Johns from Jones to Smith, because the entries are ordered on surname first.

Same with your query: if you order on oscar_alpha first, all values with the same oscar_alpha go in three order, and it's possible to apply a range condition to them.

Sign up to request clarification or add additional context in comments.

3 Comments

I added a composite index on (oscar_alpha, three), but it`s not workiing
@Usm: oh I see. You want a composite index on quebec_seven, oscar_alpha, three.
@Usm: unfortunately, there's not much I can do without seeing the data and the query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.