How to determine the best database indexes in Rails?

In Rails, I try to create database indexes that speed up my queries, but I often find that after migrating my database to create new ones, it still does not use the indexes that I create (even though they seem ideal for a particular query) .

Is there a tool in Rails that can search for a system and identify specific indexes that need to be created for optimal performance?

If not, are there any specific rules that determine why my database does not use my lovingly created indexes?

Essentially, my question is: how can I avoid my current process, which: 1) start the migration by creating a bunch of possible indexes, 2) find out that they do not work, 3) rollback and the feeling of a little more frustrated in my database is obvious myopia ?

+3
source share
3 answers

Well, if all your queries are in the form of SELECT * FROM , indexes are probably not going to be used. First configure the queries so that you return only the data needed for each view, and then create the index.

In addition, you can run EXPLAIN in the database for each request, which will be much more illuminating than any gem / plugin offered by the Ruby community.

+1
source

? , , , , ..... postgres pgfouine. mysql , . , , ..

?

0

All Articles