Re: 'fake' join and performance ? - Mailing list pgsql-sql

From Tom Lane
Subject Re: 'fake' join and performance ?
Date
Msg-id 24033.1035308365@sss.pgh.pa.us
Whole thread Raw
In response to 'fake' join and performance ?  ("Peter Galbavy" <peter.galbavy@knowtion.net>)
List pgsql-sql
"Peter Galbavy" <peter.galbavy@knowtion.net> writes:
> photos=# select * from metadata m, images i WHERE m.name = 'Make' and
> m.value = 'Canon' limit 10;

> Er, what's that nested loop. I *know* I have shot myself in the foot
> somehow,

Yeah, you didn't restrict the reference to images at all.

> but my initial reaction was that the optimiser should just make the
> 'fake' (i.e. unreferenced) reference to another table go away...

That would be in violation of the SQL spec.  The query is defined to
return each join row from the cross product of the FROM tables that
meets the condition of the WHERE clause.  As you wrote the query, each
metadata row that meets the WHERE clause will be returned exactly as
many times as there are rows in the images table.  There is no such
thing as an "unreferenced" FROM entry as far as SQL is concerned.
        regards, tom lane


pgsql-sql by date:

Previous
From: Stephan Szabo
Date:
Subject: Re: 'fake' join and performance ?
Next
From: "Peter Galbavy"
Date:
Subject: Re: 'fake' join and performance ?