From 48ef701fa9d14504870aefc75f5847efbfc495b4 Mon Sep 17 00:00:00 2001 From: Joshua Lockerman Date: Fri, 4 Oct 2019 15:01:20 -0400 Subject: [PATCH] Set toast_tuple_target to 128B when able We want compressed data to be stored out-of-line whenever possible so that the headers are colocated and scans on the metadata and segmentbys are cheap. This commit lowers toast_tuple_target to 128 bytes, so that more tables will have this occur; using the default size, very often a non-trivial portion of the data ends up in the main table, and only very few rows are stored in a page. --- tsl/src/compression/create.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tsl/src/compression/create.c b/tsl/src/compression/create.c index d1b30c9d6..e244470fe 100644 --- a/tsl/src/compression/create.c +++ b/tsl/src/compression/create.c @@ -495,6 +495,26 @@ set_statistics_on_compressed_table(Oid compressed_table_id) RelationClose(table_rel); } +#if !PG96 && !PG10 +static void +set_toast_tuple_target_on_compressed(Oid compressed_table_id) +{ + DefElem def_elem = { + .type = T_DefElem, + .defname = "toast_tuple_target", + .arg = (Node *) makeInteger(128), + .defaction = DEFELEM_SET, + .location = -1, + }; + AlterTableCmd cmd = { + .type = T_AlterTableCmd, + .subtype = AT_SetRelOptions, + .def = (Node *) list_make1(&def_elem), + }; + AlterTableInternal(compressed_table_id, list_make1(&cmd), true); +} +#endif + static int32 create_compression_table(Oid owner, CompressColInfo *compress_cols) { @@ -540,6 +560,10 @@ create_compression_table(Oid owner, CompressColInfo *compress_cols) set_statistics_on_compressed_table(compress_relid); +#if !PG96 && !PG10 + set_toast_tuple_target_on_compressed(compress_relid); +#endif + create_compressed_table_indexes(compress_relid, compress_cols); return compress_hypertable_id; }