Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1v3KAj-00EVzH-Jl for pgsql-performance@arkaria.postgresql.org; Mon, 29 Sep 2025 20:08:33 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1v3KAh-003qZK-Ks for pgsql-performance@arkaria.postgresql.org; Mon, 29 Sep 2025 20:08:32 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1v3KAh-003qZC-Al for pgsql-performance@lists.postgresql.org; Mon, 29 Sep 2025 20:08:32 +0000 Received: from mail-lj1-x235.google.com ([2a00:1450:4864:20::235]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1v3KAf-000luo-2f for Pgsql-performance@postgresql.org; Mon, 29 Sep 2025 20:08:31 +0000 Received: by mail-lj1-x235.google.com with SMTP id 38308e7fff4ca-363cb0cd8a1so58035271fa.2 for ; Mon, 29 Sep 2025 13:08:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1759176509; x=1759781309; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=SEfHuNcpjatbsN6VIOyQVY10mX660OvX049r6MPfK5I=; b=fcJvTuE5yNlIMKLcNIpGlbjgAWhsKmEJoESN5CfMh1QltRy1P8u5C+thvr0jmE4ON1 M0JZpwhjcLBGLgj+3bQDmGGXFF2b1NNaFyFGjAz7xz6881Z1fa6iH8b7+T8EBkO1LX2D NJkB65BXsqLVN0W93MdWspPwsK2Coyrwf1lTKR0WuSz0SkMnV+K+0GZkgoO9JXP37nLL tFSETtvc5xR0CaVYUZEC3Tf5YBBTBp+tAonKzMa2xfBViHeL90f/U/nwRAgc6qbnjpbV j72jN8irR2Qb/MT4etXIXd42PdwemzXwV/fjgyysUkakXxKeTwMfLOPxEXKwMHYSDoP/ UDWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1759176509; x=1759781309; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SEfHuNcpjatbsN6VIOyQVY10mX660OvX049r6MPfK5I=; b=PVSWKUmYmQ9aER5yqfBJccf0vgQwWy8oVraHAN1v2oo2PZ1VwEWmCtLEPWXuZFY6yg aWrJUcTeY23rJUHMLc/IupaLLCUFNxKNrDC4+q2duyJK11WPKD6T6jn+rMGkj37OX3bo 81zD30ROadfYzEj7KnIB7xM98ezuYpImLnYE9+AVqM58SBsv7T/++Y0vO/MI4gcxblao 3yVnPiEboDz3pu/3gZfT3huQ2L8R8pmH7NUWWU9bm0vme6VvWV6hkplAyOPlDu47kXXL XcYJjR9Ns19deejbe1Vi92HtpbFUMZ8/8v+0SzGICUKE+fUTgl5jcGximQaV3cndf5PJ Omjg== X-Gm-Message-State: AOJu0YxZMp4mMwQgqjGODXnlPUvtybnUEP7chYj/4vxAp4j+okxe64AF 4aKA9TbatkzlkmYCEp/La+NtH7lj+Oz6BCw9dtCSC/+kL/1CMwyzKVIH3bI7Ou03YsfbZcuDzFd PzNHYr6/Mf6+eL7wYMuPYhcQugGhBuwc= X-Gm-Gg: ASbGnctgE9clrJ6QWFQwnU4zlisHfRP8lKUwbtEzjRmWrO8nf340tV09sjL7nQQz2XM qu8Yd1Kov6USlhWaQPqpnD4ZhEYb8IeMdRixtrG3otIrXWoQCnUnWp/vNhqwRMmkVJRFpnR2k/U EFqbTAbv4fOcFI0Z4W2SAPfdY/n9Go8Z77RPxAICkfFIWwiDhUbbYDTMXiK5G7zNos/9Y4QugeB FW6aHwidLGeVgYIRfzLPcdBaOhX5rJW/Lp408WZWaZY4idnqkmJSuuSooMEuh2KPFmSgqMKhNEd lauik1ZG X-Google-Smtp-Source: AGHT+IHdwvFesQ519edRmdlHtO8U3ngIZkXkB3THFADAS+pQ/TiEgQn0XRw+QnHLijW1QIwBWCps3lNwv+bXuifUmBg= X-Received: by 2002:a2e:a908:0:b0:36e:9883:2928 with SMTP id 38308e7fff4ca-36f7d0c31a5mr45560081fa.16.1759176508423; Mon, 29 Sep 2025 13:08:28 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: David Rowley Date: Tue, 30 Sep 2025 09:08:16 +1300 X-Gm-Features: AS18NWAdQb8vSbwCartrZAMWouEcc4BhxZ2iI0p4EJRZ73oe_89Jfo9soSNBYCc Message-ID: Subject: Re: Partition pruning is not happening (even in PG18) To: Lauro Ojeda Cc: Pgsql-performance@postgresql.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Tue, 30 Sept 2025 at 02:49, Lauro Ojeda wrote: > By looking into it, I have the impression there is a bug in the costing s= um in that situation, where the cost of the "never executed" partitions sho= uld be deducted from the final cost estimation, which would make pruning to= be the preferred option in this case. > > Are my assumptions correct? The "never executed" part is not determined at planning time. It's only something the executor gets to figure out, and by that time, it's no good adjusting the plan's costs since the planner has already decided on what it thinks the best plan is and it's too late to change that. > Is there anything I could do to influence the planner to dismiss the cost= of "never executed" scans? Not in the general sense, but for nodes that are "never executed" due to run-time partition pruning. It would be possible to make some assumptions during planning. The planner would need to do some extra work during planning to figure out if an AppendPath or MergeAppend path has run-time prunable parameters. If those parameters plus any non-parameterized quals result in pruning being possible at run-time, then *maybe* there's something we can do better. For equi joins, you could assume that only 1 of the Append children will be scanned. The planner will have no idea which one, but it could do something like total_append_cost / number_of_append_children. For other join types, it's much less clear how that would work. There have been previous proposals to do something with DEFAULT_INEQ_SEL or maybe DEFAULT_RANGE_INEQ_SEL. I've forgotten the exact details as it was about 8 years ago. David