X-Original-To: pgsql-performance-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 3A0199DC8D9 for ; Sat, 17 Dec 2005 14:13:51 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 24841-01 for ; Sat, 17 Dec 2005 14:13:50 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id C38489DC88F for ; Sat, 17 Dec 2005 14:13:48 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id jBHIDgxJ008628; Sat, 17 Dec 2005 13:13:42 -0500 (EST) To: Simon Riggs cc: Bruce Momjian , =?ISO-8859-1?Q?P=E5l?= Stenslet , pgsql-performance@postgresql.org Subject: Re: Should Oracle outperform PostgreSQL on a complex In-reply-to: <1134810953.2964.117.camel@localhost.localdomain> References: <200512170428.jBH4S2W23715@candle.pha.pa.us> <1134810953.2964.117.camel@localhost.localdomain> Comments: In-reply-to Simon Riggs message dated "Sat, 17 Dec 2005 09:15:53 +0000" Date: Sat, 17 Dec 2005 13:13:42 -0500 Message-ID: <8627.1134843222@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.013 required=5 tests=[AWL=0.013] X-Spam-Score: 0.013 X-Spam-Level: X-Archive-Number: 200512/427 X-Sequence-Number: 16248 Simon Riggs writes: > On Fri, 2005-12-16 at 23:28 -0500, Bruce Momjian wrote: >> How are star joins different from what we do now? > Methods: > 1. join all N small tables together in a cartesian product, then join to > main Large table once (rather than N times) Of course, the reason the current planner does not think of this is that it does not consider clauseless joins unless there is no alternative. However, I submit that it wouldn't pick such a plan anyway, and should not, because the idea is utterly stupid. The plan you currently get for this sort of scenario is typically a nest of hash joins: QUERY PLAN ------------------------------------------------------------------------ Hash Join (cost=2.25..4652.25 rows=102400 width=16) Hash Cond: ("outer".f1 = "inner".f1) -> Hash Join (cost=1.12..3115.12 rows=102400 width=12) Hash Cond: ("outer".f2 = "inner".f1) -> Seq Scan on fact (cost=0.00..1578.00 rows=102400 width=8) -> Hash (cost=1.10..1.10 rows=10 width=4) -> Seq Scan on d2 (cost=0.00..1.10 rows=10 width=4) -> Hash (cost=1.10..1.10 rows=10 width=4) -> Seq Scan on d1 (cost=0.00..1.10 rows=10 width=4) (9 rows) This involves only one scan of the fact table. As each row is pulled up through the nest of hash joins, we hash one dimension key and join to one small table at each level. This is at worst the same amount of work as hashing all the keys at once and probing a single cartesian-product hashtable, probably less work (fewer wasted key-comparisons). And definitely less memory. You do have to keep your eye on the ball that you don't waste a lot of overhead propagating the row up through multiple join levels, but we got rid of most of the problem there in 8.1 via the introduction of "virtual tuple slots". If this isn't fast enough yet, it'd make more sense to invest effort in further cutting the executor's join overhead (which of course benefits *all* plan types) than in trying to make the planner choose a star join. > 2. transform joins into subselects, then return subselect rows via an > index bitmap. Joins are performed via a bitmap addition process. This one might be interesting but it's not clear what you are talking about. "Bitmap addition"? regards, tom lane