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 1uEWqz-009OQq-KG for pgsql-performance@arkaria.postgresql.org; Mon, 12 May 2025 17:22:14 +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 1uEWqx-0009LQ-3Z for pgsql-performance@arkaria.postgresql.org; Mon, 12 May 2025 17:22:11 +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 1uEWqw-0009LH-Po for pgsql-performance@lists.postgresql.org; Mon, 12 May 2025 17:22:10 +0000 Received: from mail-wm1-x32a.google.com ([2a00:1450:4864:20::32a]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uEWqu-001SSV-1G for pgsql-performance@lists.postgresql.org; Mon, 12 May 2025 17:22:09 +0000 Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-441c99459e9so31746615e9.3 for ; Mon, 12 May 2025 10:22:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1747070527; x=1747675327; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=cI4K6fAcbhRS0EHtmiHzEVpB8W8MyMEnwJheD1OWfPc=; b=VydiPO62JCkJE6UV7ggKlpH3kx0cE5YO44HXZXkJo8oqkfZqkWIALs5WbC6Sd/q5lS 6rsFK1eCIeciiHReJUJFVizQMCdVjZRN2ACExm181Qk0iECoJDYa1qcSZlZ3KjdMpwqs DrotGpJKIcwwmHegnWVSGMeHDr8g4RiHZ1uVAHSr6zjLHg0UmYE5bvFgSBh2Z2Of/EJU Cdsz94EgpovoIQGPNerl2Wgg8kPNU7h6v6DwFpa++L8qc3aAeXVYV6kSrsTTudSCaxSX QrXmoW5q6xbcYeE13qsmGdaedqTIliRKIQ3iaDRUC1+QIaVEmr0cUBL5op4mnWRSHPWn Hhhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747070527; x=1747675327; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=cI4K6fAcbhRS0EHtmiHzEVpB8W8MyMEnwJheD1OWfPc=; b=mKUiNbuPPTMj+ppo1iVdhzF2zexuFn8GKynUl59I/rN8aVFhR+4p/AiYMJHqxdMjo7 Nod754M0fq2BoUtRW2P8SHfmdYXvj/9t0wQqt60oDNZcZb746d3bfAh/YDVGesBcvhfq cw4/Fw9aOyqB+lsB6Q//0hMlqeuZQKd7LqerFx9XViAKc9aCgdc8bwYpU1QB4z/cbEQB E7XtHMvcyRFPK8gs9pTLBT/TnaDFa/qqoIb99iSLxGji1PF088LX19+TiQ7tUalXuuxk axwz8XCR1tGv9e0AJFfAZnA1vzuSGNs61L9fQzpngAg0RJbm9heya0tdd4BU9IzZwno6 QApw== X-Gm-Message-State: AOJu0YzcuNJO54YLa5kGeWJtdN47yhgLl3OHV0LbwQx13BMdEgFu+9wt AouuEt8pY+rD9G0jrpLioZAMBhO6vUx58vulFT11yk/n++UTnn4i X-Gm-Gg: ASbGncuQrdtTywT2Q4mq3GjLsMvX0KAMoik4Ajm9XWBKaGz6+JymYxJL/7W+jtPNgwf 18H1AMi1yJQvAOKpwvoJHt/f+iPGO9XMn/HiDwcmqHl9JE50opPJCUUs2veG8SEUa3b4wc/xOkS OdIiBXGKN8zGUgaeibC9aikBrwzY9nDHAF8aomVTBYFwGA/8va+2IdEIe3Upuu5gJt3hiW1WbR+ oNaMpr/n7HxrIYWXKW+d17jG0CoUK86nLLIahRawJpXV/S9BEzyuCuWF3YAEtvgA9fgpZdV9osn yW3XlEIUBZOipYza2M4WNnOOWbtf+gyym0CM9Yu+G0eARuTR/Cpb0jGWNOxlicDrfbf+pm6atzd /ZizOKNZNM1Xd+043ko1qsna7 X-Google-Smtp-Source: AGHT+IGHiBbThPSFZrpTxzBHNg16bG8RiUUnaaeBtHKdOMJLI0j0zPDgDeaFN2yyAhUzp5i65ZSUOQ== X-Received: by 2002:a05:600c:a42:b0:441:d228:1fe5 with SMTP id 5b1f17b1804b1-442d6de0f78mr102691345e9.33.1747070526424; Mon, 12 May 2025 10:22:06 -0700 (PDT) Received: from [172.33.109.83] (17.pool62-36-37.static.orange.es. [62.36.37.17]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a1f58f2b29sm13311904f8f.53.2025.05.12.10.22.05 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 12 May 2025 10:22:06 -0700 (PDT) Message-ID: Date: Mon, 12 May 2025 19:22:05 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: inefficient/wrong plan cache mode selection for queries with partitioned tables (postgresql 17) To: Maxim Boguk Cc: pgsql-performance@lists.postgresql.org, Tom Lane , David Rowley References: <8480be46-6e2a-4b12-9f80-78ba3db79dfb@gmail.com> Content-Language: en-US From: Andrei Lepikhov In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 12/5/2025 16:04, Maxim Boguk wrote: > On Mon, May 12, 2025 at 4:48 PM Andrei Lepikhov It is not hard to write such a tiny extension. As I see, the only extra > stored "C" procedure is needed to set up force-plan-type flag employing > FetchPreparedStatement(). The rest of the code - querying > pg_stat_statements and switching between plan types may be written in > plpgsql. > > If I'm not mistaken, it will work with all PG versions that are > currently in support. What do you think? > > > Such extension would be very useful (and in general - the solution based > on the actual execution data - seems more stable/predictable than the > plan cost based selection which is currently used by postgresql). Okay, as far as I can see now, it costs a couple of weeks to develop. It would be more profitable in terms of speed and usage in older versions than any core patch. What's more, if, as you predict, it will work, it may provide a rationale for opening the entire plan cache for extensions and allow a wide audience to impact the extended protocol (and query plans in stored procedures) in many curious ways. As I may envision, a dummy routine providing a link to the saved_plan_list will spend a few lines of code. A subscription to cached statements may cost more time and effort but seems even more profitable. -- regards, Andrei Lepikhov