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 1w4nIW-002YuT-2O for pgsql-performance@arkaria.postgresql.org; Mon, 23 Mar 2026 21:58:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1w4nIU-002eb0-0h for pgsql-performance@arkaria.postgresql.org; Mon, 23 Mar 2026 21:58:54 +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.96) (envelope-from ) id 1w4nIT-002eas-2b for pgsql-performance@lists.postgresql.org; Mon, 23 Mar 2026 21:58:54 +0000 Received: from mail-qv1-xf31.google.com ([2607:f8b0:4864:20::f31]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1w4nIS-00000000grr-1wTZ for pgsql-performance@lists.postgresql.org; Mon, 23 Mar 2026 21:58:53 +0000 Received: by mail-qv1-xf31.google.com with SMTP id 6a1803df08f44-899ee491af3so5851216d6.1 for ; Mon, 23 Mar 2026 14:58:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1774303132; cv=none; d=google.com; s=arc-20240605; b=YHXMtCv0pqJEmPpKw3hl5RFEBnrsHZTfX1tskdrljPi2+AXBB498CHpS5cIZrJUX1K qdsSv1N+8sVzyCHTIJW/nORJTnoP7Pe+t98/+tAFjiwvwTO4ZMOJoxoh/eocu3tkz97+ xiWC5gXlEqq2269SHG4QGvrNm+5XSPorhNyasTW38y6toWuRAqLrNoEGRP0nLz+KzSLS UO+n+AG1sgqvF+4siPZaycZCM8/pRpDTfi6GJdnoaPOSoSxDCdWfHybHhZSXsX8jlClp JpCLX6l5jtuG6i5OO1qg1fX0Dj1X09X6tJDWfhBuhMMp2PrD4uJqSJb4/4PVh1uaA9iW GEqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=P9w9wPstUAJ6k4pXekA/WjyHOunGhtjjIQZCcmx/qsY=; fh=fhb8pqLZ3bWk5X7i2TICsWgN/MLLCxzAw6zoDGzxa9s=; b=dge+wnzeIuZd+s4ZoiDdhOFf5SSdy+Ip4ObYTywTJeA8t89BGJ4FMf70z6KFrPr0fD vvBzT/Sz1mY10wJQIq8WEK5YLaoOZIcg3bPfQAUovoytUdNuYCGaqKjVeld27LpA04BD MoKHIGyQ6EGfu8mugiJNuUjY5nNCui37D7Po2Alloal/kf9SDYmLx1H1g8n9A5q4R9oL A7uyqMhFqaE95BOIiJ+o1y0psgzBqRp02Jg8d7CkNjXwjtdZNyQe5Tb5/BBmHh8wJW3h SnK6tBHAdbisg/ih7K03jZqyz/04Ohi4w6s2NEviL/Ed1jrCXc7R0d/4OK8GiFLK53gg nMvA==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1774303132; x=1774907932; 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=P9w9wPstUAJ6k4pXekA/WjyHOunGhtjjIQZCcmx/qsY=; b=kV4GzT1I4jVaqjOseBOqf4p1ZBc6cirQKuGhFoeMMbe516VOMyDjuqYURJjOXJ9kaG fiC4JApbf5irJAp3eXcNY6JtGZx556u0pE7xJXwvND2w8C5C/R8NeJ1x3SQIGSTj1z9f gUrdAJtod9ILWpxR02LdxoG+oPLULGLibJojhej5u63PhltDNA0RX/FFBWefuFbWxvda 1KFwwLapL1RfJvQE8SErq7pI+kHIb05e36qd129Jr2NHpN1RKNaTDdljtYCI6+G+F+1M Q9r0cfp4EciwgWiYttbNWj6osgua3zdGUIu5at/itP4IqkXV5FMdTXyFW4BhSi6EQHg7 DWaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1774303132; x=1774907932; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=P9w9wPstUAJ6k4pXekA/WjyHOunGhtjjIQZCcmx/qsY=; b=U5wpAhITk6UyrR7HdhEGGHHEN6T4snmdRGtV7qMOvi0U1F6Ir7WcWjGjoBHBbMqOx5 i8KxNAH7WNfX9ZeylEWEdSqfRpOu3WRHof5ql3niz7XCPY5Yz0F11FnVZ5ZkDFshcUNp QazXjg8k95aK3FyDPdj/1xQnaktuXabrw3k8KsaETT84OEXJzs9X9/ZQp1TkoHzImYIm nFhpdNyiAAF8QuRZ6q5SuhJzVvdZZuotw17qVMJ8bMJvYa0T7HVKN5bAjvI9Dc3CPlV7 ks/cyE2x2LmrGITAKqtoqpjP58GrxqrpzAveD/giNbQKkMfylksAxguUZhWySaxfVS2T tJ8w== X-Forwarded-Encrypted: i=1; AJvYcCUBT3ym6G+mV0GmZY4qIZph9H1RzoLP2p8lOjlRUP2LKtrorh+f+M6mbgw9ntDxzzagM1O+536KaBicxGwsjBHHVw==@lists.postgresql.org X-Gm-Message-State: AOJu0YydaoVL0Z+4Yl60RJE9cThCCytJiLbQv2osvC0y0wdqLOPZp5eN OMky0QuX7ugUeoiL1sMVry7JU8OxTYBVNQZPoKhp0ROJw0XR9QPExq9RbA7ft306lJbdmYwq7yZ RzYDbYGBYcREFjNyOU5wDDC36Cv3iIjI= X-Gm-Gg: ATEYQzxsLG6m0WceLdqlLXYEo+FHNDdyIVd4xxdFGshaMtkZ9j4OPDfdzsYWSTVRNfW NhwnC7ayk7KCfJSOHoH4z1FTFS7rzPxw0+fYk+Wi7tdoFTOjKIXhEAbFErqpvkmvwP7iFSnNASf hW5q+r11N+Rfcy7TK5xpMlqljQoGIA6Yo1rjFOfrWdsgA3cgcUJIlPY4UIPmwxShGE7JaQZJOHd 2kYNJi0IWPDC3BzVBo8n7UT152/QdQFALKydJb9j5OruCIba81X3HQhEdyIULt9XnPpoDBe3whp vZop9sW6XPoLpraxh4txEtT3bagcz96/bvqnPliYd859o/bdS27upWpx5rwGYxicD5rzg777q3z S2LLsXjIJ X-Received: by 2002:a05:6214:1bce:b0:89a:10d8:f9ca with SMTP id 6a1803df08f44-89c859e84d5mr226201076d6.26.1774303131554; Mon, 23 Mar 2026 14:58:51 -0700 (PDT) MIME-Version: 1.0 References: <574349.1773786268@sss.pgh.pa.us> <381e7d47-8021-458d-9a64-0cdb80b004f0@gmail.com> <2a32c870-3f69-4b09-854d-ffea03b1e537@gmail.com> In-Reply-To: <2a32c870-3f69-4b09-854d-ffea03b1e537@gmail.com> From: Merlin Moncure Date: Mon, 23 Mar 2026 15:58:40 -0600 X-Gm-Features: AQROBzDvd0Wuh5RFcyjVtheguuks9IbSPCPaRJHCJDcL94mU3Ape0NvhL_FMAPw Message-ID: Subject: Re: postgres chooses objectively wrong index To: Andrei Lepikhov Cc: Alexey Ermakov , Tom Lane , pgsql-performance@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000e1564a064db8238b" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000e1564a064db8238b Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Thu, Mar 19, 2026 at 1:09=E2=80=AFAM Andrei Lepikhov = wrote: > On 18/3/26 19:38, Merlin Moncure wrote: > > On Tue, Mar 17, 2026 at 11:27=E2=80=AFPM Alexey Ermakov > I think the planner is not giving enough bonus for an exact match versu= s > > an inexact match on partial index mathcing, (A=3DA should be better th= an > > A IN(A,B,C)), and it's unclear why the planner things bitmap heap + sor= t > > is outperforming a raw read off the index base on marginal estimated ro= w > > 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. > Thanks. I understand the challenge with estimation around partial indexes. Something deeper seems to be at play here. Poking around more, I see that the bad plans are related to bloat. A simple REINDEX of one of the indexes made the problem disappear; however, what's odd is that the estimates didn't really change although the net plan cost certainly did. It's also worth noting ANALYZE doesn't help, only REINDEX does. I keep coming back to this: the bitmap scan noted above makes no sense. I'm trying to figure out what is steering the planner in that direction and eliminate it. This problem reliably reproduces about once a month (taking down production). I'll wait for it to recur and look at it with fresh eyes. merlin --000000000000e1564a064db8238b Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
On Thu, Mar 19, 2026 at 1:09=E2=80=AFAM A= ndrei Lepikhov <lepihov@gmail.com> wrote:
--000000000000e1564a064db8238b--