Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UamnK-0007Xq-Od for pgsql-performance@arkaria.postgresql.org; Fri, 10 May 2013 12:51:30 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1UamnK-00076m-9L for pgsql-performance@arkaria.postgresql.org; Fri, 10 May 2013 12:51:30 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UamnJ-00076h-Fr for pgsql-performance@postgresql.org; Fri, 10 May 2013 12:51:29 +0000 Received: from [2404:130:0:10::40:2] (helo=mail.catalyst.net.nz) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1UamnG-00067Y-CW for pgsql-performance@postgresql.org; Fri, 10 May 2013 12:51:28 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.catalyst.net.nz (Postfix) with ESMTP id 968093303F; Sat, 11 May 2013 00:51:22 +1200 (NZST) X-Virus-Scanned: Debian amavisd-new at catalyst.net.nz Received: from mail.catalyst.net.nz ([127.0.0.1]) by localhost (bertrand.catalyst.net.nz [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id NacxQLB3P7SL; Sat, 11 May 2013 00:51:21 +1200 (NZST) Received: from [192.168.1.64] (122-60-64-230.jetstream.xtra.co.nz [122.60.64.230]) (Authenticated sender: mark.kirkwood) by mail.catalyst.net.nz (Postfix) with ESMTPSA id 4F27132FAE; Sat, 11 May 2013 00:51:21 +1200 (NZST) Message-ID: <518CED48.1030706@catalyst.net.nz> Date: Sat, 11 May 2013 00:51:20 +1200 From: Mark Kirkwood User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20130404 Thunderbird/17.0.5 MIME-Version: 1.0 To: Vitalii Tymchyshyn CC: pgsql-performance@postgresql.org, Gavin Flower , Tom Lane , Simon Riggs Subject: Re: In progress INSERT wrecks plans on table References: <5179E77B.7050601@catalyst.net.nz> <5179ECC5.2010206@archidevsys.co.nz> <5179F259.3010509@catalyst.net.nz> <5179F5C6.8070702@archidevsys.co.nz> <5180E3C8.3010201@catalyst.net.nz> <2121.1367417215@sss.pgh.pa.us> <5181B80D.70404@catalyst.net.nz> <916bff05a5ab130c76d7835abbaf7762.squirrel@mail.catalyst.net.nz> <51870CB6.6090404@catalyst.net.nz> <51889FF4.7000306@catalyst.net.nz> In-Reply-To: Content-Type: text/plain; charset=KOI8-U; format=flowed Content-Transfer-Encoding: quoted-printable X-Host-Lookup-Failed: Reverse DNS lookup failed for 2404:130:0:10::40:2 (failed) X-Pg-Spam-Score: -1.1 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-performance Precedence: bulk Sender: pgsql-performance-owner@postgresql.org (See below for the reply) On 10/05/13 22:48, Vitalii Tymchyshyn wrote: > Well, could you write a trigger that would do what you need? AFAIR > analyze data is stored no matter transaction boundaries. You could store > some counters in session vars and issue an explicit analyze when enough > rows were added. > > 7 =D4=D2=C1=D7. 2013 08:33, "Mark Kirkwood" > =CE=C1=D0=C9=D3. > > On 07/05/13 18:10, Simon Riggs wrote: > > On 7 May 2013 01:23, __> wrote: > > I'm thinking that a variant of (2) might be simpler to > inplement: > > (I think Matt C essentially beat me to this suggestion - he > originally > discovered this issue). It is probably good enough for only > *new* plans to > react to the increased/increasing number of in progress > rows. So this > would require backends doing significant numbers of row > changes to either > directly update pg_statistic or report their in progress > numbers to the > stats collector. The key change here is the partial > execution numbers > would need to be sent. Clearly one would need to avoid doing > this too > often (!) - possibly only when number of changed rows > > autovacuum_analyze_scale___factor proportion of the relation > concerned or > similar. > > > Are you loading using COPY? Why not break down the load into chun= ks? > > > INSERT - but we could maybe workaround by chunking the INSERT. > However that *really* breaks the idea that in SQL you just say what > you want, not how the database engine should do it! And more > practically means that the most obvious and clear way to add your > new data has nasty side effects, and you have to tip toe around > muttering secret incantations to make things work well :-) > > I'm still thinking that making postgres smarter about having current > stats for getting the actual optimal plan is the best solution. Unfortunately a trigger will not really do the job - analyze ignores in=20 progress rows (unless they were added by the current transaction), and=20 then the changes made by analyze are not seen by any other sessions. So=20 no changes to plans until the entire INSERT is complete and COMMIT=20 happens (which could be a while - too long in our case). Figuring out how to improve on this situation is tricky. Cheers Mark -- Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-performance