Received: from maia.hub.org (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id EA29D632FED for ; Sat, 24 Apr 2010 22:14:57 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 89382-05 for ; Sun, 25 Apr 2010 01:14:39 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-iw0-f202.google.com (mail-iw0-f202.google.com [209.85.223.202]) by mail.postgresql.org (Postfix) with ESMTP id 2FF63632D50 for ; Sat, 24 Apr 2010 22:14:47 -0300 (ADT) Received: by iwn40 with SMTP id 40so2166604iwn.1 for ; Sat, 24 Apr 2010 18:14:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=M1PDdJl8Sh8GKzydKmw8uTGJY34yYxKxDXlUN6lJhAM=; b=Ide5kKSvh+cyCMuU7GtvC4hsEHyykg8c87F1p8leK/XbHVw4tI8IPg6Z4kp/J10qbu EyemqaTBlfCi1GTHUFueTymzd3mjfhfnJHk7g74mpWUpTwVEzZVwbY5qDRYDsnDmfUJ0 GDrMebKU5JQgmUp+4f5UNzlPWFq5vsvsb9uAg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=tMebr6UgeBF2MO/Ty1BgS18jRSxan4qoW1bMwdTNUQ/o523AJUjTBVaeuEI4O8G+KJ E63tJ4E6XI1kar2wmr7hxXYx8xTy1wYIZEk3ohBR2h6E/8FqB+CdOK93XsUq913SqSM8 u5maew23SN/KPzNEbaxjspUcbH5WZGaVJjGCk= MIME-Version: 1.0 Received: by 10.231.149.71 with SMTP id s7mr669701ibv.86.1272158084739; Sat, 24 Apr 2010 18:14:44 -0700 (PDT) Received: by 10.231.12.129 with HTTP; Sat, 24 Apr 2010 18:14:44 -0700 (PDT) In-Reply-To: References: <7796.1272125493@sss.pgh.pa.us> <9319.1272130283@sss.pgh.pa.us> Date: Sat, 24 Apr 2010 21:14:44 -0400 Message-ID: Subject: Re: global temporary tables From: Robert Haas To: Jim Nasby Cc: Tom Lane , Greg Sabino Mullane , pgsql-hackers@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.072 tagged_above=-10 required=5 tests=AWL=-0.172, BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201004/1138 X-Sequence-Number: 161250 On Sat, Apr 24, 2010 at 8:47 PM, Jim Nasby wrote: > On Apr 24, 2010, at 12:31 PM, Tom Lane wrote: >> Robert Haas writes: >>> At least AIUI, the use case for this feature is that you want to avoid >>> creating "the same" temporary table over and over again. >> >> The context that I've seen it come up in is that people don't want to >> clutter their functions with create-it-if-it-doesn't-exist logic, >> which you have to have given the current behavior of temp tables. >> Any performance gain from reduced catalog churn would be gravy. >> >> Aside from the DROP problem, I think this implementation proposal >> has one other big shortcoming: what are you going to do about >> table statistics? =A0In many cases, you really *have* to do an ANALYZE >> once you've populated a temp table, if you want to get decent plans >> for it. =A0Where will you put those stats? > > One possibility: rename the existing pg_stats to pg_stats_permanent. Crea= te a global temporary table called pg_stats_temporary. pg_stats becomes a u= nion of the two. I know the backend wouldn't be able to use the view, but h= opefully access to statistics goes through a limited set of functions so th= at teaching them about the two different tables isn't hard. Yeah, I don't think that would be too horrible. Part of me feels like you'd want to have the ability to store stats for a global temp table in either one of those tables depending on use-case, but I'm also reluctant to invent a lot of new syntax for a very limited use case. > As for cleanup and storage questions; what about having temp objects live= in pgsql_tmp? I'm thinking create a directory under pgsql_tmp for a backen= d PID the first time it creates a temp object (global or local) and create = the files in there. That also means that we don't have to come up with diff= erent relfilenodes for each backend. That would impose a couple of implementation restrictions that don't seem necessary. One, it would imply ignoring reltablespace. Two, it would prohibit (or at least complicate) allowing a backend to CLUSTER or REINDEX its own private copy of the rel. > On the other hand, some layer (presumably smgr) would need to understand = whether a relation was temporary or not. If we do that, cleanup is easy: yo= u can remove any directories that no longer have a running PID. For forensi= cs you probably only want to do that automatically when a backend starts an= d discovers it already has a directory, though we should also provide an ad= ministrator function that will clobber all directories that no longer have = backends. Unfortunately, I don't see much alternative to making smgr know something about the temp-ness of the relation, though I'm hoping to keep the smgr surgery to an absolute minimum. Maybe what we could do is incorporate the backend ID or PID into the file name when the relation is temp. Then we could scan for and nuke such files pretty easily. Otherwise I can't really think how to make it work. ...Robert