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.96) (envelope-from ) id 1w37Vj-000v1t-2c for pgsql-performance@arkaria.postgresql.org; Thu, 19 Mar 2026 07:09:39 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w37Vi-00GwkB-17 for pgsql-performance@arkaria.postgresql.org; Thu, 19 Mar 2026 07:09:38 +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.96) (envelope-from ) id 1w37Vh-00Gwk3-3C for pgsql-performance@lists.postgresql.org; Thu, 19 Mar 2026 07:09:38 +0000 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w37Vf-000000014y3-1yJ9 for pgsql-performance@lists.postgresql.org; Thu, 19 Mar 2026 07:09:37 +0000 Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-43b4f48c47cso414522f8f.0 for ; Thu, 19 Mar 2026 00:09:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1773904175; x=1774508975; 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=R9EYTzMy0EtIHXIZ4QWjQoHKf6n4E5hboSDfF5SjeTQ=; b=Hxa6eXER2YIb22RSGFJwSRiWw6HUAP/Rwc+IGwYa5XHGdb/iqqB40AYYxo8xLnjl75 XNETl4UnMcRvNgj5XQpK81dfOXgqE1/4Sz38JGtwNkKJRLsQApPWR4D082i7X0hMrmT+ u1BMMX+qW+W46sd+r2VT7J0c2WHbKfO/DGnrMADqnmy6JPqWrUFbiRI73+K4fGxTi9+j e0yTaaBbSBqyTpyxs1oM/AZTi108iWuQLcgGTXj+WNkXBF2yGmp0uvpp/K11lQCWobiC A2cVfl4xd8QXLFTFHwb6RCvdSrezMyNU+kAXh4jYkU782W7tb5IRkcHmI8uNkzJSW7uA DKeA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1773904175; x=1774508975; h=content-transfer-encoding:in-reply-to:from:content-language :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=R9EYTzMy0EtIHXIZ4QWjQoHKf6n4E5hboSDfF5SjeTQ=; b=ItKaBKM3MqI5NkNmSHsiBhD3XMoutd0QbthNhzOJFKe/Il+o3HvvRZ4LwHhN8lHSRG Be0y/ymJyUK6/jkPWVXs7Fx0RiB0gZzz1R4ONaxdjq27mWDd8YVgKGMCNRbpeF6GBfYf Tl4RaM+N5OCV66EfOeErkWYTeksgQ+MKdJiq9OU1xNOOr+djB1e21/jW1h2GPSrFyhmu jpFWkd1OeaQqwj1Y9rT9880+k/+se9+9MKNFNQf14PVwRRl6hYjE1CsKicJ+TCxySCWX cI4ZkCXAFGOGDTdVJfxihXQu/Wc91auQ5+gSA5tlCv3ZtHBt46fx7jEakANGCnqU05TW ygHQ== X-Forwarded-Encrypted: i=1; AJvYcCVWLgSHQDm1tEciBGPyM0iWyIMyK77KJzQNe1hU5epLmgeGPkMH264Unf7PZXTzdxVeLm1WLi29ZdKbJmzYdzyz6Q==@lists.postgresql.org X-Gm-Message-State: AOJu0YxO+WaJz6Myff/CFB1Qgd0Jdmqgtn7VTV2v4o0K2TKD7FPyFfdv +DDtFf1K5uUtBI5nzemwMhLiNKnej9IeLQkAtURxmeLzKhHWB4Paz0sK X-Gm-Gg: ATEYQzwdxTbGVbR5matFSVh98ztHQ0XngsbYJdvyAOw3MupoAtkC0JPh4SmHfI7kvjl PSGTyusGo1B0bqBmUN42NeBKwQn5n6Z4MpxNtibXsx9wGswX1APbBOfykLZW2SKUVS283lE++Lu lI4BhXUa3ohMIok1uM11IGhcEJW1UpHA6KrbSb7IpENP8lODcZ4AFLrVQVT8zz7+obripsFi6lj doS04qEVtZ5go5cAyR72PC8aRbBRv+V/YcXaSQUS+ihcyhjkOACwD36iMSM4ZXWJwnNMwUg2uXe EmCVuGknq8NAxXIl2ASlbvigB0Lg/jbzvAI+HEFaKebNvvjoBcdRPqugzbv8qXYtaRew4u4uqEs tLnnkBIfKRQJPo4w8xwX9OjbxPD6HhUbcDlg+eiexFSHh0VRI1dWZBuMFJDEOIKJL+IbP9KoWxd R3v43ut87pO6UVCIE5eYvUEK2sJXjKNvG2GKPcZnOQev8C X-Received: by 2002:a5d:588a:0:b0:439:ca9b:1f61 with SMTP id ffacd0b85a97d-43b527aa30cmr10752264f8f.17.1773904174681; Thu, 19 Mar 2026 00:09:34 -0700 (PDT) Received: from [192.168.15.192] ([80.251.191.198]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43b51805291sm14308126f8f.0.2026.03.19.00.09.33 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 19 Mar 2026 00:09:34 -0700 (PDT) Message-ID: <2a32c870-3f69-4b09-854d-ffea03b1e537@gmail.com> Date: Thu, 19 Mar 2026 08:09:33 +0100 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: postgres chooses objectively wrong index To: Merlin Moncure , Alexey Ermakov Cc: Tom Lane , pgsql-performance@lists.postgresql.org References: <574349.1773786268@sss.pgh.pa.us> <381e7d47-8021-458d-9a64-0cdb80b004f0@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 18/3/26 19:38, Merlin Moncure wrote: > On Tue, Mar 17, 2026 at 11:27 PM Alexey Ermakov I think the planner is not giving enough bonus for an exact match versus > an inexact match on partial index mathcing,  (A=A should be better than > A IN(A,B,C)), and it's unclear why the planner things bitmap heap + sort > is outperforming a raw read off the index base on marginal estimated row > counts.  Lowering random_page_cost definitely biases the plan I like, > but it skews both estimates. One ongoing shortcoming is that cardinality estimation takes place early in the optimisation process and uses all filter conditions. This can be frustrating because a partial index covers just part of the table and could give the optimiser better statistics. If we ignored the index condition, we might get a more accurate estimate. I haven’t tried to redesign this part myself. If it were simple, someone likely would have fixed it by now. Maybe Tom has some ideas about it. -- regards, Andrei Lepikhov, pgEdge