pgsql: Introduce a new smgr bulk loading facility.

Поиск
Список
Период
Сортировка
От Heikki Linnakangas
Тема pgsql: Introduce a new smgr bulk loading facility.
Дата
Msg-id E1rdWVd-000KXJ-6A@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Introduce a new smgr bulk loading facility.

The new facility makes it easier to optimize bulk loading, as the
logic for buffering, WAL-logging, and syncing the relation only needs
to be implemented once. It's also less error-prone: We have had a
number of bugs in how a relation is fsync'd - or not - at the end of a
bulk loading operation. By centralizing that logic to one place, we
only need to write it correctly once.

The new facility is faster for small relations: Instead of of calling
smgrimmedsync(), we register the fsync to happen at next checkpoint,
which avoids the fsync latency. That can make a big difference if you
are e.g. restoring a schema-only dump with lots of relations.

It is also slightly more efficient with large relations, as the WAL
logging is performed multiple pages at a time. That avoids some WAL
header overhead. The sorted GiST index build did that already, this
moves the buffering to the new facility.

The changes to pageinspect GiST test needs an explanation: Before this
patch, the sorted GiST index build set the LSN on every page to the
special GistBuildLSN value, not the LSN of the WAL record, even though
they were WAL-logged. There was no particular need for it, it just
happened naturally when we wrote out the pages before WAL-logging
them. Now we WAL-log the pages first, like in B-tree build, so the
pages are stamped with the record's real LSN. When the build is not
WAL-logged, we still use GistBuildLSN. To make the test output
predictable, use an unlogged index.

Reviewed-by: Andres Freund
Discussion: https://www.postgresql.org/message-id/30e8f366-58b3-b239-c521-422122dd5150%40iki.fi

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/8af256524893987a3e534c6578dd60edfb782a77

Modified Files
--------------
contrib/pageinspect/expected/gist.out |  14 +-
contrib/pageinspect/sql/gist.sql      |  16 +-
src/backend/access/gist/gistbuild.c   | 121 ++++----------
src/backend/access/heap/rewriteheap.c |  72 +++-----
src/backend/access/nbtree/nbtree.c    |  33 +---
src/backend/access/nbtree/nbtsort.c   | 135 +++++----------
src/backend/access/spgist/spginsert.c |  49 ++----
src/backend/catalog/storage.c         |  46 ++----
src/backend/storage/smgr/Makefile     |   1 +
src/backend/storage/smgr/bulk_write.c | 298 ++++++++++++++++++++++++++++++++++
src/backend/storage/smgr/md.c         |  45 ++++-
src/backend/storage/smgr/meson.build  |   1 +
src/backend/storage/smgr/smgr.c       |  31 ++++
src/include/storage/bulk_write.h      |  40 +++++
src/include/storage/md.h              |   1 +
src/include/storage/smgr.h            |   1 +
src/tools/pgindent/typedefs.list      |   3 +
17 files changed, 552 insertions(+), 355 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: pgsql: Fix mistake in SQL features list
Следующее
От: Heikki Linnakangas
Дата:
Сообщение: pgsql: Fix compiler warning on typedef redeclaration