From: | David Rowley <dgrowleyml(at)gmail(dot)com> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Jean Landercy - BEEODIVERSITY <jean(dot)landercy(at)beeodiversity(dot)com>, "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
Subject: | Re: Sudden database error with COUNT(*) making Query Planner crashes: variable not found in subplan target list |
Date: | 2022-06-07 20:31:58 |
Message-ID: | CAApHDvquZPsD88s7MkfGFmwTxonniBXFYbJtrRz88emYspxFiw@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Wed, 8 Jun 2022 at 07:55, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>
> David Rowley <dgrowleyml(at)gmail(dot)com> writes:
> > On Tue, 7 Jun 2022 at 19:58, Jean Landercy - BEEODIVERSITY
> > <jean(dot)landercy(at)beeodiversity(dot)com> wrote:
> >> Here is the detail of the table (I have anonymized it on SO, this is its real name):
> >> "logistic_site_location_54ae0166_id" gist (location)
> > I imagine this is due to the planner choosing an index-only scan on
> > the above index. A similar problem was reported in [1].
>
> The other gist index could also be the problem. It seems odd though
> that the planner would favor either index for this purpose over the btree
> indexes on scalar columns, which you'd think would be a lot smaller.
> I wonder if there is some quirk in gist cost estimation that makes it
> improperly claim to be cheaper than btree scans.
I installed PostGIS 3.1.1 and mocked this up with the attached.
Looking at the plans, I see:
# explain select count(*) from logistic_site;
QUERY PLAN
---------------------------------------------------------------------------------------------------------
Aggregate (cost=20.18..20.19 rows=1 width=8)
-> Bitmap Heap Scan on logistic_site (cost=5.92..19.32 rows=340 width=0)
-> Bitmap Index Scan on logistic_site_location_54ae0166_id
(cost=0.00..5.84 rows=340 width=0)
(3 rows)
# drop index logistic_site_location_54ae0166_id;
# explain select count(*) from logistic_site;
QUERY PLAN
-----------------------------------------------------------------------------------------------------
Aggregate (cost=9.92..9.93 rows=1 width=8)
-> Bitmap Heap Scan on logistic_site (cost=5.26..9.39 rows=213 width=0)
-> Bitmap Index Scan on logistic_site_geom_105a08da_id
(cost=0.00..5.20 rows=213 width=0)
(3 rows)
# drop index logistic_site_geom_105a08da_id;
# explain select count(*) from logistic_site;
QUERY PLAN
------------------------------------------------------------------------------------------------------
Aggregate (cost=13.93..13.94 rows=1 width=8)
-> Bitmap Heap Scan on logistic_site (cost=9.26..13.39 rows=213 width=0)
-> Bitmap Index Scan on logistic_site_key_2e791173_like
(cost=0.00..9.21 rows=213 width=0)
(3 rows)
So it does appear that the location index is being chosen, at least
with the data that I inserted. Those gist indexes are costing quite a
bit cheaper than the cheapest btree index.
David
Attachment | Content-Type | Size |
---|---|---|
logistic_site.sql | application/octet-stream | 928 bytes |
From | Date | Subject | |
---|---|---|---|
Next Message | Peter Geoghegan | 2022-06-07 20:41:33 | Re: Collation version tracking for macOS |
Previous Message | Jeremy Schneider | 2022-06-07 20:24:15 | Re: Collation version tracking for macOS |