Replying to myself...
Jeff suggested to build pages in local memory and insert them later in the
table. This is what's used in CLUSTER for instance, I believe.
It has some drawbacks though :
- To insert the tuples in indexes, the tuples need tids, but if you build
the page in local memory, you don't know on which page they will be until
after allocating the page, which will probably be done after the page is
built, so it's a bit of a chicken and egg problem.
- It only works on new pages. Pages which are not empty, but have free
space, cannot be written in this way.
The little experiment I made yesterday does not have these drawbacks,
since it allocates pages in the standard way, simply it inserts many
tuples in one operation instead of just inserting one. If the page
happened to be empty, it's even better, but it's not necessary. If your
table has lots of free space, it will be used.