Re: BUG #19548: Missing dependency between a graph edge and the related PK
Re: BUG #19548: Missing dependency between a graph edge and the related PK
От:
Ayoub Kazar <kazarayoub2004@gmail.com>
Дата:
Hi Christophe,
On Thu, Jul 16, 2026 at 12:38 PM PG Bug reporting form <noreply@postgresql.org> wrote:
The following bug has been logged on the website:
Bug reference: 19548
Logged by: Christophe Courtois
Email address: christophe.courtois@dalibo.com
PostgreSQL version: 19beta1
Operating system: Linux Debian 13
Description:
Hi,
A dependency between a graph and the PK of a relationship
seems to be missing.
In the following example, a PK on the edge table is compulsory,
but this PK can be cascade-dropped and the graph is unchanged.
The graph can be dropped later,
but it cannot be recreated :
ERROR: no key specified and no suitable primary key exists for definition
of element "family"
I imagine that a pg_restore will fail too.
Tested on 19~beta2-1~20260629.2015.g9cfd19bc10a.pgdg13+1 from
apt.postgresql.org
and 20devel freshly compiled.
Full example :
-- persons
CREATE TABLE persons (
id TEXT PRIMARY KEY,
nom TEXT,
sexe TEXT
);
CREATE TABLE family (
id TEXT PRIMARY KEY,
spouse1 TEXT REFERENCES persons(id),
spouse2 TEXT REFERENCES persons(id)
);
CREATE PROPERTY GRAPH wedding
VERTEX TABLES (
persons KEY (id) PROPERTIES ALL COLUMNS
)
EDGE TABLES (
family
SOURCE KEY (spouse1) REFERENCES persons (id)
DESTINATION KEY (spouse2) REFERENCES persons (id)
);
-- Drop the constraint
-- CASCADE does NOT get rid if the graph
ALTER TABLE family DROP CONSTRAINT family_pkey CASCADE ;
-- The graph is still there
\dG+
-- Recreation fails
DROP PROPERTY GRAPH wedding ;
CREATE PROPERTY GRAPH wedding
VERTEX TABLES (
persons KEY (id) PROPERTIES ALL COLUMNS
)
EDGE TABLES (
family
SOURCE KEY (spouse1) REFERENCES persons (id)
DESTINATION KEY (spouse2) REFERENCES persons (id)
);
ERROR: no key specified and no suitable primary key exists for definition
of element "family"
LINE 6: family
I checked with Oracle as well to see the behavior and i can confirm its the same (its a standard thing, see below).
The KEY, either explicit or implicit through the PK is used just at graph definition time: the catalog just keeps the column numbers in the relative graph element table (in your case, the family table). There's no dependency kept.
See:
select * from pg_propgraph_element;
oid | pgepgid | pgerelid | pgealias | pgekind | pgesrcvertexid | pgedestvertexid | pgekey | pgesrckey | pgesrcref | pgesrceqop | pgedestkey | pgedestref | pgedesteqop
-------+---------+----------+----------+---------+----------------+-----------------+--------+-----------+-----------+------------+------------+------------+-------------
25282 | 25281 | 25259 | persons | v | 0 | 0 | {1} | | | | | |
25291 | 25281 | 25265 | family | e | 25282 | 25282 | {1} | {2} | {1} | {96} | {3} | {1} | {96}
(2 rows)
oid | pgepgid | pgerelid | pgealias | pgekind | pgesrcvertexid | pgedestvertexid | pgekey | pgesrckey | pgesrcref | pgesrceqop | pgedestkey | pgedestref | pgedesteqop
-------+---------+----------+----------+---------+----------------+-----------------+--------+-----------+-----------+------------+------------+------------+-------------
25282 | 25281 | 25259 | persons | v | 0 | 0 | {1} | | | | | |
25291 | 25281 | 25265 | family | e | 25282 | 25282 | {1} | {2} | {1} | {96} | {3} | {1} | {96}
(2 rows)
If a PK was used (your case), it's to deduce what columns uniquely identify the edge table. What's required is either a KEY clause or an existing PK on the element table.
The standard itself doesn't mention keeping the dependency (i argue it should); it only talks about the different cases of the graph element table's key.
Regards,
Ayoub Kazar
Re: BUG #19548: Missing dependency between a graph edge and the related PK
От:
Peter Eisentraut <peter@eisentraut.org>
Дата:
On 16.07.26 14:13, Ayoub Kazar wrote: > I checked with Oracle as well to see the behavior and i can confirm its > the same (its a standard thing, see below). > > The KEY, either explicit or implicit through the PK is used just at > graph definition time: the catalog just keeps the column numbers in the > relative graph element table (in your case, the family table). There's > no dependency kept. Correct. The current behavior is intentional.
Re: BUG #19548: Missing dependency between a graph edge and the related PK
От:
Christophe Courtois <christophe.courtois@dalibo.com>
Дата:
Le 16/07/2026 à 14:13, Ayoub Kazar a écrit :
> Hi Christophe,
>
> On Thu, Jul 16, 2026 at 12:38 PM PG Bug reporting form
> > wrote:
>
> The following bug has been logged on the website:
>
> Bug reference: 19548
> Logged by: Christophe Courtois
> Email address: christophe.courtois@dalibo.com
>
> PostgreSQL version: 19beta1
> Operating system: Linux Debian 13
> Description:
>
> Hi,
>
> A dependency between a graph and the PK of a relationship
> seems to be missing.
>
> In the following example, a PK on the edge table is compulsory,
> but this PK can be cascade-dropped and the graph is unchanged.
>
> The graph can be dropped later,
> but it cannot be recreated :
> ERROR: no key specified and no suitable primary key exists for
> definition
> of element "family"
>
> I imagine that a pg_restore will fail too.
>
> Tested on 19~beta2-1~20260629.2015.g9cfd19bc10a.pgdg13+1 from
> apt.postgresql.org
> and 20devel freshly compiled.
>
> Full example :
>
> -- persons
> CREATE TABLE persons (
> id TEXT PRIMARY KEY,
> nom TEXT,
> sexe TEXT
> );
>
> CREATE TABLE family (
> id TEXT PRIMARY KEY,
> spouse1 TEXT REFERENCES persons(id),
> spouse2 TEXT REFERENCES persons(id)
> );
>
> CREATE PROPERTY GRAPH wedding
> VERTEX TABLES (
> persons KEY (id) PROPERTIES ALL COLUMNS
> )
> EDGE TABLES (
> family
> SOURCE KEY (spouse1) REFERENCES persons (id)
> DESTINATION KEY (spouse2) REFERENCES persons (id)
> );
>
> -- Drop the constraint
> -- CASCADE does NOT get rid if the graph
>
> ALTER TABLE family DROP CONSTRAINT family_pkey CASCADE ;
>
> -- The graph is still there
>
> \dG+
>
> -- Recreation fails
>
> DROP PROPERTY GRAPH wedding ;
>
> CREATE PROPERTY GRAPH wedding
> VERTEX TABLES (
> persons KEY (id) PROPERTIES ALL COLUMNS
> )
> EDGE TABLES (
> family
> SOURCE KEY (spouse1) REFERENCES persons (id)
> DESTINATION KEY (spouse2) REFERENCES persons (id)
> );
> ERROR: no key specified and no suitable primary key exists for
> definition
> of element "family"
> LINE 6: family
>
>
>
>
>
>
>
> I checked with Oracle as well to see the behavior and i can confirm its
> the same (its a standard thing, see below).
>
> The KEY, either explicit or implicit through the PK is used just at
> graph definition time: the catalog just keeps the column numbers in the
> relative graph element table (in your case, the family table). There's
> no dependency kept.
>
> See:
>
> select * from pg_propgraph_element;
> oid | pgepgid | pgerelid | pgealias | pgekind | pgesrcvertexid |
> pgedestvertexid | pgekey | pgesrckey | pgesrcref | pgesrceqop |
> pgedestkey | pgedestref | pgedesteqop
> -------+---------+----------+----------+---------+----------------
> +-----------------+--------+-----------+-----------+------------
> +------------+------------+-------------
> 25282 | 25281 | 25259 | persons | v | 0 |
> 0 | {1} | | | |
> | |
> 25291 | 25281 | 25265 | family | e | 25282 |
> 25282 | {1} | {2} | {1} | {96} | {3}
> | {1} | {96}
> (2 rows)
>
>
> If a PK was used (your case), it's to deduce what columns uniquely
> identify the edge table. What's required is either a KEY clause or an
> existing PK on the element table.
>
> The standard itself doesn't mention keeping the dependency (i argue it
> should); it only talks about the different cases of the graph element
> table's key.
Thanks for the explanation!
In fact I can see in pg_get_propgraphdef() that the graph definition is
correctly stored with a KEY (id).
I should have checked the result of pg_dump/pg_restore,
I would have probably found this explanation.
Sorry for the noise.
Yours,
SELECT pg_get_propgraphdef ('wedding'::regclass);
pg_get_propgraphdef
----------------------------------------------------------------------------------------------------------------------------------------------------------
CREATE PROPERTY GRAPH public.wedding
+
VERTEX TABLES (
+
persons KEY (id) PROPERTIES (id, nom, sexe)
+
)
+
EDGE TABLES (
+
family KEY (id) SOURCE KEY (spouse1) REFERENCES persons (id)
DESTINATION KEY (spouse2) REFERENCES persons (id) PROPERTIES (id,
spouse1, spouse2)+
)
--
_________ ____
| || | Christophe Courtois
| ||__ | Consultant DALIBO
| | | | 43, rue du Faubourg Montmartre
| - | / / 75009 Paris
|___| |___| \/ www.dalibo.com
Re: Direct TOAST v2, faster, smaller and no migration needed
От:
Nikita Malakhov <hukutoc@gmail.com>
Дата:
Hi Hannu!
Great you're continuing this work! I've started to review your patch set,
and have question about tests and performance: have you tested it against
large toasted values? When experimenting with direct toast before my prototype
was much faster on small values but starting with relatively large (have to recover
previous test results so cannot say exact size), about tens of Mbs, performance
starts to degrade and on very large values it is much slower compared to the original
mechanics.
Re: Direct TOAST v2, faster, smaller and no migration needed
On Mon, Sep 7, 2026 at 9:45 AM Nikita Malakhov wrote:
>
> Hi Hannu!
>
> Great you're continuing this work! I've started to review your patch set,
> and have question about tests and performance: have you tested it against
> large toasted values? When experimenting with direct toast before my prototype
> was much faster on small values but starting with relatively large (have to recover
> previous test results so cannot say exact size), about tens of Mbs, performance
> starts to degrade and on very large values it is much slower compared to the original
> mechanics.
Hi, here is a guick tests inserting 10 rows of 1MB, 10MB and 100MB text datums
Direct toast is consistently faster by 7 to 15% on writes
datum size | plain | direct | speed-up
-------------------------------------------
1 MB | 58 | 54 | 7.4%
10 MB | 568 | 495 | 14.7%
100 MB | 6821 | 6139 | 11.1%
1000 MB | 64363 | 58763 | 9.5%
On the read side they are the same when the toast index fits in
memory, varying less than a percent between runs
select id, length(data) from largedirecttoast where id between 21 and
30; -> 19 ms
select id, length(data) from largedirecttoast where id between 21 and
30; -> 183 ms
select id, length(data) from largedirecttoast where id between 21 and
30; -> 1920 ms
For 1GB rows the above select was 2x slower on plain, 47 s vs 23 sec on direct
Here is what I tested:
dtoast=# create table largedirecttoast(id serial primary key, data
text storage external) with (toast_flavour=direct);
CREATE TABLE
Time: 4.351 ms
dtoast=# create table largeplaintoast(id serial primary key, data text
storage external) with (toast_flavour=plain);
CREATE TABLE
Time: 4.269 ms
dtoast=# with large as (SELECT repeat('abcdefghij', 100000) as datum1m)
insert into largeplaintoast(data) select large.datum1m from large,
generate_series(1,10);
INSERT 0 10
Time: 58.330 ms
dtoast=# with large as (SELECT repeat('abcdefghij', 100000) as datum1m)
insert into largedirecttoast(data) select large.datum1m from large,
generate_series(1,10);
INSERT 0 10
Time: 54.280 ms
dtoast=# with large as (SELECT repeat('abcdefghij', 1000000) as datum10m)
insert into largeplaintoast(data) select large.datum10m from large,
generate_series(1,10);
INSERT 0 10
Time: 567.808 ms
dtoast=# with large as (SELECT repeat('abcdefghij', 1000000) as datum10m)
insert into largedirecttoast(data) select large.datum10m from large,
generate_series(1,10);
INSERT 0 10
Time: 494.823 ms
dtoast=# with large as (SELECT repeat('abcdefghij', 10000000) as datum100m)
insert into largeplaintoast(data) select large.datum100m from large,
generate_series(1,10);
INSERT 0 10
Time: 6820.868 ms (00:06.821)
dtoast=# with large as (SELECT repeat('abcdefghij', 10000000) as datum100m)
insert into largedirecttoast(data) select large.datum100m from large,
generate_series(1,10);
INSERT 0 10
Time: 6138.979 ms (00:06.139)
dtoast=# with large as (SELECT repeat('abcdefghij', 100000000) as datum1000m)
insert into largedirecttoast(data) select large.datum1000m from large,
generate_series(1,10);
INSERT 0 10
Time: 58763.165 ms (00:58.763)
dtoast=# with large as (SELECT repeat('abcdefghij', 100000000) as datum1000m)
insert into largeplaintoast(data) select large.datum1000m from large,
generate_series(1,10);
INSERT 0 10
Time: 64363.909 ms (01:04.364)
....
dtoast=# select id, length(data) from largedirecttoast where id
between 31 and 40;
id │ length
────┼────────────
31 │ 1000000000
32 │ 1000000000
33 │ 1000000000
34 │ 1000000000
35 │ 1000000000
36 │ 1000000000
37 │ 1000000000
38 │ 1000000000
39 │ 1000000000
40 │ 1000000000
(10 rows)
Time: 22981.708 ms (00:22.982)
dtoast=# select id, length(data) from largeplaintoast where id between
31 and 40;
id │ length
────┼────────────
31 │ 1000000000
32 │ 1000000000
33 │ 1000000000
34 │ 1000000000
35 │ 1000000000
36 │ 1000000000
37 │ 1000000000
38 │ 1000000000
39 │ 1000000000
40 │ 1000000000
(10 rows)
Time: 47346.034 ms (00:47.346)
Re: Direct TOAST v2, faster, smaller and no migration needed
The slowness of 1GB datum test in previous email is likely just
because of more levels in toast inex, as it should fit well into
shared buffers
table_name │ table_size │ toast_table_size │ toast_index_size │
──────────────────────────┼──────────────┼──────────────────┼──────────────────┼
public.largeplaintoast │ 11527708672 │ 11399487488 │ 125042688 │
public.largedirecttoast │ 11495727104 │ 11492515840 │ 8192 │
Time: 8.935 ms
dtoast=# show shared_buffers;
shared_buffers
────────────────
8GB
(1 row)
On Mon, Sep 7, 2026 at 10:47 AM Hannu Krosing wrote:
>
> On Mon, Sep 7, 2026 at 9:45 AM Nikita Malakhov wrote:
> >
> > Hi Hannu!
> >
> > Great you're continuing this work! I've started to review your patch set,
> > and have question about tests and performance: have you tested it against
> > large toasted values? When experimenting with direct toast before my prototype
> > was much faster on small values but starting with relatively large (have to recover
> > previous test results so cannot say exact size), about tens of Mbs, performance
> > starts to degrade and on very large values it is much slower compared to the original
> > mechanics.
>
> Hi, here is a guick tests inserting 10 rows of 1MB, 10MB and 100MB text datums
>
> Direct toast is consistently faster by 7 to 15% on writes
>
> datum size | plain | direct | speed-up
> -------------------------------------------
> 1 MB | 58 | 54 | 7.4%
> 10 MB | 568 | 495 | 14.7%
> 100 MB | 6821 | 6139 | 11.1%
> 1000 MB | 64363 | 58763 | 9.5%
>
> On the read side they are the same when the toast index fits in
> memory, varying less than a percent between runs
>
> select id, length(data) from largedirecttoast where id between 21 and
> 30; -> 19 ms
> select id, length(data) from largedirecttoast where id between 21 and
> 30; -> 183 ms
> select id, length(data) from largedirecttoast where id between 21 and
> 30; -> 1920 ms
>
> For 1GB rows the above select was 2x slower on plain, 47 s vs 23 sec on direct
>
>
> Here is what I tested:
>
> dtoast=# create table largedirecttoast(id serial primary key, data
> text storage external) with (toast_flavour=direct);
> CREATE TABLE
> Time: 4.351 ms
> dtoast=# create table largeplaintoast(id serial primary key, data text
> storage external) with (toast_flavour=plain);
> CREATE TABLE
> Time: 4.269 ms
> dtoast=# with large as (SELECT repeat('abcdefghij', 100000) as datum1m)
> insert into largeplaintoast(data) select large.datum1m from large,
> generate_series(1,10);
> INSERT 0 10
> Time: 58.330 ms
> dtoast=# with large as (SELECT repeat('abcdefghij', 100000) as datum1m)
> insert into largedirecttoast(data) select large.datum1m from large,
> generate_series(1,10);
> INSERT 0 10
> Time: 54.280 ms
> dtoast=# with large as (SELECT repeat('abcdefghij', 1000000) as datum10m)
> insert into largeplaintoast(data) select large.datum10m from large,
> generate_series(1,10);
> INSERT 0 10
> Time: 567.808 ms
> dtoast=# with large as (SELECT repeat('abcdefghij', 1000000) as datum10m)
> insert into largedirecttoast(data) select large.datum10m from large,
> generate_series(1,10);
> INSERT 0 10
> Time: 494.823 ms
> dtoast=# with large as (SELECT repeat('abcdefghij', 10000000) as datum100m)
> insert into largeplaintoast(data) select large.datum100m from large,
> generate_series(1,10);
> INSERT 0 10
> Time: 6820.868 ms (00:06.821)
> dtoast=# with large as (SELECT repeat('abcdefghij', 10000000) as datum100m)
> insert into largedirecttoast(data) select large.datum100m from large,
> generate_series(1,10);
> INSERT 0 10
> Time: 6138.979 ms (00:06.139)
> dtoast=# with large as (SELECT repeat('abcdefghij', 100000000) as datum1000m)
> insert into largedirecttoast(data) select large.datum1000m from large,
> generate_series(1,10);
> INSERT 0 10
> Time: 58763.165 ms (00:58.763)
> dtoast=# with large as (SELECT repeat('abcdefghij', 100000000) as datum1000m)
> insert into largeplaintoast(data) select large.datum1000m from large,
> generate_series(1,10);
> INSERT 0 10
> Time: 64363.909 ms (01:04.364)
> ....
> dtoast=# select id, length(data) from largedirecttoast where id
> between 31 and 40;
> id │ length
> ────┼────────────
> 31 │ 1000000000
> 32 │ 1000000000
> 33 │ 1000000000
> 34 │ 1000000000
> 35 │ 1000000000
> 36 │ 1000000000
> 37 │ 1000000000
> 38 │ 1000000000
> 39 │ 1000000000
> 40 │ 1000000000
> (10 rows)
>
> Time: 22981.708 ms (00:22.982)
> dtoast=# select id, length(data) from largeplaintoast where id between
> 31 and 40;
> id │ length
> ────┼────────────
> 31 │ 1000000000
> 32 │ 1000000000
> 33 │ 1000000000
> 34 │ 1000000000
> 35 │ 1000000000
> 36 │ 1000000000
> 37 │ 1000000000
> 38 │ 1000000000
> 39 │ 1000000000
> 40 │ 1000000000
> (10 rows)
>
> Time: 47346.034 ms (00:47.346)
Re: Direct TOAST v2, faster, smaller and no migration needed
От:
Hannu Krosing <hannuk@google.com>
Дата:
Also, truncate was faster on direct toast
dtoast=# truncate table largedirecttoast;
TRUNCATE TABLE
Time: 891.392 ms
dtoast=# truncate table largeplaintoast;
TRUNCATE TABLE
Time: 1193.535 ms (00:01.194)
On Mon, Sep 7, 2026 at 10:54 AM Hannu Krosing wrote:
>
> The slowness of 1GB datum test in previous email is likely just
> because of more levels in toast inex, as it should fit well into
> shared buffers
>
> table_name │ table_size │ toast_table_size │ toast_index_size │
> ──────────────────────────┼──────────────┼──────────────────┼──────────────────┼
> public.largeplaintoast │ 11527708672 │ 11399487488 │ 125042688 │
> public.largedirecttoast │ 11495727104 │ 11492515840 │ 8192 │
>
> Time: 8.935 ms
> dtoast=# show shared_buffers;
> shared_buffers
> ────────────────
> 8GB
> (1 row)
>
> On Mon, Sep 7, 2026 at 10:47 AM Hannu Krosing wrote:
> >
> > On Mon, Sep 7, 2026 at 9:45 AM Nikita Malakhov wrote:
> > >
> > > Hi Hannu!
> > >
> > > Great you're continuing this work! I've started to review your patch set,
> > > and have question about tests and performance: have you tested it against
> > > large toasted values? When experimenting with direct toast before my prototype
> > > was much faster on small values but starting with relatively large (have to recover
> > > previous test results so cannot say exact size), about tens of Mbs, performance
> > > starts to degrade and on very large values it is much slower compared to the original
> > > mechanics.
> >
> > Hi, here is a guick tests inserting 10 rows of 1MB, 10MB and 100MB text datums
> >
> > Direct toast is consistently faster by 7 to 15% on writes
> >
> > datum size | plain | direct | speed-up
> > -------------------------------------------
> > 1 MB | 58 | 54 | 7.4%
> > 10 MB | 568 | 495 | 14.7%
> > 100 MB | 6821 | 6139 | 11.1%
> > 1000 MB | 64363 | 58763 | 9.5%
> >
> > On the read side they are the same when the toast index fits in
> > memory, varying less than a percent between runs
> >
> > select id, length(data) from largedirecttoast where id between 21 and
> > 30; -> 19 ms
> > select id, length(data) from largedirecttoast where id between 21 and
> > 30; -> 183 ms
> > select id, length(data) from largedirecttoast where id between 21 and
> > 30; -> 1920 ms
> >
> > For 1GB rows the above select was 2x slower on plain, 47 s vs 23 sec on direct
> >
> >
> > Here is what I tested:
> >
> > dtoast=# create table largedirecttoast(id serial primary key, data
> > text storage external) with (toast_flavour=direct);
> > CREATE TABLE
> > Time: 4.351 ms
> > dtoast=# create table largeplaintoast(id serial primary key, data text
> > storage external) with (toast_flavour=plain);
> > CREATE TABLE
> > Time: 4.269 ms
> > dtoast=# with large as (SELECT repeat('abcdefghij', 100000) as datum1m)
> > insert into largeplaintoast(data) select large.datum1m from large,
> > generate_series(1,10);
> > INSERT 0 10
> > Time: 58.330 ms
> > dtoast=# with large as (SELECT repeat('abcdefghij', 100000) as datum1m)
> > insert into largedirecttoast(data) select large.datum1m from large,
> > generate_series(1,10);
> > INSERT 0 10
> > Time: 54.280 ms
> > dtoast=# with large as (SELECT repeat('abcdefghij', 1000000) as datum10m)
> > insert into largeplaintoast(data) select large.datum10m from large,
> > generate_series(1,10);
> > INSERT 0 10
> > Time: 567.808 ms
> > dtoast=# with large as (SELECT repeat('abcdefghij', 1000000) as datum10m)
> > insert into largedirecttoast(data) select large.datum10m from large,
> > generate_series(1,10);
> > INSERT 0 10
> > Time: 494.823 ms
> > dtoast=# with large as (SELECT repeat('abcdefghij', 10000000) as datum100m)
> > insert into largeplaintoast(data) select large.datum100m from large,
> > generate_series(1,10);
> > INSERT 0 10
> > Time: 6820.868 ms (00:06.821)
> > dtoast=# with large as (SELECT repeat('abcdefghij', 10000000) as datum100m)
> > insert into largedirecttoast(data) select large.datum100m from large,
> > generate_series(1,10);
> > INSERT 0 10
> > Time: 6138.979 ms (00:06.139)
> > dtoast=# with large as (SELECT repeat('abcdefghij', 100000000) as datum1000m)
> > insert into largedirecttoast(data) select large.datum1000m from large,
> > generate_series(1,10);
> > INSERT 0 10
> > Time: 58763.165 ms (00:58.763)
> > dtoast=# with large as (SELECT repeat('abcdefghij', 100000000) as datum1000m)
> > insert into largeplaintoast(data) select large.datum1000m from large,
> > generate_series(1,10);
> > INSERT 0 10
> > Time: 64363.909 ms (01:04.364)
> > ....
> > dtoast=# select id, length(data) from largedirecttoast where id
> > between 31 and 40;
> > id │ length
> > ────┼────────────
> > 31 │ 1000000000
> > 32 │ 1000000000
> > 33 │ 1000000000
> > 34 │ 1000000000
> > 35 │ 1000000000
> > 36 │ 1000000000
> > 37 │ 1000000000
> > 38 │ 1000000000
> > 39 │ 1000000000
> > 40 │ 1000000000
> > (10 rows)
> >
> > Time: 22981.708 ms (00:22.982)
> > dtoast=# select id, length(data) from largeplaintoast where id between
> > 31 and 40;
> > id │ length
> > ────┼────────────
> > 31 │ 1000000000
> > 32 │ 1000000000
> > 33 │ 1000000000
> > 34 │ 1000000000
> > 35 │ 1000000000
> > 36 │ 1000000000
> > 37 │ 1000000000
> > 38 │ 1000000000
> > 39 │ 1000000000
> > 40 │ 1000000000
> > (10 rows)
> >
> > Time: 47346.034 ms (00:47.346)
Re: Direct TOAST v2, faster, smaller and no migration needed
От:
Hannu Krosing <hannuk@google.com>
Дата:
Вложения:
The latest patch set, now includes patch to pruning to treat a TOAST tuple with NULL chunk_id as if it had HEAP_ONLY_TUPLE set and release it immediately.
I am running some tests on both this (in classic and direct toast mode) and the OID8 toast to write up a better comparison
I am running some tests on both this (in classic and direct toast mode) and the OID8 toast to write up a better comparison
Re: Direct TOAST v2, faster, smaller and no migration needed
От:
Hannu Krosing <hannuk@google.com>
Дата:
Вложения:
A few more fixes to pass CI tests
Re: Direct TOAST v2, faster, smaller and no migration needed
От:
Hannu Krosing <hannuk@google.com>
Дата:
Вложения:
and another one to account for recently committed OID8 TOAST On Mon, Sep 21, 2026 at 2:11 PM Hannu Krosing wrote: > > A few more fixes to pass CI tests
Re: Direct TOAST v2, faster, smaller and no migration needed
От:
Hannu Krosing <hannuk@google.com>
Дата:
Вложения:
one more round On Mon, Sep 21, 2026 at 5:02 PM Hannu Krosing wrote: > > and another one to account for recently committed OID8 TOAST > > On Mon, Sep 21, 2026 at 2:11 PM Hannu Krosing wrote: > > > > A few more fixes to pass CI tests
Re: Direct TOAST v2, faster, smaller and no migration needed
От:
Andres Freund <andres@anarazel.de>
Дата:
On 2026-09-21 20:29:14 +0200, Hannu Krosing wrote: > one more round Please just run CI on your own repo. Sending a patchset three times in a day, to thousands of people, just to see CI results, is ... not a scalable approach.
Re: Direct TOAST v2, faster, smaller and no migration needed
От:
Hannu Krosing <hannuk@google.com>
Дата:
Is there a way to make sure that it actually runs the same way? The reason I have been sending it is that the tests do pass locally, even the ones that fail in CI and I have been trying to figure out why On Mon, Sep 21, 2026 at 8:49 PM Andres Freund wrote: > > On 2026-09-21 20:29:14 +0200, Hannu Krosing wrote: > > one more round > > Please just run CI on your own repo. Sending a patchset three times in a day, > to thousands of people, just to see CI results, is ... not a scalable approach.
Re: Direct TOAST v2, faster, smaller and no migration needed
От:
Tomas Vondra <tomas@vondra.me>
Дата:
On 9/21/26 22:01, Hannu Krosing wrote: > Is there a way to make sure that it actually runs the same way? > > The reason I have been sending it is that the tests do pass locally, > even the ones that fail in CI and I have been trying to figure out why > That's why Andres was suggesting you enable CI on your github repo, in which case you'll be able to debug the failures there. It's also possible to investigate the logs from cfbot runs, by clicking on the link in cfbot: https://github.com/postgres/postgres-cfbot/actions/runs/35639175676/attempts/1 From a cursory look, I guess there's a couple compiler warnings due to toast_decompress_datum now being unused, etc. Some of the failures seem to be caused by lz4 being the default TOAST on some of the machines (and you seem to expect pglz). Haven't looked further. regards -- Tomas Vondra
Re: Direct TOAST v2, faster, smaller and no migration needed
От:
shihao zhong <zhong950419@gmail.com>
Дата:
Hi Hannu,
On Mon, Sep 21, 2026 at 10:01 PM Hannu Krosing <hannuk@google.com> wrote:
> Is there a way to make sure that it actually runs the same way?
Yes. cfbot runs the GitHub Actions workflow that is in the tree, so
your own fork runs the same jobs. Push the branch to your fork, enable
pg-ci.yml under Actions, and add a repository variable PG_CI_ENABLED
with the value 1. It is all in src/tools/ci/README.
> The reason I have been sending it is that the tests do pass locally,
> even the ones that fail in CI and I have been trying to figure out why
That is usually a platform you do not build on, like 32 bit, Windows
or the autoconf build, or a warning your local compiler does not
report.
Regards,
Shihao
On Mon, Sep 21, 2026 at 10:01 PM Hannu Krosing <hannuk@google.com> wrote:
> Is there a way to make sure that it actually runs the same way?
Yes. cfbot runs the GitHub Actions workflow that is in the tree, so
your own fork runs the same jobs. Push the branch to your fork, enable
pg-ci.yml under Actions, and add a repository variable PG_CI_ENABLED
with the value 1. It is all in src/tools/ci/README.
> The reason I have been sending it is that the tests do pass locally,
> even the ones that fail in CI and I have been trying to figure out why
That is usually a platform you do not build on, like 32 bit, Windows
or the autoconf build, or a warning your local compiler does not
report.
Regards,
Shihao
Re: Direct TOAST v2, faster, smaller and no migration needed
От:
Hannu Krosing <hannuk@google.com>
Дата:
On Mon, Sep 21, 2026 at 10:12 PM shihao zhong wrote: > > Hi Hannu, > > On Mon, Sep 21, 2026 at 10:01 PM Hannu Krosing wrote: > > > Is there a way to make sure that it actually runs the same way? > Yes. cfbot runs the GitHub Actions workflow that is in the tree, so > your own fork runs the same jobs. Thanks a lot! That was the missing piece :) > Push the branch to your fork, enable > pg-ci.yml under Actions, and add a repository variable PG_CI_ENABLED > with the value 1. It is all in src/tools/ci/README. Regards Hannu
Re: Direct TOAST v2, faster, smaller and no migration needed
От:
Hannu Krosing <hannuk@google.com>
Дата:
Вложения:
Now the CI passes in my repo (https://github.com/postsql/postgres/actions/runs/35711192304) On Mon, Sep 21, 2026 at 10:21 PM Hannu Krosing wrote: > > On Mon, Sep 21, 2026 at 10:12 PM shihao zhong wrote: > > > > Hi Hannu, > > > > On Mon, Sep 21, 2026 at 10:01 PM Hannu Krosing wrote: > > > > > Is there a way to make sure that it actually runs the same way? > > Yes. cfbot runs the GitHub Actions workflow that is in the tree, so > > your own fork runs the same jobs. > > Thanks a lot! > > That was the missing piece :) > > > Push the branch to your fork, enable > > pg-ci.yml under Actions, and add a repository variable PG_CI_ENABLED > > with the value 1. It is all in src/tools/ci/README. > > Regards > Hannu
Re: Direct TOAST v2, faster, smaller and no migration needed
От:
Hannu Krosing <hannuk@google.com>
Дата:
Вложения:
[PATCH v10 0/9] Direct TOAST: bypass TOAST B-Tree index via physical TIDs
============================================================
Hello hackers,
Here is version 10 of the Direct TOAST patch set.
Direct TOAST introduces an alternative out-of-line varlena storage format
that bypasses the traditional TOAST B-Tree index scans during reads and index
insertions during writes by embedding physical TIDs directly in the varlena
pointer (varatt_direct) and within hierarchical chunk trees.
This update addresses several concurrency, resource safety, and permission
invariants identified during recent reviews, and adds interrupt checks and
recursion guards across chunk traversal paths.
The updated branch is also pushed to:
https://github.com/postsql/postgres/tree/direct-toast-submission
Key Changes in v10
==================
1. Superuser Privilege Check for In-Place Upgrades
- Added an explicit superuser check (superuser()) in pg_ensure_direct_toast()
before modifying catalog state. Only superusers may alter TOAST table
metadata and mark TOAST indexes partial.
- Added regression test coverage in direct_toast.sql / direct_toast.out
verifying that unprivileged roles receive ERRCODE_INSUFFICIENT_PRIVILEGE.
2. Relation Locking and Transaction Lifetime Invariants
- In ensure_direct_toast(), upgraded the target relation lock from
AccessShareLock to ShareUpdateExclusiveLock while catalog columns and
index predicates are being modified, preventing concurrent conflicting
schema modifications.
- Followed standard backend conventions by using table_close(..., NoLock) on
both the target relation and toast relation in ensure_direct_toast(),
ensuring locks are held until transaction commit rather than released
prematurely.
- In toast_delete_datum_direct(), changed table_close(toastrel,
RowExclusiveLock)
to table_close(toastrel, NoLock) to avoid premature lock release/downgrade
before the transaction finishes.
3. Safe Buffer Pin Cleanup on Corrupted Chunk Error Paths
- In toast_fetch_datum_slice() (detoast.c), explicitly call
ReleaseBuffer(buffer)
before invoking elog(ERROR, ...) on unexpected NULL chunk data or corrupted
chunk headers, preventing buffer pin leaks during error recovery.
4. Recursion Depth Protection (Stack Safety)
- Added check_stack_depth() calls to all recursive chunk tree traversals:
* toast_fetch_datum_direct_slice_recursive() in detoast.c
* toast_delete_datum_direct_recursive() in toast_internals.c
* check_toasted_attribute_direct_recursive() in
contrib/amcheck/verify_heapam.c
5. Interrupt Responsiveness in Iteration Loops
- Added CHECK_FOR_INTERRUPTS() in chunk iteration loops across the backend
to ensure statement timeouts and cancel requests (SIGINT) are processed
promptly when processing very large TOAST DAGs:
* Multi-chunk tree slice traversal in detoast.c
* Direct chunk deletion loop in toast_internals.c
* Logical decoding chunk reconstruction in reorderbuffer.c
* Recursive child verification loop in contrib/amcheck/verify_heapam.c
6. Pointer Size Documentation and Static Assertions
- Updated varatt.h and README.toast to document that sizeof(varatt_direct)
is 20 bytes (matching varatt_external_oid8 due to 2 bytes of trailing
compiler struct alignment padding), resulting in a 22-byte on-disk
external varlena header.
- Added a compile-time StaticAssertDecl on sizeof(varatt_direct) to ensure
struct layout invariants are enforced across platforms.
Patch Series Overview (v10)
===========================
v10-0001: Refactor detoasting and decompression pipeline to unify full and
slice operations.
v10-0002: Add Direct TOAST catalog, GUC, and reloptions infrastructure.
v10-0003: Implement Direct TOAST core storage reading and writing (flat array
and hierarchical tree DAG, recursive slicing, deletion).
v10-0004: Support Direct TOAST in logical decoding, replication, and online
REPACK.
v10-0005: Add amcheck verification for Direct TOAST tuples (verify_heapam).
v10-0006: Add documentation for Direct TOAST.
v10-0007: Add pg_ensure_direct_toast for in-place legacy TOAST table upgrade.
v10-0008: Add backend TOAST architecture documentation and clean up detoast
access.
v10-0009: Prune dead unindexed TOAST tuples directly to LP_UNUSED
during VACUUM.
Testing & Verification
======================
The patch series builds cleanly under GCC and Clang with:
CFLAGS="-O2 -ggdb -fsanitize=alignment,undefined -fno-sanitize-recover=all"
CPPFLAGS="-DRELCACHE_FORCE_RELEASE
-DENFORCE_REGRESSION_TEST_NAME_RESTRICTIONS"
--enable-cassert --enable-injection-points --enable-tap-tests
Verification results:
- make check in src/test/regress: 240/240 tests passed (including
direct_toast).
- make check in contrib/amcheck: 4 regression tests and 6 TAP suites (298/298
tests) passed.
- make check in src/test/modules/injection_points: 4 regression tests and
15 isolation tests (including repack_direct_toast) passed.
- Server log audit confirmed zero buffer refcount leaks, zero cache leaks,
and zero resource warnings under RELCACHE_FORCE_RELEASE.
Feedback and review are warmly welcome.
Best regards,
Hannu
Re: Direct TOAST v2, faster, smaller and no migration needed
От:
Hannu Krosing <hannuk@google.com>
Дата:
Вложения:
Rebased
Conflict resolved in Commit 0001 (detoast.c): Upstream commit
e27f3b2cad7 ("Remove duplicate definition of the compressed varlena
header") replaced TOAST_COMPRESS_METHOD / TOAST_COMPRESS_EXTSIZE with
VARDATA_COMPRESSED_GET_COMPRESS_METHOD /
VARDATA_COMPRESSED_GET_EXTSIZE. Resolved in
toast_decompress_datum_slice() to use
VARDATA_COMPRESSED_GET_COMPRESS_METHOD(attr).
On Fri, Sep 25, 2026 at 8:49 AM Hannu Krosing wrote:
>
> [PATCH v10 0/9] Direct TOAST: bypass TOAST B-Tree index via physical TIDs
> ============================================================
>
> Hello hackers,
>
> Here is version 10 of the Direct TOAST patch set.
>
> Direct TOAST introduces an alternative out-of-line varlena storage format
> that bypasses the traditional TOAST B-Tree index scans during reads and index
> insertions during writes by embedding physical TIDs directly in the varlena
> pointer (varatt_direct) and within hierarchical chunk trees.
>
> This update addresses several concurrency, resource safety, and permission
> invariants identified during recent reviews, and adds interrupt checks and
> recursion guards across chunk traversal paths.
>
> The updated branch is also pushed to:
> https://github.com/postsql/postgres/tree/direct-toast-submission
>
>
> Key Changes in v10
> ==================
>
> 1. Superuser Privilege Check for In-Place Upgrades
> - Added an explicit superuser check (superuser()) in pg_ensure_direct_toast()
> before modifying catalog state. Only superusers may alter TOAST table
> metadata and mark TOAST indexes partial.
> - Added regression test coverage in direct_toast.sql / direct_toast.out
> verifying that unprivileged roles receive ERRCODE_INSUFFICIENT_PRIVILEGE.
>
> 2. Relation Locking and Transaction Lifetime Invariants
> - In ensure_direct_toast(), upgraded the target relation lock from
> AccessShareLock to ShareUpdateExclusiveLock while catalog columns and
> index predicates are being modified, preventing concurrent conflicting
> schema modifications.
> - Followed standard backend conventions by using table_close(..., NoLock) on
> both the target relation and toast relation in ensure_direct_toast(),
> ensuring locks are held until transaction commit rather than released
> prematurely.
> - In toast_delete_datum_direct(), changed table_close(toastrel,
> RowExclusiveLock)
> to table_close(toastrel, NoLock) to avoid premature lock release/downgrade
> before the transaction finishes.
>
> 3. Safe Buffer Pin Cleanup on Corrupted Chunk Error Paths
> - In toast_fetch_datum_slice() (detoast.c), explicitly call
> ReleaseBuffer(buffer)
> before invoking elog(ERROR, ...) on unexpected NULL chunk data or corrupted
> chunk headers, preventing buffer pin leaks during error recovery.
>
> 4. Recursion Depth Protection (Stack Safety)
> - Added check_stack_depth() calls to all recursive chunk tree traversals:
> * toast_fetch_datum_direct_slice_recursive() in detoast.c
> * toast_delete_datum_direct_recursive() in toast_internals.c
> * check_toasted_attribute_direct_recursive() in
> contrib/amcheck/verify_heapam.c
>
> 5. Interrupt Responsiveness in Iteration Loops
> - Added CHECK_FOR_INTERRUPTS() in chunk iteration loops across the backend
> to ensure statement timeouts and cancel requests (SIGINT) are processed
> promptly when processing very large TOAST DAGs:
> * Multi-chunk tree slice traversal in detoast.c
> * Direct chunk deletion loop in toast_internals.c
> * Logical decoding chunk reconstruction in reorderbuffer.c
> * Recursive child verification loop in contrib/amcheck/verify_heapam.c
>
> 6. Pointer Size Documentation and Static Assertions
> - Updated varatt.h and README.toast to document that sizeof(varatt_direct)
> is 20 bytes (matching varatt_external_oid8 due to 2 bytes of trailing
> compiler struct alignment padding), resulting in a 22-byte on-disk
> external varlena header.
> - Added a compile-time StaticAssertDecl on sizeof(varatt_direct) to ensure
> struct layout invariants are enforced across platforms.
>
>
> Patch Series Overview (v10)
> ===========================
>
> v10-0001: Refactor detoasting and decompression pipeline to unify full and
> slice operations.
> v10-0002: Add Direct TOAST catalog, GUC, and reloptions infrastructure.
> v10-0003: Implement Direct TOAST core storage reading and writing (flat array
> and hierarchical tree DAG, recursive slicing, deletion).
> v10-0004: Support Direct TOAST in logical decoding, replication, and online
> REPACK.
> v10-0005: Add amcheck verification for Direct TOAST tuples (verify_heapam).
> v10-0006: Add documentation for Direct TOAST.
> v10-0007: Add pg_ensure_direct_toast for in-place legacy TOAST table upgrade.
> v10-0008: Add backend TOAST architecture documentation and clean up detoast
> access.
> v10-0009: Prune dead unindexed TOAST tuples directly to LP_UNUSED
> during VACUUM.
>
>
> Testing & Verification
> ======================
>
> The patch series builds cleanly under GCC and Clang with:
> CFLAGS="-O2 -ggdb -fsanitize=alignment,undefined -fno-sanitize-recover=all"
> CPPFLAGS="-DRELCACHE_FORCE_RELEASE
> -DENFORCE_REGRESSION_TEST_NAME_RESTRICTIONS"
> --enable-cassert --enable-injection-points --enable-tap-tests
>
> Verification results:
> - make check in src/test/regress: 240/240 tests passed (including
> direct_toast).
> - make check in contrib/amcheck: 4 regression tests and 6 TAP suites (298/298
> tests) passed.
> - make check in src/test/modules/injection_points: 4 regression tests and
> 15 isolation tests (including repack_direct_toast) passed.
> - Server log audit confirmed zero buffer refcount leaks, zero cache leaks,
> and zero resource warnings under RELCACHE_FORCE_RELEASE.
>
> Feedback and review are warmly welcome.
>
> Best regards,
> Hannu