Re: Unexpected Seq Scan's when using MERGE WHEN NOT MATCHED BY SOURCE

2025-01-09 Thread Tom Lane
David Mullineux writes: > On Thu, 9 Jan 2025, 12:26 Feike Steenbergen, > wrote: >> If we run this however, there is always a Seq Scan against merge_target, >> whereas the filter of `AND t.device_id = $1` uses a (Bitmap) Index scan >> in other types of queries. > I note ,in the documentation, tha

Re: Unexpected Seq Scan's when using MERGE WHEN NOT MATCHED BY SOURCE

2025-01-09 Thread David Mullineux
On Thu, 9 Jan 2025, 12:26 Feike Steenbergen, wrote: > I'm trying to change a few applications to fully use this, as PostgreSQL > 17 added this support. > > The application does something like this: > > - fetch information from a source system and store it in a temp table > - run a MERGE with a ta

Re: Unexpected Seq Scan's when using MERGE WHEN NOT MATCHED BY SOURCE

2025-01-09 Thread Feike Steenbergen
As a followup, these are the `EXPLAIN (ANALYZE, COSTS OFF, TIMING OFF)` plans for the previous version of the query and the one using NOT MATCHED BY SOURCE. Previous plan: Buffers: shared hit=84 dirtied=1 written=1 New plan: Buffers: shared hit=100690 *Old plan, using delete in CTE, then M

Unexpected Seq Scan's when using MERGE WHEN NOT MATCHED BY SOURCE

2025-01-09 Thread Feike Steenbergen
I'm trying to change a few applications to fully use this, as PostgreSQL 17 added this support. The application does something like this: - fetch information from a source system and store it in a temp table - run a MERGE with a table (target) in this database, updating, inserting and deleting