Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lVL4n-00021z-9I for pgsql-hackers@arkaria.postgresql.org; Sat, 10 Apr 2021 21:23:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lVL4G-0003pk-Ot for pgsql-hackers@arkaria.postgresql.org; Sat, 10 Apr 2021 21:23:00 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lVL4G-0003pd-D5 for pgsql-hackers@lists.postgresql.org; Sat, 10 Apr 2021 21:23:00 +0000 Received: from mail-ej1-x631.google.com ([2a00:1450:4864:20::631]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lVL4D-0000vB-Dx for pgsql-hackers@lists.postgresql.org; Sat, 10 Apr 2021 21:22:59 +0000 Received: by mail-ej1-x631.google.com with SMTP id e14so14008682ejz.11 for ; Sat, 10 Apr 2021 14:22:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=enterprisedb-com.20150623.gappssmtp.com; s=20150623; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=yaz62mr+83tkKIZy7taM4gV/PfSY0ZGP1HfG2WRRlIo=; b=i4CsLOz9LHGtRd8KcvCqTUIL3FESF2I/iPiM/OhFjBF87Y25eDVpfM8r+vJhX+xY8T xJvXWgoI7nMNEM2v3RjQwsdVdSJlBLHLb0LxgDknzJxDJSGm3jP1KvBrkgY0AroXc23V poadbAXF5H11yVtLv6PwrqOL3akN2RDorUYkTFP7Mo4ALosb40NjdkAN0XZm+XTkcXoT isqaQnYGbzeJAAseA5TYnNMlMqE4+h/WjqSxwj8h7hkfLdbrwg5T60/LRhP1BDJpGEOu 524LJILnJWxd21D9rqmHcqu0yKzCQC5GyYm3peSeF4y270or5lPVHuQiTSzOYJoJcZsF +Sxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=yaz62mr+83tkKIZy7taM4gV/PfSY0ZGP1HfG2WRRlIo=; b=Ae0SBGW0H7Ua+M+Pf9cXektAO+MJarzcqU6GjrvSS8rCe1NmJi3X3XByScVS3k5SPe JIeRuMNfzSckodSXFTHyzAeS8p4m7zgqG95FyCuzZ8bAru3aUWMgn21yJU4/Nc9163uA zZ1jxHo3yf/SJsuv0a6BfboVZC8KF5n1Rsz2ludXDqS8l8C260YmC/dnY6JI2wIaaNtF ujAbFAyDCQg4uKnRfBziplRalD61jU8DlNIkkQTmYHC4sbqaMi/MP+Bx/Jj+oY4vKH5d RF7QNAZKXDX5Epz2nDNlrpGQG1xitXr93czV17EyG3S/4DC5T3pIZneJYmqYLGcbo4ek OXKA== X-Gm-Message-State: AOAM533Xx87sdgtL8SZa770jZWKrRA/3RTXN6qzTeOLJJXp1/n+Btojl X7KYz3GuH8VaFDJP74VQyp505WCNYEFa4QKKJT3fbaiO9P1IAHXnUuzpk6motgiuBFfVDXCWD3j 5W+sUT6q1frbtiW2OWgGTBkQS/nLdXM1SGapcuVrbh8nlE9j9NkJAXZyR5kl6p4Mgj1a7uvyR0w Dk3eGKqlfYZG7Y2rcnMHrSaXO+tMNR1kJvpz+VWDbTPesul4WJVGss X-Google-Smtp-Source: ABdhPJzQX27VdA/9YJWUkPC9jS7nAHztDOB5KUhOMpS/ndMN7tBmt+RAozyq+b/YFIVv63aWtrK0Cg== X-Received: by 2002:a17:906:1386:: with SMTP id f6mr20967322ejc.45.1618089776102; Sat, 10 Apr 2021 14:22:56 -0700 (PDT) Received: from [10.137.0.4] (ip-86-49-253-127.net.upcbroadband.cz. [86.49.253.127]) by smtp.gmail.com with ESMTPSA id a9sm3748422eda.13.2021.04.10.14.22.55 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 10 Apr 2021 14:22:55 -0700 (PDT) Subject: Re: pgsql: autovacuum: handle analyze for partitioned tables To: Justin Pryzby , Alvaro Herrera Cc: Robert Haas , Tom Lane , Zhihong Yu , pgsql-hackers@lists.postgresql.org, Yuzuko References: <20210409214508.GV6592@telsasoft.com> <20210409221659.GA28298@alvherre.pgsql> <20210409222958.GW6592@telsasoft.com> From: Tomas Vondra Message-ID: Date: Sat, 10 Apr 2021 23:22:53 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.8.1 MIME-Version: 1.0 In-Reply-To: <20210409222958.GW6592@telsasoft.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-CLOUD-SEC-AV-Info: enterprisedb,google_mail,monitor X-CLOUD-SEC-AV-Sent: true X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 4/10/21 12:29 AM, Justin Pryzby wrote: > On Fri, Apr 09, 2021 at 06:16:59PM -0400, Alvaro Herrera wrote: >> On 2021-Apr-09, Justin Pryzby wrote: >> >>> One data point: we do DETACH/ATTACH tables during normal operation, before >>> type-promoting ALTERs, to avoid worst-case disk use, and to avoid locking the >>> table for a long time. It'd be undesirable (but maybe of no great consequence) >>> to trigger an ALTER when we DETACH them, since we'll re-ATTACH it shortly >>> afterwards. >> >> You mean to trigger an ANALYZE, not to trigger an ALTER, right? > > Oops, right. It's slightly undesirable for a DETACH to cause an ANALYZE. > >> I think I agree with Tomas: we should do it by default, and offer some >> way to turn that off. I suppose a new reloptions, solely for >> partitioned tables, would be the way to do it. >> >>> However, I think DROP should be handled ? >> >> DROP of a partition? ... I would think it should do the same as DETACH, >> right? Inform that however many rows the partition had, are now changed >> in ancestors. > > Yes, drop of an (attached) partition. The case for DROP is clear, since it > was clearly meant to go away forever. The case for DETACH seems somewhat less > clear. > > The current behavior of pg_dump/restore (since 33a53130a) is to CREATE+ATTACH, > so there's an argument that if DROPping the partition counts towards the > parent's analyze, then so should CREATE+ATTACH. > I think it's tricky to "optimize" the behavior after ATTACH/DETACH. I'd argue that in principle, we should aim to keep accurate statistics, so ATTACH should be treated as insert of all rows, and DETACH should be treated as delete of all rows. Se for the purpose of ANALYZE, we should propagate reltuples as changes_since_analyze after ATTACH/DETACH. Yes, it may result in more frequent ANALYZE on the parent, but I think that's necessary. Repeated attach/detach of the same partition may bloat the value, but I guess that's an example of "If it hurts don't do it." What I think we might do is offer some light-weight analyze variant, e.g. based on the merging of statistics (I've posted a PoC patch a couple days ago.). That would make the ANALYZEs on parent much cheaper, so those "unnecessary" analyzes would not be an issue. regards -- Tomas Vondra EnterpriseDB: http://www.enterprisedb.com The Enterprise PostgreSQL Company