| From: | Israel Brewster <ijbrewster(at)alaska(dot)edu> |
|---|---|
| To: | PostgreSQL General <pgsql-general(at)lists(dot)postgresql(dot)org> |
| Subject: | PostgreSQL 15-->18 slowdown? |
| Date: | 2026-06-26 17:58:30 |
| Message-ID: | 4A6D9280-1409-42A8-9A1F-99E2A558E2BB@alaska.edu |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
In postgreSQL 15, I had the below query that worked quickly. Now, I make no claims that the query is the best possible, or even a good query, but it DID work, and it did so quickly enough to be un-noticable when running.
Then I upgrade to PostgreSQL 18 - and now the query never completes (as in, I get a command timeout after at least half an hour before I get a result). Looking at the EXPLAIN (https://explain.depesz.com/s/llAQ) makes it pretty obvious why: we have a sequence scan on a large table inside a nested loop - and that sequence scan is apparently not short circuiting.
I tried the obvious: REINDEX database and VACUUM ANALYZE, but neither helped. I have my default_statistics_target set to 500 at the moment.
Then I tried SET enable_seqscan = off; Lo and behold, the query ran in only 123.888 ms (fun number :-D ) - https://explain.depesz.com/s/K2K9
What did I do wrong here? Thanks!
The query in question:
SELECT
stations.id,
stations.name as name,
latitude::float as lat,
longitude::float as lon,
elevation::float alt,
type,
coalesce(sites.name, 'Unknown') as site,
sites.id as siteid,
coalesce((SELECT true
FROM tilt_data
INNER JOIN tilt_orientation
ON tilt_data.station=tilt_orientation.station
WHERE tilt_data.station=stations.id
LIMIT 1),
false) as has_tilt,
array_to_json(volcano) as stationvolcs,
coalesce(
(SELECT array_agg(s.volcano_name ORDER BY t.ord)
FROM volcano s
JOIN unnest( volcano ) WITH ORDINALITY t(id,ord)
ON (t.id=s.volcano_id)
), '{}' ) volcnames
FROM stations
LEFT JOIN sites ON stations.siteref=sites.id
ORDER BY site, name
---
Israel Brewster
Software Engineer
Alaska Volcano Observatory
Geophysical Institute - UAF
2156 Koyukuk Drive
Fairbanks AK 99775-7320
Work: 907-474-5172
cell: 907-328-9145
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Adrian Klaver | 2026-06-26 18:14:56 | Re: PostgreSQL 15-->18 slowdown? |
| Previous Message | Daniel Gustafsson | 2026-06-26 11:44:33 | Re: FYI, 19beta1 server working fine for us |