[GENERAL] JOIN issues (Left vs Right for sorting), and Nested Loop problem

2007-09-01 Thread Phoenix Kiula
Hello, I have a simple query as follows. It joins two very straightforward tables. SELECT trades.id, trades.url, trades.alias, tradecount.t_count, tradecount.u_count FROM trades LEFT JOIN tradecount ON trades.id = tradecount.id WHERE trades.user_id = 'jondoe' and trades.status = 'Y'

Re: [GENERAL] JOIN issues (Left vs Right for sorting), and Nested Loop problem

2007-09-01 Thread Alban Hertroys
On Sep 1, 2007, at 11:46, Phoenix Kiula wrote: Hello, I have a simple query as follows. It joins two very straightforward tables. SELECT trades.id, trades.url, trades.alias, tradecount.t_count, tradecount.u_count FROM trades LEFT JOIN tradecount ON trades.id = tradecount.id

Re: [GENERAL] JOIN issues (Left vs Right for sorting), and Nested Loop problem

2007-09-01 Thread Phoenix Kiula
On 01/09/07, Alban Hertroys [EMAIL PROTECTED] wrote: On Sep 1, 2007, at 11:46, Phoenix Kiula wrote: . ..snip However, there's a nested loop in there as the EXPLAIN ANALYZE shows below. What is causing this nested loop? It looks like it's used to match trades to tradecounts. I think

Re: [GENERAL] JOIN issues (Left vs Right for sorting), and Nested Loop problem

2007-09-01 Thread Alban Hertroys
On Sep 1, 2007, at 14:48, Phoenix Kiula wrote: On 01/09/07, Alban Hertroys [EMAIL PROTECTED] wrote: On Sep 1, 2007, at 11:46, Phoenix Kiula wrote: . ..snip However, there's a nested loop in there as the EXPLAIN ANALYZE shows below. What is causing this nested loop? It looks like

Re: [GENERAL] JOIN issues (Left vs Right for sorting), and Nested Loop problem

2007-09-01 Thread Tom Lane
Phoenix Kiula [EMAIL PROTECTED] writes: On 01/09/07, Alban Hertroys [EMAIL PROTECTED] wrote: Is 10 ms problematic for this query? I think you got 10ms from the query plan? These queries are very fast after they have been executed once. But the first time is huge. Sometimes I have to wait as

Re: [GENERAL] JOIN issues (Left vs Right for sorting), and Nested Loop problem

2007-09-01 Thread Tom Lane
Alban Hertroys [EMAIL PROTECTED] writes: I am kind of surprised that the planner doesn't understand that a foreign key with a unique constraint (which a primary key is) means there is a 0..1 to 1 relationship with the target table. Hm? It correctly estimated that it'd get one row out for