aboutsummaryrefslogtreecommitdiff
path: root/src/include/access/hio.h
diff options
context:
space:
mode:
authorAndres Freund <andres@anarazel.de>2023-08-14 09:54:03 -0700
committerAndres Freund <andres@anarazel.de>2023-08-14 11:33:09 -0700
commit82a4edabd272f70d044faec8cf7fd1eab92d9991 (patch)
tree10ffcc17c59ed5c753822166fff4c082d394a9f7 /src/include/access/hio.h
parent94f9c087421ccda6a615df2dda6c40fb99570fa9 (diff)
downloadpostgresql-82a4edabd272f70d044faec8cf7fd1eab92d9991.tar.gz
postgresql-82a4edabd272f70d044faec8cf7fd1eab92d9991.zip
hio: Take number of prior relation extensions into account
The new relation extension logic, introduced in 00d1e02be24, could lead to slowdowns in some scenarios. E.g., when loading narrow rows into a table using COPY, the caller of RelationGetBufferForTuple() will only request a small number of pages. Without concurrency, we just extended using pwritev() in that case. However, if there is *some* concurrency, we switched between extending by a small number of pages and a larger number of pages, depending on the number of waiters for the relation extension logic. However, some filesystems, XFS in particular, do not perform well when switching between extending files using fallocate() and pwritev(). To avoid that issue, remember the number of prior relation extensions in BulkInsertState and extend more aggressively if there were prior relation extensions. That not just avoids the aforementioned slowdown, but also leads to noticeable performance gains in other situations, primarily due to extending more aggressively when there is no concurrency. I should have done it this way from the get go. Reported-by: Masahiko Sawada <sawada.mshk@gmail.com> Author: Andres Freund <andres@anarazel.de> Discussion: https://postgr.es/m/CAD21AoDvDmUQeJtZrau1ovnT_smN940=Kp6mszNGK3bq9yRN6g@mail.gmail.com Backpatch: 16-, where the new relation extension code was added
Diffstat (limited to 'src/include/access/hio.h')
-rw-r--r--src/include/access/hio.h13
1 files changed, 10 insertions, 3 deletions
diff --git a/src/include/access/hio.h b/src/include/access/hio.h
index 228433ee4a2..9bc563b7628 100644
--- a/src/include/access/hio.h
+++ b/src/include/access/hio.h
@@ -32,15 +32,22 @@ typedef struct BulkInsertStateData
Buffer current_buf; /* current insertion target page */
/*
- * State for bulk extensions. Further pages that were unused at the time
- * of the extension. They might be in use by the time we use them though,
- * so rechecks are needed.
+ * State for bulk extensions.
+ *
+ * last_free..next_free are further pages that were unused at the time of
+ * the last extension. They might be in use by the time we use them
+ * though, so rechecks are needed.
*
* XXX: Eventually these should probably live in RelationData instead,
* alongside targetblock.
+ *
+ * already_extended_by is the number of pages that this bulk inserted
+ * extended by. If we already extended by a significant number of pages,
+ * we can be more aggressive about extending going forward.
*/
BlockNumber next_free;
BlockNumber last_free;
+ uint32 already_extended_by;
} BulkInsertStateData;