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 1v1sPo-00Dbrj-IK for pgsql-performance@arkaria.postgresql.org; Thu, 25 Sep 2025 20:18:08 +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 1v1sPm-005mkv-QG for pgsql-performance@arkaria.postgresql.org; Thu, 25 Sep 2025 20:18:06 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1v1sPm-005mka-GU for pgsql-performance@lists.postgresql.org; Thu, 25 Sep 2025 20:18:06 +0000 Received: from mail-lj1-x231.google.com ([2a00:1450:4864:20::231]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1v1sPk-002QOU-0x for Pgsql-performance@postgresql.org; Thu, 25 Sep 2025 20:18:05 +0000 Received: by mail-lj1-x231.google.com with SMTP id 38308e7fff4ca-367444a3e2aso16130901fa.2 for ; Thu, 25 Sep 2025 13:18:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1758831483; x=1759436283; darn=postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=CS82kF4pFfNLAt8THXpdDdR69LMUno5Tww6FBDJXiSs=; b=Qc49wa9rznPSe/idNvXRXp+KJgEjr1ZdPgW/qyW3iTMMVyA+EQ13yPWCTpE1Qz4ard 7CXZ8RsLbwmb9hZgslVGoLzW6le9jsyuv+PH6mf00iOnW2eDWpe7ZEHRj40i/6NTr6Aa qGuuD1ScPjPhUevbrMyOjpo4tLa/6H+jcdWcaNqb4DObpOo6fnzTO8mnSrEVBaAaHzQ+ W+iF1FVRrO4FyVCheDdCI3XYQxq+fZiEy1fPWeVpBW7lbKCdz+Ujwe1s/xGc7NYAzzdY +CDD/HGXKH3vQaU7z0frMtLPqn1Sfd+KdCWaDsx0zE4pJLUmPlC/SMr1/Hhe5x1D22lg By1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1758831483; x=1759436283; h=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=CS82kF4pFfNLAt8THXpdDdR69LMUno5Tww6FBDJXiSs=; b=IRcVXmZTnkS2UO+KlzG3t1CzyjSP65gIL43xK/mvk3CnTzclIzgtotHxivcGadr1Fx BNSW3/m2f9pnago5zk+66vp02hqRfpfGcxE6ml/wF2npfkwJoy8eBcMeQUhGihP3vrb+ fynTCn1/WR2R64tBY3aKe36g6t0hY+ZVTdhNgdwcuMQMHqz9Dav1OO/zGOa/+qgux+q/ tg0n7BcbvsQgLYd0JoEsYujx3lHhmiH5q9jlssYCNZrnW8/4fhkKN0L/gRuyZ0Qdw9oH VFS63xsGlsisnUATY1EI4LNTmRkvbM9cf3lVPoDCV+BNin/d32ZRCIFanHrC51g4rN5s HIbA== X-Gm-Message-State: AOJu0Yw5F6B0gLeT33naPAWjcw/WCXRCFh75VXCV/PHAWlmZxfxcYTWh 7SYOr18WAfTTajUzwidMouCs+wVDaQIDhkBUWnmya5SCBwOrp0z7pZQpfN6tJ2ulVZvQ8cwOw+L I0QAIBimK0fixz0nQqLw/MxghqJlyN23nLmHv X-Gm-Gg: ASbGncv49sERTp7QxFG9tQ/b903W+3K0I1H7vSVP4SbFcL6Jm1h4rvvcDnc+Ens/jzD JNueZgg1A0ucE6+IVTZ6BRKvSstcfZdnG6JmYEAP7bmFXqeDf6tWrSZ1vLd22drmptbiuJH8+IR L+RyZTptKY4dFTDr5txReeVu4JVPyE/fGmW52/o4LpPUbfX07xBe4GzHdPdqtQ4lmq6az/9GxUL a3I1ye6VZ8RAkm4BcGv5nxdTbfvcCNd/IKG+o6WnYzmu3U4MBQS X-Google-Smtp-Source: AGHT+IGPm5MKZUkgr2Anxkp7S/JoC4qcAJ/lFGAesHTwKzD0vQMKRiNisHSPjAMjK1tE5oUjYV7y5SrcHDNi0NqNfoE= X-Received: by 2002:a2e:a58b:0:b0:336:b941:4ab1 with SMTP id 38308e7fff4ca-36f7d8b6be1mr12706891fa.17.1758831482727; Thu, 25 Sep 2025 13:18:02 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: David Rowley Date: Fri, 26 Sep 2025 08:17:50 +1200 X-Gm-Features: AS18NWC1QSNbAriXH8GdZVFL05qMQoZ-kwhiRFqQmDS1jkbyCQtcuUkQYG8mJbc 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" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Fri, 26 Sept 2025 at 07:49, Lauro Ojeda wrote: > The only way I found to make pruning work is to force index_scan using pg_hint_plan, but I wanted to influence the planner to decide it by itself rather than relying on hints. What's the reason for this misbehaving and what could I do to overcome it? > Partition key: RANGE (transaction_date) > postgres=> explain analyze > select aid, abalance > from accounts > where transaction_date in (select dt_col from t2); The only partition pruning that exists in PostgreSQL that can prune for that query is for parameterised Nested Loop joins. For Hash Join, it's been talked about, but this requires running the partition pruning code for every values that goes into the Hash Table and only scanning the unioned set of those partitions during the hash probe phase. The trouble with that is that it's very hard to know in advance if it'll be worth the extra effort. Putting a tuple into a hash table is quite cheap. Running the pruning code for a range partitioned table is likely to be a few times more costly than the hash insert (depending on how many partitions there are), so if the end result is that nothing was pruned, then that's quite a bit of extra effort for no gain. What we maybe could do better is reduce the cost of the Append scan when there's a run-time pruning object attached. This is a little tricky as we currently only build that object when creating the final plan. To include that in the costs we'd need to move that to the Path generation phase so that we didn't accidentally reject Paths which could be cheaper than we first think. > Also, how could I contribute to get this partition pruning to work? The pgsql-hackers mailing list is where all the discussions about that happen. There is plenty of past discussions on these topics. One such (fairly) recent discussion is in [1]. There are plenty more, including some ideas from Robert Haas about how we might cost run-time partition pruning. That was likely around 2017-2018 range, so you might need to dig deep to find that. David [1] https://www.postgresql.org/message-id/flat/CAApHDvoC7n_oceb%3D8z%2BMY8sTgH4xa%2ByAwBxZ4Dxv8pwkT9bOcA%40mail.gmail.com#45314d3d01ef8ad1eebe72111989062c