Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to implement a functionality that is in line with the GEQO functionality of PostgreSQL. I understand that GEQO approach is to encode query plans as integer strings and GEQO generates these possible join sequences at random. Source :

My question: how to modify the GEQO function if I definitively know the right join sequence, so that I don't have to search different join sequences. For ex., if I knew that the best way of joining the 4 relations is 4-1-3-2, I needn't have to check for other permutations.

There aren't any good materials on how GEQO is implemented in PostgreSQL. PostgreSQL only gives the overall view of the GEQO functionality but doesn't explain much.

Or could I achieve this functionality in the standard_join_search() itself without using GEQO?

share|improve this question
It sounds like you want to implement query hints. That's all well and good, but you shouldn't expect to get the change accepted in PostgreSQL core because the project community isn't what you'd call a big fan of query hints. If you're serious about this, you'll need to read quite a bit of the query planner code and you'll need to figure out how to pass your hints from the parser down through the rewriter and into the planner. I don't see a quick and simple answer here. What you want to eventually do is force a particular path choice in the planner/optimizer. – Craig Ringer May 2 '14 at 0:20
Ah, yes they are skeptical about query hints. I have done the reading of the planner code and it seemed GEQO would be a way to minimize the changes to the existing core. – user2761431 May 2 '14 at 9:46
Is that what you are trying to achieve, to implement query hints to force join ordering? If so, look into whether anyone else has already implemented it. You should also consider why you need it, why the planner is making the wrong choices in the first place. Consider producing a self-contained test case and reporting to pgsql-performance. – Craig Ringer May 2 '14 at 11:36
There is pg_hint_plan: , but i didn't use it. One dba told me that it was working on 9.2. There is also article in russian about it – ckorzhik Jul 17 '14 at 20:25

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.