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 1oBI2l-000164-Pj for pgsql-performance@arkaria.postgresql.org; Tue, 12 Jul 2022 15:43:23 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1oBI2j-0006BC-E3 for pgsql-performance@arkaria.postgresql.org; Tue, 12 Jul 2022 15:43:21 +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 1oBI2j-0006B2-0J for pgsql-performance@lists.postgresql.org; Tue, 12 Jul 2022 15:43:21 +0000 Received: from mail-io1-xd2d.google.com ([2607:f8b0:4864:20::d2d]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1oBI2b-0002RN-Vo for pgsql-performance@lists.postgresql.org; Tue, 12 Jul 2022 15:43:20 +0000 Received: by mail-io1-xd2d.google.com with SMTP id n68so8209888iod.3 for ; Tue, 12 Jul 2022 08:43:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telsasoft-com.20210112.gappssmtp.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=5TcxI9Z8tR+hjRBvr5x+p3YUh0d7sMdZssswcQQfSNA=; b=zgVZrQq6XinYLtJK3NoGGKXdgOQnN1l/+9KMspXlEMUyRisvBaa6nNvQNw9tmGpzpw blxiJ/aPfWBJCs71odH/+TzTpAWrByNDPfKzpwrG046JUMNkNeZbT8/TzuGu4g0/tDjS jKMt1JB6QqcH0ihoqZdSoFohjCPxab5KTkXKwv8Lr16E1hhzhyHd+9DXl8yWelKIBosD e47zv+BcEZt/Pes86RnJpf5SAseX/ro5GfceRJMBGpwKAwln5Hp00VH8jvM+rDQzu+Ba VRfVpSDbWzHvPGi3zdeGk0kEWtgNfoWUpm5Hss1gBqo1PDThGxYWtYlzMbDshUbMUc/X U37A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to:user-agent; bh=5TcxI9Z8tR+hjRBvr5x+p3YUh0d7sMdZssswcQQfSNA=; b=30bJzTetfUybdkSTjbmzAphldyR9FpBh86kCDjmBIwd6D5BGdMclqVSfv+cFNHfRtK yEs83JT1qG9wYz8/ymb7NvrN2Z6XQjVpgutQOjZJhLBVtoO1Ju9uvZDpbK4zNmpz181Q YTHwqzc6u9VDRWfS6kcGrAtJN+w28sY3ysheK8T/Ga5Y3fPsxqWvOCcf0VxWkmeLO8tQ isRU7imuatAHI4L0/HtNJWWB11qnAQJTYnwhmXIwqhbW+XSfSyGWr9dv6wiiXGjbe7A9 /EgFB/z+fhf8YmCbHgpy6KJOCrhgs88+H/oP5CvcojZ89RoZeNVyhW11ZMt8cfg/q5dy gWHg== X-Gm-Message-State: AJIora8Bw6lCpqipnN9zFB+ShijwD+ecfF1NIL4BrcrJiCxrVgExW9DH DRR8oCe9Gc//zGEtbozTAO3J8O+re3Osfg== X-Google-Smtp-Source: AGRyM1un0mb7z0nmLEyi3s/LNdTa7jPyKUPoq7m5hjxYbZmvvTTz91WLITu5EWOJrDFODaRMau9vwA== X-Received: by 2002:a05:6602:2d12:b0:678:777d:86f4 with SMTP id c18-20020a0566022d1200b00678777d86f4mr12526434iow.12.1657640591755; Tue, 12 Jul 2022 08:43:11 -0700 (PDT) Received: from pryzbyj.telsasoft (charmander.telsasoft.com. [50.244.222.1]) by smtp.gmail.com with ESMTPSA id f9-20020a02a049000000b0033ee1e67c6esm3068996jah.79.2022.07.12.08.43.11 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 12 Jul 2022 08:43:11 -0700 (PDT) Received: by pryzbyj.telsasoft (Postfix, from userid 1000) id 64202802E74; Tue, 12 Jul 2022 10:43:10 -0500 (CDT) Date: Tue, 12 Jul 2022 10:43:10 -0500 From: Justin Pryzby To: Nathan Ward Cc: pgsql-performance@lists.postgresql.org Subject: Re: Occasional performance issue after changing table partitions Message-ID: <20220712154310.GA13040@telsasoft.com> References: <24A451C3-1F45-48ED-B747-4BA17C249AF1@daork.net> <20220710140519.GN13040@telsasoft.com> <4954694D-9E02-4209-815B-07903F57779A@daork.net> <20220711040527.GQ13040@telsasoft.com> <84101021-8B67-45AD-83F2-A3C8F0AA4BEE@daork.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <84101021-8B67-45AD-83F2-A3C8F0AA4BEE@daork.net> User-Agent: Mutt/1.9.4 (2018-02-28) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Wed, Jul 13, 2022 at 03:13:46AM +1200, Nathan Ward wrote: > I have been stepping through the various statements which are different between the two functions, and note that when I do math on a timestamp in a SELECT statement (i.e. _event_timestamp - INTERVAL ‘1 hour’), > the planner takes 50ms or so - note that the result of the timestamp is used to search the partition key. > If I declare a function which does the math in advance, stores it in a variable and then runs the SELECT, the planner takes less than 1ms. > Does this mean it’s calculating the timestamp for each partition, or something like that? I'm not sure I understand what you're doing - the relevant parts of your function text and query plan would help here. Maybe auto_explain.log_nested_statements would be useful ? Note that "partition pruning" can happen even if you don't have a literal constant. For example: |explain(costs off) SELECT * FROM metrics WHERE start_time > now()::timestamp - '1 days'::interval; | Append | Subplans Removed: 36 > I see Postgres 14 release notes has information about performance improvements in the planner for updates on tables with "many partitions”. Is 444 partitions “many”? > My updates are all impacting a single partition only. It sounds like that'll certainly help you. Another option is to update the partition directly (which is what we do, to be able to use "ON CONFLICT"). I think with "old partitioning with inheritance", more than a few hundred partitions was considered unreasonable, and plan-time suffered. With relkind=p native/declarative partitioning, a few hundred is considered reasonable, and a few thousand is still considered excessive - even if the planner time is no issue, you'll still run into problems like "work-mem is per-node", which works poorly when you might have 10x more nodes. TBH, this doesn't sound related to your original issue. -- Justin