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 1uERxL-008HK7-Qs for pgsql-performance@arkaria.postgresql.org; Mon, 12 May 2025 12:08:28 +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 1uERxK-00FbAU-9c for pgsql-performance@arkaria.postgresql.org; Mon, 12 May 2025 12:08:26 +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 1uERxJ-00FbAM-Vu for pgsql-performance@lists.postgresql.org; Mon, 12 May 2025 12:08:25 +0000 Received: from mail-wr1-x42c.google.com ([2a00:1450:4864:20::42c]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1uERxH-001VTJ-15 for pgsql-performance@lists.postgresql.org; Mon, 12 May 2025 12:08:25 +0000 Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-3a108684f90so2634082f8f.1 for ; Mon, 12 May 2025 05:08:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1747051702; x=1747656502; darn=lists.postgresql.org; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=j3n0oapbtEHfXDETmiEXvWDbATbvx+k9tcfx8eKR9xw=; b=NVCumbPgRatoPjpoYZb8SPkRYS+x8YZHQrwp1bFTRaBqUgGiAhsWh3doK80DCxlpKz S5lg2pPiOXYMSka3str47COZ5ByMIO1Y5ctcW3jpmesE8/FsB70CTKlg26c1HdwHdavk XMv/FXcZYBr/OM+hUgo2T+XhzvnpRjTdFraqT2rclD6pbcUOL+akmLAXOCE8pX51LxDK lEkMAIImef4+Wf6ixOQgBSRVwqXd/Vn6MfYCHCWGTMAvLslQtdMfIFSVliOcvQmNx7dQ 0HQuW7HwfyDTGJxTjfaI8t3Y/yC2r6B8BMdiZDivpcZ6R3dOnYRsnXu09VFvIwKSgWnV 8MeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1747051702; x=1747656502; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=j3n0oapbtEHfXDETmiEXvWDbATbvx+k9tcfx8eKR9xw=; b=ks2YQ7TdmFMf553+ZxP40cEUguKR37kKTTAU0uWyDcNBYiE68M5f+ICJxtvaUVtv0s R3pdfCkI6Ufld5J+vSkJynNQi5j6pgdbY+0cQ6OPZPWwB+ThcU6eLYOQH3PnBNyOdeQb D06OQ5uSweg1wg3Sn+yAygq3yGWCFLYdyvosPwBV5+8cQuilAumel5Zj9U4Vzy+vE3+L 4dxm7DBp7Nhr2rK3nw62HocLUX61aP3dM5gKpL8S6aRf7Kx1UafcUEwpKL7d+IGpr7SI 9BC2KtQ88LkA/IeY4jSyZ54MUZNoGOiRLBkHDYlJOvY9wNyWFhDKdtKdt6KU7U7uFv5Y 2AKw== X-Forwarded-Encrypted: i=1; AJvYcCXOo5LNkwi43JDM0SRw66fqk0f3QXd2awX33s7a6jEBDSUuQmykoBI+eGEooDqiraySmmHZ5Xs/t59R8krxMASCbA==@lists.postgresql.org X-Gm-Message-State: AOJu0YxcfTmvrpB+E+ivRrbvmAOnS+U5uyEfIiUsD+BTTAYFYau+OYeI 9ZqCgmMxNX3DwTXRv5/DSek7ItGcjc701U3ove4PrvaY7kfsh77TJC3ylCAfMi8= X-Gm-Gg: ASbGncvMccsj0nFhQWvN+A/T5/ZZYJZKtcPh9LDTv6J3Rih4t7k6fTzYM2Sqz0kg4sz p1jD23bSR66ulUmeUKpIrn2FkUTIZQnUqaEQsKWW3ifEaWb942a/YcsVGuYl3YSqjKHUswlmBuI Yrthp1w2K7zUTNkxMU+kUmJRkY1pIudIR/R0j6m81V3gvx37dZiXpDRJ8U9aISvoDJgFqaRzuLB EbcsxJNPaJ9N7SgMfSfNEf3DIynsTg0d2P2wQG1y9TN8dBoLG0YBaLeDYRzl6Oc8Wij0lOxXvfW tFChY0wi9eXA8+p6H11Ro09sqDEhtuUmUnUnX3ENdEZBdPGOntcduClnXb6HT3l5DRF2VBeRaDI TVwfVxfy1qA== X-Google-Smtp-Source: AGHT+IHYQVKzt9HhQ/OAnqC9nvJ6NuutAruBEYZhe5WU2jSAvTYyOKGGMrOMvy2tq3MoM8caML2sZQ== X-Received: by 2002:a05:6000:2506:b0:3a1:f537:94d0 with SMTP id ffacd0b85a97d-3a1f6487b80mr11036249f8f.41.1747051702397; Mon, 12 May 2025 05:08:22 -0700 (PDT) Received: from [192.168.0.89] (84.123.234.224.dyn.user.ono.com. [84.123.234.224]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-3a1f57de001sm12113684f8f.20.2025.05.12.05.08.21 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 12 May 2025 05:08:22 -0700 (PDT) Message-ID: Date: Mon, 12 May 2025 14:08:21 +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 , pgsql-performance@lists.postgresql.org References: Content-Language: en-AU From: Andrei Lepikhov In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 5/12/25 13:49, Maxim Boguk wrote: > I suspect this situation should be quite common with queries over > partitioned tables (where planning time is usually quite a high). > > Any suggestions what could be done there outside of using > force_generic_plan for a particular db user (which will kill performance > in other queries for sure)? 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. So, to clarify the problem, may you provide EXPLAIN (without analyze) with BUFFERS ON ? Also, could you provide extra information on the statistics involved? For each column (I think created_at is the most important one), show the size of MCV and histogram arrays. -- regards, Andrei Lepikhov