Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id CDAAB63269C for ; Sat, 24 Apr 2010 14:17:26 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 59255-02 for ; Sat, 24 Apr 2010 17:17:16 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-iw0-f187.google.com (mail-iw0-f187.google.com [209.85.223.187]) by mail.postgresql.org (Postfix) with ESMTP id 1F90263265B for ; Sat, 24 Apr 2010 14:17:16 -0300 (ADT) Received: by iwn17 with SMTP id 17so3946877iwn.19 for ; Sat, 24 Apr 2010 10:17:15 -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=qDRhEwf6QUlTTb4jOqYRBmyadP7aVTT3KpOEyCFpgJU=; b=AkX3RZHREAeudindsUda+qld8QMWF85i1sCaQjR3u7XXZSnRxUQb20ge8wec+YjrAH y/3PgRLNnW87pEG3NBVsJLWSNsN0xMUDiU6LYccuIDTS6NO/Jt4xO+EUqqIWsW94Uppg jUUJSt6ZyyweySJF4HhHjvThi+cOLPekQdLIc= 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=Lr17z0SZQECV7v1jLMeXeoIrwfLvTFxT9fKRAOUHDfQY/SoTqNMvOe6Az7dOctVbXF TuaB/L3ydFC0/eUqddEBTzcQd14CBVkxvbN4QtocJmx8UAWRKO6lX5h7zxQknJ9Wmd/y Q8GS+ElDgIyqfwTda6jfDD+CRCrggwprLoST8= MIME-Version: 1.0 Received: by 10.231.145.145 with SMTP id d17mr541554ibv.30.1272129380220; Sat, 24 Apr 2010 10:16:20 -0700 (PDT) Received: by 10.231.12.129 with HTTP; Sat, 24 Apr 2010 10:16:20 -0700 (PDT) In-Reply-To: <7796.1272125493@sss.pgh.pa.us> References: <7796.1272125493@sss.pgh.pa.us> Date: Sat, 24 Apr 2010 13:16:20 -0400 Message-ID: Subject: Re: global temporary tables From: Robert Haas To: Tom Lane Cc: 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=0 tagged_above=-10 required=5 tests=BAYES_20=-0.001, FREEMAIL_FROM=0.001 X-Spam-Level: X-Archive-Number: 201004/1119 X-Sequence-Number: 161231 On Sat, Apr 24, 2010 at 12:11 PM, Tom Lane wrote: > "Greg Sabino Mullane" writes: >>> surprised to find my clone unaffected? =A0If it modifies both, how do w= e >>> avoid complete havoc if the original has since been modified (perhaps >>> incompatibly, perhaps not) by some other backend doing its own ALTER >>> TABLE? > >> Since this is such a thorny problem, and this is a temporary table, why >> not just disallow ALTER completely for the first pass? > > Usually the way we approach these kinds of problems is that we want > to see some plausible outline for how they might be fixed before we > move forward with the base feature. =A0IOW, I wouldn't object to not > having ALTER in the first release, but if we have no idea how to do > ALTER at all I'd be too worried that we were painting ourselves into > a corner. > > Or maybe you can make a case that there's no need to allow ALTER at > all, ever. =A0But surely DROP needs to be possible, and that seems to > already introduce some of the same issues. I had the same thought as GSM this morning. More specifically, it seems to me that the problematic cases are precisely those in which you might feel an urge to touch somebody else's local buffers, so I think we should disallow, approximately, those ALTER TABLE cases which require a full-table rewrite. I don't see the problem with DROP. Under the proposed design, it's approximately equivalent to dropping a table that someone else has truncated. You just wait for the necessary lock and then do it. 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 schema is fixed and doesn't change much, but you're creating it lots and lots of times in lots and lots of different backends, leading to both management and performance difficulties. If you want to be able to change the schema frequently or in a backend-local way, use the existing temporary table feature. Now, there is ONE problem with DROP, which is that you might orphan some heaps. Of course, that can also happen due to a backend crash. Currently, autovacuum arranges to drop any orphaned temp tables that have passed the wraparound threshold, but even if we were happy with waiting 2 billion transactions to get things cleaned up, the mechanism can't work here because it relies on being able to examine the pg_class row and determine which backend owns it, and where the storage is located. We could possibly set things up so that a running backend will notice if a global temporary table for which it's created a private relfilenode gets dropped, and blow away the backing file. But that doesn't protect against crashes, so I think we're going to need some other garbage collection mechanism, either instead of in addition to asking backends to clean up after themselves. I'm not quite sure what the design of that should look like, though. ...Robert