X-Original-To: pgsql-hackers-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id BF4089DCAEE for ; Tue, 28 Feb 2006 13:05:50 -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 62575-10 for ; Tue, 28 Feb 2006 13:05:49 -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 985A19DCA62 for ; Tue, 28 Feb 2006 13:05: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 k1SH5mkd016077; Tue, 28 Feb 2006 12:05:48 -0500 (EST) To: "Jim C. Nasby" cc: Kevin Grittner , pgsql-hackers@postgresql.org, pgsql-performance@postgresql.org Subject: Re: [PERFORM] temporary indexes In-reply-to: <20060228164515.GS82012@pervasive.com> References: <44041B68.EE98.0025.0@wicourts.gov> <20060228164515.GS82012@pervasive.com> Comments: In-reply-to "Jim C. Nasby" message dated "Tue, 28 Feb 2006 10:45:15 -0600" Date: Tue, 28 Feb 2006 12:05:48 -0500 Message-ID: <16076.1141146348@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.111 required=5 tests=[AWL=0.111] X-Spam-Score: 0.111 X-Spam-Level: X-Archive-Number: 200602/1212 X-Sequence-Number: 80350 "Jim C. Nasby" writes: > FWIW, Sybase supported something similar a long time ago. It had the > ability to build a temporary 'clustered table' (think index organized > table) when there was enough benefit to do so. This is actually > much easier to make happen inside a transaction for us, because we don't > need to keep visibility information around. There's probably also some > index metadata that could be done away with. Perhaps the materialize > node could be made to allow this. How does what you describe differ from a merge join? Or a hash join, if you imagine the temp index as being a hash rather than btree index? The issue at hand really has nothing to do with temp indexes, it's with the constrained way that the planner deals with EXISTS subplans. The subplans themselves are cheap enough, even in the poorly-indexed variant, that the planner would certainly never have decided to create an index to use for them. The problem only becomes apparent at the next level up, where those subplans are going to be repeated a huge number of times ---- but the subplan plan is already chosen and won't be changed. So even if we invented a temp-index facility, it would fail to be applied in Kevin's example. The limiting factor is that EXISTS subplans aren't flattened ... and once that's fixed, I doubt the example would need any new kind of join support. regards, tom lane