pgsql: Create TOAST table for partitions made by MERGE/SPLIT PARTITION

From: Alexander Korotkov <akorotkov(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Create TOAST table for partitions made by MERGE/SPLIT PARTITION
Date: 2026-06-18 07:30:29
Message-ID: E1wa7Cm-000q78-2f@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

Create TOAST table for partitions made by MERGE/SPLIT PARTITION

ALTER TABLE ... MERGE PARTITIONS / SPLIT PARTITION builds a new
partition via createPartitionTable(), but never gives it a TOAST table.
When the source rows carried out-of-line varlena values, the move
into the new partition entered heap_toast_insert_or_update() with
reltoastrelid = InvalidOid: the externalization step is skipped, the
value falls back to inline storage and heap_insert() fails with
"row is too big" error. Also, TOAST table is needed if the new partition
receives out-of-line varlena values after the DDL operation is complete.

Call NewRelationCreateToastTable() right after the new partition is
created in createPartitionTable(), mirroring what DefineRelation()
does for regular CREATE TABLE. NewRelationCreateToastTable() decides
on its own whether a TOAST table is actually required, so partitions
with no toast-eligible columns are unaffected.

Reported-by: Justin Pryzby <pryzby(at)telsasoft(dot)com>
Discussion: https://postgr.es/m/ai_c4-v8iLA2kXFV%40pryzbyj2023
Reviewed-by: Pavel Borisov <pashkin(dot)elfe(at)gmail(dot)com>
Reviewed-by: Jian He <jian(dot)universality(at)gmail(dot)com>

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/ff8bec8c460a13bedbb416d8697f4675a0709ce8

Modified Files
--------------
src/backend/commands/tablecmds.c | 9 ++++++++
src/test/regress/expected/partition_merge.out | 26 +++++++++++++++++++++++
src/test/regress/expected/partition_split.out | 30 +++++++++++++++++++++++++++
src/test/regress/sql/partition_merge.sql | 17 +++++++++++++++
src/test/regress/sql/partition_split.sql | 19 +++++++++++++++++
5 files changed, 101 insertions(+)

Browse pgsql-committers by date

  From Date Subject
Next Message Andrew Dunstan 2026-06-18 13:42:33 pgsql: Revert non-text output formats for pg_dumpall
Previous Message Amit Langote 2026-06-18 06:57:04 pgsql: Report undefined jsonpath variable when no variables are supplie