Thread: [sql]Joins

[sql]Joins

From
Najm Hashmi
Date:
I am facing a dilemma at my work,   I am using postgres first time. For
some reason, my co-workers think that in Postgres joins i.e.
simple joins of two or three tables are so bad that their cost is
exponential. They believe that postgres simply takes  Cartesian product
of joining table in order to obtain desired tuples i.e. no optimization
is done.      I refused to believe  so. I need your help to convince
them that it is okay to join tables --two or three tables :)-- so we can

eliminate redundancies from the database. I also want to know how
postgres optimizes a join query.  Thank you very much your help.
Regards
Najm



Re: [sql]Joins

From
Stephan Szabo
Date:
On Fri, 10 Nov 2000, Najm Hashmi wrote:

> I am facing a dilemma at my work,   I am using postgres first time. For
> some reason, my co-workers think that in Postgres joins i.e.
> simple joins of two or three tables are so bad that their cost is
> exponential. They believe that postgres simply takes  Cartesian product
> of joining table in order to obtain desired tuples i.e. no optimization
> is done.
>        I refused to believe  so. I need your help to convince
> them that it is okay to join tables --two or three tables :)-- so we can 
> eliminate redundancies from the database. I also want to know how
> postgres optimizes a join query.  Thank you very much your help.

Umm, I don't know where they got that idea.  Tom Lane can go into details 
as the optimizer guru, but as a start, if you use EXPLAIN on your queries,
the system will tell you what plan it would use if you were to run the
query.  That will get you some idea of what the system is doing.

I've had no problems really until about 8-12 tables joined when you might
tickle a bug in some versions of postgres which cause bogus plans to be
generated.



Re: [sql]Joins

From
"Cristóvão B. B. Dalla Costa"
Date:
> I've had no problems really until about 8-12 tables joined when you might
> tickle a bug in some versions of postgres which cause bogus plans to be
> generated.

I've had queries with over 25 joins and self-joins with no problems
whatsoever.