Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 87F9F632217 for ; Sat, 24 Apr 2010 15:32:32 -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 70690-05 for ; Sat, 24 Apr 2010 18:32:21 +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 D23A262D468 for ; Sat, 24 Apr 2010 15:32:21 -0300 (ADT) Received: by iwn40 with SMTP id 40so1995434iwn.1 for ; Sat, 24 Apr 2010 11:32:20 -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=kaxcO0YbLY1FB8ML8AC6yTnCmiMHjnxsX5ZbTFH6baM=; b=nHrvghT3zJdTtDceE7Jd8zGnmtQ/Fe9o0bNI3g1mPYVIGC4OEx6spELbPFRIQjnRWI PgmSh9J61B9xevBJTXdn7GqfgLjQJMFxWqNQWT87Ln1P/eHUbQjeeYnkQguH49jnmkum Y5xohqHrKa9ueHttwd9+bB08vuNIp8jhWzzN4= 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=iAFZ8DGGrr/qrMKlbLpBSumx2sDPJDLMkMVcK1SJ5syEQ6KgXUtOsCWArni56toJlM EZ7feEr+9wL0P5H0wSec9oY7HZ1qE/XRJijtGBFUmq2idWLdlBicYggoOvZH4pgSNiKP AMlvjcLx8az9xVsxlQH2TyKWDmxDFyYftlmk0= MIME-Version: 1.0 Received: by 10.231.168.1 with SMTP id s1mr547763iby.84.1272133940686; Sat, 24 Apr 2010 11:32:20 -0700 (PDT) Received: by 10.231.12.129 with HTTP; Sat, 24 Apr 2010 11:32:20 -0700 (PDT) In-Reply-To: <9319.1272130283@sss.pgh.pa.us> References: <7796.1272125493@sss.pgh.pa.us> <9319.1272130283@sss.pgh.pa.us> Date: Sat, 24 Apr 2010 14:32: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=-1.899 tagged_above=-10 required=5 tests=BAYES_00=-1.9, FREEMAIL_FROM=0.001 X-Spam-Level: X-Archive-Number: 201004/1122 X-Sequence-Number: 161234 On Sat, Apr 24, 2010 at 1: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. I think there's a significant contingent on this mailing list who feel that that gravy would be rather tasty and would like very much to enjoy some of it along with their temporary table tetrazzini. > 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? For a first cut, I had thought about ignoring the problem. Now, that may sound stupid, because now if two different backends have very different distributions of data in the table and both do an ANALYZE, one set of statistics will clobber the other set of statistics. On the flip side, for some usage patterns, it might be actually work out to a win. Maybe the data I'm putting in here today is a great deal like the data I put in here yesterday, and planning it with yesterday's statistics doesn't cost enough to be worth a re-ANALYZE. If we don't want to do that, I suppose one option is to create a pg_statistic-like table in the backend's temporary tablespace and put them there; or we could put them into a backend-local hash table. The current setup of pg_statistic is actually somewhat weak for a number of things we might want to do: for example, it might be interesting to gather statistics for the subset of a table for which a particular partial index is predOK. When such an index is available for a particular query, we could use the statistics for that subset of the table instead of the overall statistics for the table, and get better estimates. Or we could even let the user specify predicates which will cause the table to have a different statistical distribution than the table as a whole, and gather statistics for the subset that matches the predicate. One approach would be to make the starelid column able to reference something other than a relation OID, although I don't think that actually helps with the global temp table problem because if we use the real pg_statistic to store the data then we have to arrange to clean it up. ...Robert