H
H
happyjedi2015-11-23 10:53:45
PostgreSQL
happyjedi, 2015-11-23 10:53:45

Do I need to make an index in the database on the column by which ORDER_BY is sorted?

I have the following regularly executed query:

SELECT "f_attributes".* FROM "f_attributes" WHERE "f_attributes"."type" IN ('FHeatType') AND (visible = 't')  ORDER BY "f_attributes"."title" ASC

I want to add indexing to the database. I'm thinking of making a composite index on the type and visible columns (the order of the columns doesn't seem to matter here). But a question arose, for which he himself did not find explanations, or did not understand the essence of the theory.
Is it necessary (is it useful) to add an index on the title column, on which the ORDER BY is sorted? And should it be a separate index or part of a composite one?
And a question for Rails developers, do I need to manually update the indexes (PostgreSQL database), or does it happen automatically?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
F
Finesse, 2015-11-23
@happyjedi

It's better to make title a separate index

S
Sergey, 2015-11-27
@mastedm

Postgres has an EXPLAIN (ANALYZE) query profiler. You can feed the request to it and see the request execution plan. From it it will be clear whether indexes are used. There are situations when Postgres does not use an existing index, or only one of two indexes is used.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question