pgsql: Allow configurable LZ4 TOAST compression. - Mailing list pgsql-committers
From | Robert Haas |
---|---|
Subject | pgsql: Allow configurable LZ4 TOAST compression. |
Date | |
Msg-id | E1lNKw9-0008DT-1L@gemulon.postgresql.org Whole thread Raw |
Responses |
Re: pgsql: Allow configurable LZ4 TOAST compression.
|
List | pgsql-committers |
Allow configurable LZ4 TOAST compression. There is now a per-column COMPRESSION option which can be set to pglz (the default, and the only option in up until now) or lz4. Or, if you like, you can set the new default_toast_compression GUC to lz4, and then that will be the default for new table columns for which no value is specified. We don't have lz4 support in the PostgreSQL code, so to use lz4 compression, PostgreSQL must be built --with-lz4. In general, TOAST compression means compression of individual column values, not the whole tuple, and those values can either be compressed inline within the tuple or compressed and then stored externally in the TOAST table, so those properties also apply to this feature. Prior to this commit, a TOAST pointer has two unused bits as part of the va_extsize field, and a compessed datum has two unused bits as part of the va_rawsize field. These bits are unused because the length of a varlena is limited to 1GB; we now use them to indicate the compression type that was used. This means we only have bit space for 2 more built-in compresison types, but we could work around that problem, if necessary, by introducing a new vartag_external value for any further types we end up wanting to add. Hopefully, it won't be too important to offer a wide selection of algorithms here, since each one we add not only takes more coding but also adds a build dependency for every packager. Nevertheless, it seems worth doing at least this much, because LZ4 gets better compression than PGLZ with less CPU usage. It's possible for LZ4-compressed datums to leak into composite type values stored on disk, just as it is for PGLZ. It's also possible for LZ4-compressed attributes to be copied into a different table via SQL commands such as CREATE TABLE AS or INSERT .. SELECT. It would be expensive to force such values to be decompressed, so PostgreSQL has never done so. For the same reasons, we also don't force recompression of already-compressed values even if the target table prefers a different compression method than was used for the source data. These architectural decisions are perhaps arguable but revisiting them is well beyond the scope of what seemed possible to do as part of this project. However, it's relatively cheap to recompress as part of VACUUM FULL or CLUSTER, so this commit adjusts those commands to do so, if the configured compression method of the table happens not to match what was used for some column value stored therein. Dilip Kumar. The original patches on which this work was based were written by Ildus Kurbangaliev, and those were patches were based on even earlier work by Nikita Glukhov, but the design has since changed very substantially, since allow a potentially large number of compression methods that could be added and dropped on a running system proved too problematic given some of the architectural issues mentioned above; the choice of which specific compression method to add first is now different; and a lot of the code has been heavily refactored. More recently, Justin Przyby helped quite a bit with testing and reviewing and this version also includes some code contributions from him. Other design input and review from Tomas Vondra, Álvaro Herrera, Andres Freund, Oleg Bartunov, Alexander Korotkov, and me. Discussion: http://postgr.es/m/20170907194236.4cefce96%40wp.localdomain Discussion: http://postgr.es/m/CAFiTN-uUpX3ck%3DK0mLEk-G_kUQY%3DSNOTeqdaNRR9FMdQrHKebw%40mail.gmail.com Branch ------ master Details ------- https://git.postgresql.org/pg/commitdiff/bbe0a81db69bd10bd166907c3701492a29aca294 Modified Files -------------- configure | 170 ++++++++++++ configure.ac | 20 ++ contrib/amcheck/verify_heapam.c | 2 +- doc/src/sgml/catalogs.sgml | 12 + doc/src/sgml/func.sgml | 18 +- doc/src/sgml/ref/alter_table.sgml | 16 ++ doc/src/sgml/ref/create_table.sgml | 33 ++- doc/src/sgml/ref/psql-ref.sgml | 11 + src/backend/access/brin/brin_tuple.c | 5 +- src/backend/access/common/Makefile | 1 + src/backend/access/common/detoast.c | 77 +++--- src/backend/access/common/indextuple.c | 3 +- src/backend/access/common/toast_compression.c | 313 +++++++++++++++++++++ src/backend/access/common/toast_internals.c | 77 +++--- src/backend/access/common/tupdesc.c | 6 + src/backend/access/heap/heapam_handler.c | 40 +++ src/backend/access/table/toast_helper.c | 5 +- src/backend/bootstrap/bootstrap.c | 5 + src/backend/catalog/genbki.pl | 3 + src/backend/catalog/heap.c | 4 + src/backend/catalog/index.c | 1 + src/backend/catalog/toasting.c | 6 + src/backend/commands/tablecmds.c | 313 ++++++++++++++++++--- src/backend/nodes/copyfuncs.c | 1 + src/backend/nodes/equalfuncs.c | 1 + src/backend/nodes/nodeFuncs.c | 2 + src/backend/nodes/outfuncs.c | 1 + src/backend/parser/gram.y | 35 ++- src/backend/parser/parse_utilcmd.c | 9 + src/backend/replication/logical/reorderbuffer.c | 2 +- src/backend/utils/adt/varlena.c | 54 ++++ src/backend/utils/misc/guc.c | 12 + src/backend/utils/misc/postgresql.conf.sample | 1 + src/bin/pg_amcheck/t/004_verify_heapam.pl | 4 +- src/bin/pg_dump/pg_backup.h | 1 + src/bin/pg_dump/pg_dump.c | 39 +++ src/bin/pg_dump/pg_dump.h | 1 + src/bin/pg_dump/t/002_pg_dump.pl | 12 +- src/bin/psql/describe.c | 31 ++- src/bin/psql/help.c | 2 + src/bin/psql/settings.h | 1 + src/bin/psql/startup.c | 10 + src/bin/psql/tab-complete.c | 2 +- src/include/access/detoast.h | 10 - src/include/access/toast_compression.h | 123 +++++++++ src/include/access/toast_helper.h | 1 + src/include/access/toast_internals.h | 23 +- src/include/catalog/catversion.h | 2 +- src/include/catalog/pg_attribute.h | 8 +- src/include/catalog/pg_proc.dat | 4 + src/include/nodes/parsenodes.h | 3 + src/include/parser/kwlist.h | 1 + src/include/pg_config.h.in | 3 + src/include/postgres.h | 50 +++- src/test/regress/expected/compression.out | 347 ++++++++++++++++++++++++ src/test/regress/expected/compression_1.out | 340 +++++++++++++++++++++++ src/test/regress/parallel_schedule | 2 +- src/test/regress/pg_regress_main.c | 4 +- src/test/regress/serial_schedule | 1 + src/test/regress/sql/compression.sql | 136 ++++++++++ src/tools/msvc/Solution.pm | 1 + 61 files changed, 2261 insertions(+), 160 deletions(-)
pgsql-committers by date: