Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bDFlk-0004Wd-IB for pgsql-hackers@arkaria.postgresql.org; Wed, 15 Jun 2016 18:42:28 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bDFlk-0003bG-5X for pgsql-hackers@arkaria.postgresql.org; Wed, 15 Jun 2016 18:42:28 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bDFli-0003a2-RG; Wed, 15 Jun 2016 18:42:26 +0000 Received: from mail-ob0-x22b.google.com ([2607:f8b0:4003:c01::22b]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1bDFle-0000oO-Tf; Wed, 15 Jun 2016 18:42:26 +0000 Received: by mail-ob0-x22b.google.com with SMTP id ot10so1496538obb.2; Wed, 15 Jun 2016 11:42:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=NcbL//GhWPnAIoUXSJ8LMQlfVcWkcaA1V3j4lVEKUYs=; b=j+EltfUBYHdQUqZSV7tg8We5+0SWEKfkpYqkebNWGuwvgJjK7hy5k/aT5RSIrfYqyV lUgIYLsn3z/4gbj4B5DgN7BPMC+hv9jYj4/lpunGGTmFbwUDJKZAOtYxOki2dteneYgu frBocZBc0vmcKBERNSTFHg7UkYl/fDmXuJlbJ+PEey1+PNYNDMtNL2K2FboytrwQcosk iKU+RJ+KPGmkv2Sz+C9rCubVjt6UIvGIOwJJnmVi4wFAzxUADv2bLz+KKs2Od3DuDIvx 5FEZBs4XJ1lod5X8cQl0u8421H3g/o0mzI1CY6NOBGve1UeZ1lPDGcgdQfNMpROOQVVC Kfhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=NcbL//GhWPnAIoUXSJ8LMQlfVcWkcaA1V3j4lVEKUYs=; b=XLDvD0Ipslx3GiLQll5VkooIfJuSDdW/DG7IOy0o/9FXTnuLLoRsn86Ij3EG/6Glco aPT8vsmUEn2ZD406yJM63qO2xnse/Xf9EwQN5cNxIG/FtMgmHg/VCfTskIgQ85YG7BzB r+RSQ8WZN+B6EGImDkpWoTkRdA/o/iQxFjCdLCxNYTBXPQtwcOpY4AiKdPHtimDgjTRh G+aPSrvILpGKtkqoOahIF5b4biGt9/5V2z/IoYUusM33un6hfp0PRJ5T6vtU5oVj67hw MYjjJNa2mgDMByqa48x2mP8IXZftCmuUSCaQw76pGDhO/i3yRMiSQtFYlZ9f07/xyUvL GfgQ== X-Gm-Message-State: ALyK8tLdzXQEa1F0oyu3A7cubxoQn+cvfiPcKnICEUgd7M9WbClhr7PAq2Yl3NUPL/s9OcC9MCFNOc5cHFgqTg== X-Received: by 10.202.64.214 with SMTP id n205mr114529oia.104.1466016140239; Wed, 15 Jun 2016 11:42:20 -0700 (PDT) MIME-Version: 1.0 Received: by 10.182.168.105 with HTTP; Wed, 15 Jun 2016 11:42:19 -0700 (PDT) In-Reply-To: References: <20160416205630.puxsglckxi3sn5ec@alap3.anarazel.de> <171569342.34745.1461078735421@RIA> <20160506220728.bgyxet73t6s3hjiw@alap3.anarazel.de> <20160507004844.wbze4nhjqa67io2a@alap3.anarazel.de> <20160524170058.6fhenruilde4xza4@alap3.anarazel.de> From: Kevin Grittner Date: Wed, 15 Jun 2016 13:42:19 -0500 Message-ID: Subject: Re: Re: [COMMITTERS] pgsql: Avoid extra locks in GetSnapshotData if old_snapshot_threshold < To: Robert Haas Cc: Andres Freund , Ants Aasma , Amit Kapila , Noah Misch , Kevin Grittner , "pgsql-hackers@postgresql.org" , "pgsql-committers@postgresql.org" Content-Type: text/plain; charset=UTF-8 X-Pg-Spam-Score: -2.7 (--) 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 Wed, Jun 15, 2016 at 1:29 PM, Robert Haas wrote: > On Wed, Jun 15, 2016 at 1:44 PM, Kevin Grittner > wrote:>> So what happens in this scenario: >>> 1. ANALYZE runs really slowly - maybe the user-defined function it's >>> running for the expression index is extremely long-running. >>> 2. Eventually, the snapshot for ANALYZE is older than the configured >>> value of snapshot_too_old. >>> 3. Then, ANALYZE selects a page with an LSN new enough that it might >>> have been pruned. >>> >>> Presumably, the ANALYZE ought to error out in this scenario, just as >>> it would in any other situation where an old snapshot sees a new page. >>> No? >> >> The test I showed creates a situation which (to ANALYZE) is >> identical to what you describe -- ANALYZE sees a page with an LSN >> recent enough that it could have been (and actually has been) >> pruned. Why would it be better for the ANALYZE to fail than to >> complete? > > As I understand it, the reason we need to sometimes give "ERROR: > snapshot too old" after early pruning is because we might otherwise > give the wrong answer. > > Maybe I'm confused. In the scenario that you describe, ANALYZE is coming up with statistics to use in query planning, and the numbers are not expected to always be 100% accurate. I can think of conditions which might prevail when seeing the recent LSN. (1) The recent LSN is from a cause having nothing to do with the STO feature, like DML. As things stand, the behavior is the same as without the patch -- the rows are counted just the same as always. If we did as you suggest, we instead would abort ANALYZE and have stale statistics. (2) The recent LSN is related to STO pruning. The dead rows are gone forever, and will not be counted. This seems more correct than counting them, even if it were possible, and also superior to aborting the ANALYZE and leaving stale statistics. Of course, a subset of (1) is the case that the rows can be early-pruned at the next opportunity. In such a case ANALYZE is still counting them according to the rules that we had before the snapshot too old feature. If someone wants to argue that those rules are wrong, that seems like material for a separate patch. -- Kevin Grittner EDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers