Paolo Tavalazzi <ptavalazzi@charta.it> writes:
> I have two query that they are different only for order of the tables
> in FROM lclause , but give back different query plan :
Hm, seems like the planner is making wacko estimates in the second case.
You didn't say what data types are involved in this query --- are any of
the join columns int8 or float8 or timestamp? If so you might be
getting bitten by the 7.4 pg_statistic alignment bug. Please follow the
repair procedures suggested in the 7.4.2 release notes:
http://developer.postgresql.org/docs/postgres/release.html#RELEASE-7-4-2
and see if that improves matters.
regards, tom lane