X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 52C0A52849 for ; Wed, 8 Jun 2005 15:46:57 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 17036-02 for ; Wed, 8 Jun 2005 18:46:53 +0000 (GMT) Received: from mailgw.dmi.dk (mailgw.dmi.dk [130.226.71.185]) by svr1.postgresql.org (Postfix) with ESMTP id EF88F52834 for ; Wed, 8 Jun 2005 15:46:51 -0300 (ADT) Received: from localhost (localhost.dmi.dk [127.0.0.1]) by mailgw.dmi.dk (8.12.11/8.12.11/Debian-1) with ESMTP id j58IkpWZ015206; Wed, 8 Jun 2005 18:46:51 GMT Received: from mailgw.dmi.dk ([127.0.0.1]) by localhost (mailgw.dmi.dk [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 15130-04; Wed, 8 Jun 2005 18:46:40 +0000 (GMT) Received: from postoffice.dmi.dk (postoffice.dmi.dk [130.226.64.60]) by mailgw.dmi.dk (8.12.11/8.12.11/Debian-1) with ESMTP id j58IkaJu015183; Wed, 8 Jun 2005 18:46:36 GMT Received: from localhost (localhost.dmi.dk [127.0.0.1]) by postoffice.dmi.dk (Postfix) with ESMTP id 3B77218055; Wed, 8 Jun 2005 18:46:36 +0000 (GMT) Received: from postoffice.dmi.dk ([127.0.0.1]) by localhost (postoffice.dmi.dk [127.0.0.1]) (amavisd-new, port 10024) with LMTP id 17243-01-4; Wed, 8 Jun 2005 18:46:36 +0000 (GMT) Received: from localhost (webmail [130.226.71.186]) by postoffice.dmi.dk (Postfix) with ESMTP id DC5D118052; Wed, 8 Jun 2005 18:46:35 +0000 (GMT) Received: from port161.ds1-aroe.adsl.cybercity.dk (port161.ds1-aroe.adsl.cybercity.dk [217.157.138.230]) by webmail.dmi.dk (IMP) with HTTP for ; Wed, 8 Jun 2005 20:46:35 +0200 Message-ID: <1118256395.42a73d0bca492@webmail.dmi.dk> Date: Wed, 8 Jun 2005 20:46:35 +0200 From: Kim Bisgaard To: Tom Lane Cc: pgsql-performance@postgresql.org Subject: Re: full outer performance problem References: <42A6BC64.4010001@dmi.dk> <1275.1118239415@sss.pgh.pa.us> In-Reply-To: <1275.1118239415@sss.pgh.pa.us> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit User-Agent: Internet Messaging Program (IMP) 3.2.6 X-Originating-IP: 217.157.138.230 X-Virus-Scanned: by amavisd-new-20030616-p10 (Debian) at dmi.dk X-Virus-Scanned: by amavisd-maia-1.0.0-rc5 (Debian) at dmi.dk X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests= X-Spam-Level: X-Archive-Number: 200506/183 X-Sequence-Number: 12820 Quoting Tom Lane : > Kim Bisgaard writes: > > SELECT station_id, timeobs,temp_grass, temp_dry_at_2m > > FROM temp_dry_at_2m a > > FULL OUTER JOIN temp_grass b > > USING (station_id, timeobs) > > WHERE station_id = 52981 > > AND timeobs = '2004-1-1 0:0:0' > > > explain analyse SELECT b.station_id, b.timeobs,temp_grass, temp_dry_at_2m > > FROM temp_dry_at_2m a > > FULL OUTER JOIN temp_grass b > > USING (station_id, timeobs) > > WHERE b.station_id = 52981 > > AND b.timeobs = '2004-1-1 0:0:0' > > > Why will PostgreSQL not use the same plan for both these queries - they > > are virtually identical?? > > Because they're semantically completely different. The second query is > effectively a RIGHT JOIN, because join rows in which b is all-null will > be thrown away by the WHERE. The optimizer sees this (note your second > plan doesn't use a Full Join step anywhere) and is able to produce a > much better plan. Full outer join is difficult to optimize, in part > because we have no choice but to use a merge join for it --- the other > join types don't support full join. > > regards, tom lane > Yes I am aware that they are not "identical", they also give different results, but the data nessesary to compute the results is (0-2 rows, 0-1 row from each table), and thus ideally have the potential to have similar performance - to my head anyway, but I may not have grasped the complete picture yet :-) Regards, Kim.