Re: Introduce new multi insert Table AM and improve performance of various SQL commands with it for Heap AM
Jeff Davis <pgsql@j-davis.com>
From: Jeff Davis <pgsql@j-davis.com>
To: Matthias van de Meent <boekewurm+postgres@gmail.com>
Cc: Bharath Rupireddy <bharath.rupireddyforpostgres@gmail.com>, Masahiko
Sawada <sawada.mshk@gmail.com>, PostgreSQL-development
<pgsql-hackers@postgresql.org>, Andres Freund <andres@anarazel.de>, Dilip
Kumar <dilipbalaut@gmail.com>, Luc Vlaming <luc@swarm64.com>, Justin
Pryzby <pryzby@telsasoft.com>, Michael Paquier <michael@paquier.xyz>,
Alexander Korotkov <aekorotkov@gmail.com>
Date: 2024-08-27T20:09:10Z
Lists: pgsql-hackers
Commits
Same data as JSON:
GET /api/v1/messages/:b64id/commits
the thread's linked commits as JSON, with link sources.
API reference →
-
libpq: Fix some issues in TAP tests for service files
- 2c7bd2ba507e 18.0 cited
-
Multiple revisions to the GROUP BY reordering tests
- 874d817baa16 17.0 cited
-
Explore alternative orderings of group-by pathkeys during optimization.
- 0452b461bc40 17.0 cited
On Tue, 2024-08-27 at 15:44 +0200, Matthias van de Meent wrote:
> > One solution: when the buffer is flushed, we can return an iterator
> > over the buffered tuples to the caller. The caller can then use the
> > iterator to insert into indexes, return a tuple to the executor,
> > etc.,
> > and then release the iterator when done (freeing the buffer).
>
> I think that would work, but it'd need to be accomodated in the
> table_modify_buffer_insert path too, not just the _flush path, as the
> heap AM flushes the buffer when inserting tuples and its internal
> buffer is full, so not only at the end of modifications.
I gave this a little more thought and I don't think we need a change
here now. The callback could support RETURNING by copying the tuples
out into the caller's state somewhere, and then the caller can iterate
on its own and emit those tuples.
That's not ideal, because it involves an extra copy, but it's a much
simpler API.
Another thought is that there are already a number of cases where we
need to limit the use of batching similar to copyfrom.c:917-1006. For
instance, before-row triggers, instead-of-row triggers, and volatile
functions in the query. We could also just consider RETURNING another
restriction, which could be lifted later by implementing the logic in
the callback (as described above) without an API change.
Regards,
Jeff Davis