Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bTHUa-0000Vy-3a for pgsql-hackers@arkaria.postgresql.org; Fri, 29 Jul 2016 23:47:00 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bTHUZ-0001qc-LW for pgsql-hackers@arkaria.postgresql.org; Fri, 29 Jul 2016 23:46:59 +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 1bTHUX-0001qT-Rc for pgsql-hackers@postgresql.org; Fri, 29 Jul 2016 23:46:58 +0000 Received: from mail-wm0-x22e.google.com ([2a00:1450:400c:c09::22e]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1bTHUU-00064I-9G for pgsql-hackers@postgresql.org; Fri, 29 Jul 2016 23:46:56 +0000 Received: by mail-wm0-x22e.google.com with SMTP id f65so306533620wmi.0 for ; Fri, 29 Jul 2016 16:46:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=2ndquadrant-com.20150623.gappssmtp.com; s=20150623; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding; bh=mMZ4AZb9kiXJ/VDh/xsA9oIR18axkeNJiHJDz+flwJg=; b=TD5L5xYrKBnmgBP+kok5N2aHK+abwciELbPIdRenRn10LUryL1RnOUPDRuFZcw85fE n1wxJ69StK4uAak17fvrQENK5agPo7Xv6XY2Xse3+TpAcvpQ9EyNdYfYPAfVR5APixid sywvWW2xOCCklJTMGLF46JWnJN09laoLrOZwN2MEzM0WvLcG8H8Na4VFJ6pMfmGZ6+j7 HXrP+Za77rrUfvfk3kAEbPI4oWIXXSj1IMPja6Oa8uVYM7xrVpsScNqhMjz1bsGvV/KZ Es6R/msqXjbshiaCu0mX3NgtmyCqusLVdyYUD4f4bS9heEGc+bDK0pQ5jvYjMVI7lBGv WSmw== 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:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding; bh=mMZ4AZb9kiXJ/VDh/xsA9oIR18axkeNJiHJDz+flwJg=; b=PVxoOKWedTNfa2AzDVKayJXJP5h22V6cK+uN0A3+NsvSZ+FnUmpp3J/RU2O0RERYOa VBObEDUWbwedIONlOXn7mjpqFY7ndN1Xn1ywRvQ86DRRsbgrB8roU8f2ExfsX84Ecp8J VEI5qirs66eGygHxLaVa5Rku02d2gzpd1Wp4BcDByAvMVsl82y/NE3B4S3pSYo/+P17P HoeHj2OMa5uz9D5qF7/JgGUp+6uF10i+Rg7Qz0WrsxlNKaUsycRNeaskeuULcZFEHXOm v4O0Ttqx3/VbffMrxoFmsu+t6MVRa/jfWPGFZX9oEnV/udJ4QPzloMs0IXI3t0VQ6nNn /u5w== X-Gm-Message-State: AEkoouuXey5RcaOyMWNAKGdf/z/70mwOMrur62yx2gBM7zl/TN+sWlUP9c4t/iyE/D1wXWI0 X-Received: by 10.28.158.142 with SMTP id h136mr46569864wme.10.1469836011950; Fri, 29 Jul 2016 16:46:51 -0700 (PDT) Received: from [10.137.2.20] (cst-prg-65-26.cust.vodafone.cz. [46.135.65.26]) by smtp.gmail.com with ESMTPSA id mc8sm18702092wjb.7.2016.07.29.16.46.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 29 Jul 2016 16:46:50 -0700 (PDT) Subject: Re: [Patch] Temporary tables that do not bloat pg_catalog (a.k.a fast temp tables) To: pgsql-hackers@postgresql.org, Aleksander Alekseev References: <20160729141552.4062e19b@fujitsu> From: Tomas Vondra Message-ID: <39b0f423-a4df-3564-3b4a-b1de6f9eea80@2ndquadrant.com> Date: Sat, 30 Jul 2016 01:46:45 +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: <20160729141552.4062e19b@fujitsu> Content-Type: text/plain; charset=windows-1252; 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 Hi, On 07/29/2016 01:15 PM, Aleksander Alekseev wrote: > Hello > > Some time ago we discussed an idea of "fast temporary tables": > > https://www.postgresql.org/message-id/20160301182500.2c81c3dc%40fujitsu > > In two words the idea is following. > > > > PostgreSQL stores information about all relations in pg_catalog. Some > applications create and delete a lot of temporary tables. It causes a > bloating of pg_catalog and running auto vacuum on it. It's quite an > expensive operation which affects entire database performance. > > We could introduce a new type of temporary tables. Information about > these tables is stored not in a catalog but in backend's memory. This > way user can solve a pg_catalog bloating problem and improve overall > database performance. > > Great! Thanks for the patch, this is definitely an annoying issue worth fixing. I've spent a bit of time looking at the patch today, comments below ... > > I took me a few months but eventually I made it work. Attached patch > has some flaws. I decided not to invest a lot of time in documenting > it or pgindent'ing all files yet. In my experience it will be rewritten > entirely 3 or 4 times before merging anyway :) But it _works_ and > passes all tests I could think of, including non-trivial cases like > index-only or bitmap scans of catalog tables. > Well, jokes aside, that's a pretty lousy excuse for not writing any docs, and you're pretty much asking the reviewers to reverse-engineer your reasoning. So I doubt you'll get many serious reviews without fixing this gap. > Usage example: > > ``` > CREATE FAST TEMP TABLE fasttab_test1(x int, s text); > > INSERT INTO fasttab_test1 VALUES (1, 'aaa'), (2, 'bbb'), (3, 'ccc'); > > UPDATE fasttab_test1 SET s = 'ddd' WHERE x = 2; > > DELETE FROM fasttab_test1 WHERE x = 3; > > SELECT * FROM fasttab_test1 ORDER BY x; > > DROP TABLE fasttab_test1; > ``` > > More sophisticated examples could be find in regression tests: > > ./src/test/regress/sql/fast_temp.sql > > Any feedback on this patch will be much appreciated! > > 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. 2) Why do we need the new relpersistence value? ISTM we could easily got with just RELPERSISTENCE_TEMP, which would got right away of many chances as the steps are exactly the same. IMHO if this patch gets in, we should use it as the only temp table implementation (Or can you think of cases where keeping rows in pg_class has advantages?). That'd also eliminate the need for FAST keyword in the CREATE TABLE command. The one thin I'm not sure about is that our handling of temporary tables is not standard compliant - we require each session to create it's own private temporary table. Moving the rows from pg_class into backend memory seems to go in the opposite direction, but as no one was planning to fix this, I don't think it matters much. 3) I think the heapam/indexam/xact and various other places needs a major rework. You've mostly randomly sprinkled the code with function calls to make the patch work - that's fine for an initial version, but a more principled approach is needed. 4) I'm getting failures in the regression suite - apparently the patch somehow affects costing of index only scans, so that a several queries switch from index only scans to bitmap index scans etc. I haven't investigated this more closely, but it seems quite consistent (and I don't see it without the patch). It seems the patch delays building of visibility map, or something like that. 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