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 1uEUeh-008vcb-3B for pgsql-performance@arkaria.postgresql.org; Mon, 12 May 2025 15:01:23 +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 1uEUee-00GmBY-Of for pgsql-performance@arkaria.postgresql.org; Mon, 12 May 2025 15:01:20 +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 1uEUee-00GmA6-91 for pgsql-performance@lists.postgresql.org; Mon, 12 May 2025 15:01:20 +0000 Received: from mail-lf1-x129.google.com ([2a00:1450:4864:20::129]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uEUeb-001Win-0i for pgsql-performance@lists.postgresql.org; Mon, 12 May 2025 15:01:19 +0000 Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-54acc0cd458so4948874e87.0 for ; Mon, 12 May 2025 08:01:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1747062076; x=1747666876; darn=lists.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=0TVyF5bKO3NZKkroFdvej1czz7wNMT8/jy9zT0XwWdw=; b=XAzDAOt/7rcsaPk4XzI2q/iI3JRp3Se/yyMk74Vo6mGhcS/BoBK7D9u9t2rYlc4WhP IFtNUWK9TPDP6HNRO/x3OUAuPL3M/ytdqKNBU2zup8HEMA/cfhFwwthxYdfBjxta/UHW zLYGDtEqXEfSiwqSsDZjeLycXKJl2QthGAvCKrhPOXDYj6ONZa4V3V4AVbloKp4AqkNL bSIwu5S/BBucu4HeS+ec9q57aeuwSFsQJHR9sUIU4CB5mnMuGgx7eqF9YfeTor/DKUx8 Ec0mbMVZE3dLJLTa/FbU788rq7kQda4Zwn6JkKYlATH7VA7D5YYJ6wLqk+J0pcsBazaP e0yQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747062076; x=1747666876; 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=0TVyF5bKO3NZKkroFdvej1czz7wNMT8/jy9zT0XwWdw=; b=hYhJUbXQ6wKp3uNpm8KEzgj8ih03WEfm49EZw7+SuWY9kjry01koMyLIPmz6WJ3fb1 IdL/QNUBQ1gGnbFUJqfziSC0ype4EWAqpPSF2de0n7w687ipMvZs9Ge9HRnwfIu7DQtB FJx3fv5857UubRISmrHGaNcrA9dU6SqU5KBA09M5J0UNlmJLSXnanYX9O4mQpJEgwJ6U E4k5EUBqjsXKMsOOEjNDViszYwAPLXy4lhA+/Nm0/gxykqcagcgGs7OpFrbMuQNwr3kp OAjQ52949xwQb4K7BxCxNr6yj9HC2Nw9l8kxk2AXllYzpR8fMv95jmSleWa18kxZPQYn bLdg== X-Forwarded-Encrypted: i=1; AJvYcCW81nlqzr6cOvq0jumWLqhQkEsC+vEAkEwhloV5oNBOt3GyZZLpvDI6fxow2vaBoKAx3ukrHcGBb8nbUG+iRzA2uw==@lists.postgresql.org X-Gm-Message-State: AOJu0YwIAvrKvoEdEiGT1feNBSH43Fco19V56XiVeC2MjN7eE2Yqmvwd BYdcRwBvHcMDssgZzqYh7+Oe9lyi4JO1AQkOF9P+Wk0UCxUU6fgWR+pgjg66EgK8+vXw14aWiLR zq9r6rwQz/CXt+95PmL1gq5meZVI= X-Gm-Gg: ASbGncu49qouN/FG5giRHT4xSwSQEy16Np0X+51SKAzXprEi6EtWbVr5ubtw1KhFsZl Umvu+EVoIcRHFLJPgWKRI+Qbb9p4PZsydFiHPwyGe4EE3hf1LErWacMtGMo27qrPBsp6n3E1qkr FlDXOLVeLhEf9CNqJYHOAZjNzSR6yVYAm5Fg== X-Google-Smtp-Source: AGHT+IEWHUJkurtrRNJgxGGV9pJkKrr2W5IPekZ57DM5NefCQ+hGDLdYYTXhrcF156K8c3wVX4erUzuf5+fq8Tu3IQc= X-Received: by 2002:a05:6512:660d:b0:549:59d2:9ac0 with SMTP id 2adb3069b0e04-54fc67ec0d3mr3758958e87.47.1747062075896; Mon, 12 May 2025 08:01:15 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: David Rowley Date: Mon, 12 May 2025 08:01:03 -0700 X-Gm-Features: AX0GCFvqlgfbhC9wZEtacfxdGYAK06-dQTBM6IUm0h200k2Hj29w9mPkmFSuGds Message-ID: Subject: Re: inefficient/wrong plan cache mode selection for queries with partitioned tables (postgresql 17) To: Andrei Lepikhov Cc: Maxim Boguk , Pgsql Performance Content-Type: multipart/alternative; boundary="0000000000006f40300634f1960b" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --0000000000006f40300634f1960b Content-Type: text/plain; charset="UTF-8" On Mon, 12 May 2025, 05:08 Andrei Lepikhov, wrote: > Thanks for this puzzle! > I suppose, in case generic planning is much faster than custom one, > there are two candidates exist: > 1. Touching the index during planning causes too much overhead - see > get_actual_variable_range > 2. You have a massive default_statistics_target for a table involved. > This is just an artifact of the fact that runtime pruning is not factored into the costs. Note the cost of the generic plan. The plan_cache_mode GUC is about the only way to overrule the choice to use the custom plan. David > --0000000000006f40300634f1960b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Mon, 12 May 2025, 05:08 Andrei Lepikh= ov, <lepihov@gmail.com> wrot= e:
Thanks for this puzzle!
I suppose, in case generic planning is much faster than custom one,
there are two candidates exist:
1. Touching the index during planning causes too much overhead - see
get_actual_variable_range
2. You have a massive default_statistics_target for a table involved.

This i= s just an artifact of the fact that runtime pruning is not factored into th= e costs. Note the cost of the generic plan. The plan_cache_mode GUC is abou= t the only way to overrule the choice to use the custom plan.

David
--0000000000006f40300634f1960b--