Force Postgresql to use an index, how?

Asked

Viewed 452 times

0

There is a way to force Postgresql to use a specific index?

I have two equal tables (different servers, of course), with the same indices created in each one, however, in one server the index is used and in the other not.

I need to get you to take the index, the SELECT It’s simple, there’s only one JOIN but the very large table, accurate this index.

  • 1

    Run an ANALYZE on both machines to update statistics and retest your test.

1 answer

4


Maybe there is nothing wrong, the volume of data in these tables may be responsible for this behavior.

Think so:

Imagine a book with 5000 pages. The best way to find something specific within that book would surely be by using its content.

Now imagine a booklet of just 6 pages. The easiest way to find something inside this booklet would be to flip through it from start to finish, the need for an index is completely unnecessary and could even get in the way.

But if you want to venture into forcing the Postgres to work giving preference to indexes, Voce can do something like:

SET enable_seqscan = OFF;
  • @L.Gustavo: Add more details to your question and I’ll add the answer.

  • I created the indexes one day, the next day the bank started using.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.