Received: from maia.hub.org (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 2BF87632A64 for ; Fri, 23 Apr 2010 23:52:55 -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 56562-05 for ; Sat, 24 Apr 2010 02:52:33 +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 E35CD6334C3 for ; Fri, 23 Apr 2010 23:52:42 -0300 (ADT) Received: by iwn17 with SMTP id 17so3601662iwn.19 for ; Fri, 23 Apr 2010 19:52:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:date:message-id :subject:from:to:content-type; bh=23vcDLerKu0yL4Og9sKh+mhVhGS37QBt0SFJ/xHjJTM=; b=K2s4vPkfMVkrmCIpnQJEXcbU4V4bXb5L57zjcLi3ck2haL9tKeskJr9MECDjedeUKC OSI+igevCNjjW7RYmXOzWAAoW+1//qoDsVVjhKaeT3C0TcGbWf8CFBn48ScqNSk9uFxR UyRMTsKWhlVXe/yimAFAFtApI6tjF4y4Q5GSg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=FdRutVOFK1qNMmGNDnePwv3d/rKWYcszOu/y//ABXVBc6pmJ3skh/LSwhUoqUfslfA Ji6bMBx3tu58ncBamtOvNoEPiEg706dZoQWbNPpmFRrWHp8jtOY2e7ONd9KTIY3Aj7HE cSQA93AowV0VBTtB1Dutv6Bt03aAuvp0djknw= MIME-Version: 1.0 Received: by 10.231.162.85 with SMTP id u21mr258376ibx.95.1272077561451; Fri, 23 Apr 2010 19:52:41 -0700 (PDT) Received: by 10.231.12.129 with HTTP; Fri, 23 Apr 2010 19:52:41 -0700 (PDT) Date: Fri, 23 Apr 2010 22:52:41 -0400 Message-ID: Subject: global temporary tables From: Robert Haas To: pgsql-hackers@postgresql.org Content-Type: text/plain; charset=ISO-8859-1 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.375 tagged_above=-10 required=5 tests=AWL=-0.875, BAYES_05=-0.5 X-Spam-Level: X-Archive-Number: 201004/1099 X-Sequence-Number: 161211 A couple of recent threads made got me thinking again about the idea of global temporary tables. There seem to be two principal issues: 1. What is a global temporary table? 2. How could we implement that? Despite rereading the "idea: global temp tables" thread from April 2009 in some detail, I was not able to get a clear understanding of (1). What I *think* it is supposed to mean is that the table is a permanent object which is "globally" visible - that is, it's part of some non-temp schema like public or $user and it's column definitions etc. are visible to all backends - and it's not automatically removed on commit, backend exit, etc. - but the *contents* of the table are temporary and backend-local, so that each new backend initially sees it as empty and can then insert, update, and delete data independently of what any other backend does. As to (2), my thought is that perhaps we could implement this by instantiating a separate relfilenode for the relation for each backend which accesses it. relfilenode would be 0 in pg_class, as it is for "mapped" relations, but every time a backend touched the rel, we'd allocate a relfilenode and associated the oid of the temp table to it using some kind of backend-local storage - actually similar to what the relmapper code does, except without the complexity of ever actually having to persist the value; and perhaps using a hash table rather than an array, since the number of mapped rels that a backend can need to deal with is rather more limited than the number of temp tables it might want to use. Thoughts? ...Robert