Re: [HACKERS] Eliminating unnecessary left joins

2007-04-21 Thread Ottó Havasvölgyi
But then what about the null values? Perhaps unique + notnull is better? Otto 2007/4/20, Nicolas Barbier <[EMAIL PROTECTED]>: 2007/4/16, Ottó Havasvölgyi <[EMAIL PROTECTED]>: > Eliminate the table T from the query/subquery if the following requirements > are satisfied: > 1. T is left joined

Re: [HACKERS] Eliminating unnecessary left joins

2007-04-20 Thread Nicolas Barbier
2007/4/16, Ottó Havasvölgyi <[EMAIL PROTECTED]>: Eliminate the table T from the query/subquery if the following requirements are satisfied: 1. T is left joined 2. T is referenced only in the join expression where it is left joined 3. the left join's join expression is a simple equality expressio

Re: [HACKERS] Eliminating unnecessary left joins

2007-04-16 Thread Ottó Havasvölgyi
Hi, Could you Bruce please add a TODO item for this feature? The description could look something like this: Eliminate the table T from the query/subquery if the following requirements are satisfied: 1. T is left joined 2. T is referenced only in the join expression where it is left joined 3. th

Re: [HACKERS] Eliminating unnecessary left joins

2007-04-13 Thread Zeugswetter Andreas ADI SD
> I have this exact problem a lot. There are actually cases > where you can eliminate regular joins, not just left joins. > For example: > > CREATE TABLE partner ( > id serial, > namevarchar(40) not null, > primary key (id) > ); > >

Re: [HACKERS] Eliminating unnecessary left joins

2007-04-12 Thread Robert Haas
I have this exact problem a lot. There are actually cases where you can eliminate regular joins, not just left joins. For example: CREATE TABLE partner ( id serial, namevarchar(40) not null, primary key (id) ); CREATE TABLE projec

Re: [HACKERS] Eliminating unnecessary left joins

2007-04-12 Thread Stephan Szabo
On Wed, 11 Apr 2007, Jim Nasby wrote: > I agree with others that the way that query is constructed is a bit > odd, but it does bring another optimization to mind: when doing an > inner-join between a parent and child table when RI is defined > between them, if the query only refers to the child ta

Re: [HACKERS] Eliminating unnecessary left joins

2007-04-12 Thread Zeugswetter Andreas ADI SD
> Maybe odd, but simpler to optimize this way. > > Your idea would be also a very good optimization, there was > already a discussion about that here: > http://archives.postgresql.org/pgsql-performance/2006-01/msg00 > 151.php, but that time Tom refused it because it was too > expensive and rare

Re: [HACKERS] Eliminating unnecessary left joins

2007-04-12 Thread Ottó Havasvölgyi
Jim, Maybe odd, but simpler to optimize this way. Your idea would be also a very good optimization, there was already a discussion about that here: http://archives.postgresql.org/pgsql-performance/2006-01/msg00151.php, but that time Tom refused it because it was too expensive and rare. Maybe now

Re: [HACKERS] Eliminating unnecessary left joins

2007-04-11 Thread Jim Nasby
I agree with others that the way that query is constructed is a bit odd, but it does bring another optimization to mind: when doing an inner-join between a parent and child table when RI is defined between them, if the query only refers to the child table you can drop the parent table from

Re: [HACKERS] Eliminating unnecessary left joins

2007-04-08 Thread Ottó Havasvölgyi
My mapper joins the parent classes' tables to the current class' table in the view. In the ShapeView only ID, X, and Y is selected from the shape table, and none of the child tables are touched, opposite to your sample. But even though all Shape objects (circles and rectangles too) are in the resu

Re: [HACKERS] Eliminating unnecessary left joins

2007-04-08 Thread Nicolas Barbier
2007/4/7, Ottó Havasvölgyi <[EMAIL PROTECTED]>: My simple example: Class hierarchy and fields: Shape (ID, X, Y) | +-Circle (ID, Radius) | +-Rectangle (ID, Width, Height) The mapper creates 3 tables with the columns next to the class name. And it creates 3 views. One of them: RectangleView: S

Re: [HACKERS] Eliminating unnecessary left joins

2007-04-07 Thread Ottó Havasvölgyi
Sorry, I have left out the PK requirement. What Nicolas wrote is right, I also use an O/R mapper and inheritance is solved with vertical partitioning. The tables are connected to each other with the PK. And the mapper defines views for each class with left joins. The mapper generates queries based

Re: [HACKERS] Eliminating unnecessary left joins

2007-04-07 Thread Nicolas Barbier
2007/4/7, Andreas Pflug <[EMAIL PROTECTED]>: Tom Lane wrote: "=?ISO-8859-1?Q?Ott=F3_Havasv=F6lgyi?=" <[EMAIL PROTECTED]> writes: When using views built with left joins, and then querying against these views, there are a lot of join in the plan that are not necessary, because I don't select/u

Re: [HACKERS] Eliminating unnecessary left joins

2007-04-07 Thread Simon Riggs
On Fri, 2007-04-06 at 19:38 -0400, Tom Lane wrote: > "=?ISO-8859-1?Q?Ott=F3_Havasv=F6lgyi?=" <[EMAIL PROTECTED]> writes: > > When using views built with left joins, and then querying against these > > views, there are a lot of join in the plan that are not necessary, because I > > don't select/use

Re: [HACKERS] Eliminating unnecessary left joins

2007-04-06 Thread Andreas Pflug
Tom Lane wrote: > "=?ISO-8859-1?Q?Ott=F3_Havasv=F6lgyi?=" <[EMAIL PROTECTED]> writes: > >> When using views built with left joins, and then querying against these >> views, there are a lot of join in the plan that are not necessary, because I >> don't select/use any column of each table in the v

Re: [HACKERS] Eliminating unnecessary left joins

2007-04-06 Thread Tom Lane
"=?ISO-8859-1?Q?Ott=F3_Havasv=F6lgyi?=" <[EMAIL PROTECTED]> writes: > When using views built with left joins, and then querying against these > views, there are a lot of join in the plan that are not necessary, because I > don't select/use any column of each table in the views every time. Tables >