Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bTTd3-0002JD-DF for pgsql-hackers@arkaria.postgresql.org; Sat, 30 Jul 2016 12:44:33 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bTTd2-0004WS-6M for pgsql-hackers@arkaria.postgresql.org; Sat, 30 Jul 2016 12:44:32 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bTTbe-00031q-Ly for pgsql-hackers@postgresql.org; Sat, 30 Jul 2016 12:43:06 +0000 Received: from mail-wm0-x22d.google.com ([2a00:1450:400c:c09::22d]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1bTTbX-0001lk-3L for pgsql-hackers@postgresql.org; Sat, 30 Jul 2016 12:43:05 +0000 Received: by mail-wm0-x22d.google.com with SMTP id o80so184862871wme.1 for ; Sat, 30 Jul 2016 05:42:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:cc:from:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding; bh=EbOVWbiqSPNNsU/z3hks1lt7so6bXF9W5E0dfeE7L1s=; b=FeuEYZ4yepc5KqRyqcqX83rxA/5SsrCCwoWGLLUQGNhHTKAbRiL9S9lfnABpCLrcfE 7zl8xVaKvCvKk3ixj59D9m7cud1lzz5wKFAYIZjkzZUhpCCBFnqz5+JAveMSV/nGTUv7 xacZiHqxLY2KABWrZXcl6+plKGdBDdjhYK478djMCaS3ypqQ6Tow8+2ri6RIPlmZTkBR C414tiUhWl8MLyr/DwVdO64WgVCqYuQuCBKZ45/E5W+Kgd0b3S8Wiub2algd+T1jHehF kbvSbRV0v8RaY5UXrpW/BSxCe5qVTWu/VE7rLDh+h1hCS2jwQP88qsZGkpJhWQ7fYUp1 UTQw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:subject:to:references:cc:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=EbOVWbiqSPNNsU/z3hks1lt7so6bXF9W5E0dfeE7L1s=; b=FLXbOGGRfoxy/MVSVQM7ywy4AVK9SjD48SA4tfqKy9HeBNJkecEsoPH9ymjGGO4GDP hhObMcG8HP3lYyBVbq7Oh5aS7ClFpbASc4YvzXXSa/9LvpeeFf+KepPsCLQiaU0gUVk3 q8mFRLkFpSigbdC+Fn8aTVM5nas1rnYZH2L3wLioR0hkNPzIUjc5ilL+a2jJ6TMeNAGD kx56EwVNgMxor7beAanYnpcUX8cdQ5YroABy1BAXqBZSFwnCIGrBCWtjJi964AMrz0Fe vBgXcpLA+pokuYaNGeIQ58c4r77yFb4a6JOFXgvg2iFqJufsLzwo1TKWOcJlrossIVgi ckDg== X-Gm-Message-State: AEkoouvOgjoowPwqxGCy691kiG65Xt3pYe3f+ZNLYEHqjL4j1al11GUdxcNQnWi+MDSHxdRP X-Received: by 10.194.67.198 with SMTP id p6mr42910904wjt.138.1469882576902; Sat, 30 Jul 2016 05:42:56 -0700 (PDT) Received: from [10.137.2.20] ([89.248.140.12]) by smtp.gmail.com with ESMTPSA id o142sm7629188wme.20.2016.07.30.05.42.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 30 Jul 2016 05:42:56 -0700 (PDT) Subject: Re: [Patch] Temporary tables that do not bloat pg_catalog (a.k.a fast temp tables) To: Pavel Stehule References: <20160729141552.4062e19b@fujitsu> <39b0f423-a4df-3564-3b4a-b1de6f9eea80@2ndquadrant.com> Cc: PostgreSQL Hackers , Aleksander Alekseev From: Tomas Vondra Message-ID: Date: Sat, 30 Jul 2016 14:42:54 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:46.0) Gecko/20100101 Thunderbird/46.0a2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.6 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-hackers Precedence: bulk Sender: pgsql-hackers-owner@postgresql.org On 07/30/2016 06:49 AM, Pavel Stehule wrote: > 1) I wonder whether the FAST makes sense - does this really change > the performance significantly? IMHO you only move the catalog rows > to memory, so why should the tables be any faster? I also believe > this conflicts with SQL standard specification of CREATE TABLE. > > > Probably has zero value to have slow and fast temp tables (from > catalogue cost perspective). So the FAST implementation should be used > everywhere. But there are some patterns used with work with temp > tables,that should not working, and we would to decide if we prepare > workaround or not. > > -- problematic pattern (old code) > IF NOT EXISTS(SELECT * FROM pg_class WHERE ....) THEN > CREATE TEMP TABLE xxx() > ELSE > TRUNCATE TABLE xxx; > END IF; I'd argue that if you mess with catalogs directly, you're on your own. Not only it's fragile, but this pattern is also prone to race conditions (although a concurrent session can't create a conflicting temporary table). > > -- modern patter (new code) > BEGIN > TRUNCATE TABLE xxx; > EXCEPTION WHEN ..... THEN > CREATE TEMP TABLE(...) > END; > > In this case we can use GUC, because visible behave should be same. What GUC? > > The benefit of zero catalogue cost temp tables is significant - and for > some larger applications the temp tables did hard performance issues. Yeah, catalog bloat is a serious issue in such cases, and it's amplified by indexes created on the temporary tables. > > Some other random notes: > > 1. With this code should not be hard to implement global temp tables - > shared persistent structure, temp local data - significant help for any > who have to migrate from Oracle. The patch moves in pretty much the opposite direction - if anything, it'll make it more difficult to implement global temporary tables, because it removes the definitions from the catalog, thus impossible to share by catalogs. To get global temporary tables, I think the best approach would be to share the catalog definition and only override the filename. Or something like that. > > 2. This should to work on slaves - it is one of ToDo > No, it does not work on slaves, because it still does a read-write transaction. test=# begin read only; BEGIN test=# create fast temporary table x (id int); ERROR: cannot execute CREATE TABLE in a read-only transaction No idea how difficult it'd be to make it work. > 3. I didn't see support for memory store for column's statistics. Some > separate questions is about production statistics - pg_stat_user_table, .. That seems to work (both analyze and pg_stat_user_tables). Not sure where it's in the code, and I'm not willing to reverse engineer it. regards -- Tomas Vondra http://www.2ndQuadrant.com PostgreSQL Development, 24x7 Support, Remote DBA, Training & Services -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers