Skip to content

Commit

Permalink
Merge pull request yugabyte#50 from koordinates/include-unchanged-toast
Browse files Browse the repository at this point in the history
Preserve unchanged toast values by default.

This commit introduces a behavior change since TOAST values will always be output from now on. If you want the previous behavior, add include-unchanged-toast=0.
  • Loading branch information
Euler Taveira de Oliveira authored Mar 27, 2018
2 parents 34a3666 + 947043e commit ce82d73
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 26 deletions.
3 changes: 1 addition & 2 deletions expected/bytea.out

Large diffs are not rendered by default.

44 changes: 25 additions & 19 deletions expected/toast.out

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion sql/bytea.sql
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ INSERT INTO xpto (bincol) SELECT decode(string_agg(to_char(round(g.i * random())
UPDATE xpto SET rand1 = 123.456 WHERE id = 1;
DELETE FROM xpto WHERE id = 1;

SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'pretty-print', '1', 'include-typmod', '0');
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'pretty-print', '1', 'include-typmod', '0', 'include-unchanged-toast', '0');
SELECT 'stop' FROM pg_drop_replication_slot('regression_slot');
6 changes: 5 additions & 1 deletion sql/toast.sql
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ UPDATE xpto SET toasted_col1 = (SELECT string_agg(g.i::text, '') FROM generate_s

UPDATE xpto SET rand1 = 123.456 WHERE id = 1;

DELETE FROM xpto WHERE id = 1;
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'pretty-print', '1', 'include-typmod', '0', 'include-unchanged-toast', '0');

UPDATE xpto SET rand1 = 234.567 WHERE id = 1;

-- include-unchanged-toast=1 is the default
SELECT data FROM pg_logical_slot_get_changes('regression_slot', NULL, NULL, 'pretty-print', '1', 'include-typmod', '0');

SELECT 'stop' FROM pg_drop_replication_slot('regression_slot');
21 changes: 18 additions & 3 deletions wal2json.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ typedef struct
bool include_type_oids; /* include data type oids */
bool include_typmod; /* include typmod in types */
bool include_not_null; /* include not-null constraints */
bool include_unchanged_toast; /* include unchanged TOAST field values in output */

bool pretty_print; /* pretty-print JSON? */
bool write_in_chunks; /* write in chunks? */
Expand Down Expand Up @@ -134,6 +135,7 @@ pg_decode_startup(LogicalDecodingContext *ctx, OutputPluginOptions *opt, bool is
data->write_in_chunks = false;
data->include_lsn = false;
data->include_not_null = false;
data->include_unchanged_toast = true;
data->filter_tables = NIL;

/* add all tables in all schemas by default */
Expand Down Expand Up @@ -336,6 +338,19 @@ pg_decode_startup(LogicalDecodingContext *ctx, OutputPluginOptions *opt, bool is
pfree(rawstr);
}
}
else if (strcmp(elem->defname, "include-unchanged-toast") == 0)
{
if (elem->arg == NULL)
{
elog(LOG, "include-unchanged-toast is null");
data->include_unchanged_toast = true;
}
else if (!parse_bool(strVal(elem->arg), &data->include_unchanged_toast))
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("could not parse value \"%s\" for parameter \"%s\"",
strVal(elem->arg), elem->defname)));
}
else
{
ereport(ERROR,
Expand Down Expand Up @@ -598,10 +613,10 @@ tuple_to_stringinfo(LogicalDecodingContext *ctx, TupleDesc tupdesc, HeapTuple tu
if (isnull && replident)
continue;

/* XXX Unchanged TOAST Datum does not need to be output */
if (!isnull && typisvarlena && VARATT_IS_EXTERNAL_ONDISK(origval))
if (!isnull && typisvarlena && VARATT_IS_EXTERNAL_ONDISK(origval) && !(data->include_unchanged_toast))
{
elog(WARNING, "column \"%s\" has an unchanged TOAST", NameStr(attr->attname));
/* With include-unchanged-toast=0, unchanged TOAST Datum do not need to be output */
elog(DEBUG1, "column \"%s\" has an unchanged TOAST - excluding", NameStr(attr->attname));
continue;
}

Expand Down

0 comments on commit ce82d73

Please sign in to comment.