Re: Direct Toast PoC
Re: Direct Toast PoC
On Wed, Jul 29, 2026 at 09:13:47PM +0200, Hannu Krosing wrote: > I would like to propose a design and prototype implementation for a new > TOAST format, which we are calling **Direct TOAST**. > Not a big change, just leaving out the index part. > Hopefully this gives TOAST another 25-30 years :) I am going to be honest here, but I think beginning a thread this way is sloppy. First, the entire email and its contents are entirely AI-generated, perhaps you have spent some time double-checking the contents of the message but it does not give this impression at all; at least you are being honest regarding the code by saying that you have *not looked at the code at all*. And even if the code is generated, looking at the result is the first thing you should try to do, especially if you are asking people to look at it. Relying on such tools is a trend these days, and that's fine because LLM models are tools and they can be terribly efficient when used well, but it does not change the review and lookup part (Postgres committers do that). Some people seem to have success with such tools, which is also fine. But please, if you plan to ask people to spend some time on what you are doing, the least you can do is to give the impression that you have yourself spent some time on the actual code. I cannot speak for others, but beginning a thread this way discourages me entirely to look at what you have sent. Okay, spoiler: I did look at the code, and your LLM has just been hard-coding a new vartag_external, plumbing it into the TOAST internals without caring about any concept of backward-compatibility. Posting patches based on HEAD and not a stable branch would be a better idea, as well, as a starter. I understand that this is a POC, still. Please do not take it bad, this is just my opinion. I think that time is the most important resource we have. It is limited. However, beginning a thread this way does not give the impression that you value the time of other people at all. My 2c. -- Michael
Re: Direct Toast PoC
От:
Nikita Malakhov <hukutoc@gmail.com>
Дата:
Hi Hannu!
Haven't looked at the code yet but want to mention - I've tried 'direct' approach some time ago [1]
using list-like representation. Despite giving speedup for relatively small values and does not having
TOAST index table at all, the performance degraded over standard TOAST with large ones,
and dependency on TIDs have the immediate effect of VACUUM FULL breaking the overall structure,
so it should be modified accordingly too.
Michael had already answered that, you could check out [1] for discussion.
On Thu, Jul 30, 2026 at 7:41 AM Michael Paquier <michael@paquier.xyz> wrote:
On Wed, Jul 29, 2026 at 09:13:47PM +0200, Hannu Krosing wrote:
> I would like to propose a design and prototype implementation for a new
> TOAST format, which we are calling **Direct TOAST**.
> Not a big change, just leaving out the index part.
> Hopefully this gives TOAST another 25-30 years :)
I am going to be honest here, but I think beginning a thread this way
is sloppy. First, the entire email and its contents are entirely
AI-generated, perhaps you have spent some time double-checking the
contents of the message but it does not give this impression at all;
at least you are being honest regarding the code by saying that you
have *not looked at the code at all*. And even if the code is
generated, looking at the result is the first thing you should try to
do, especially if you are asking people to look at it.
Relying on such tools is a trend these days, and that's fine because
LLM models are tools and they can be terribly efficient when used
well, but it does not change the review and lookup part (Postgres
committers do that). Some people seem to have success with such
tools, which is also fine. But please, if you plan to ask people to
spend some time on what you are doing, the least you can do is to give
the impression that you have yourself spent some time on the actual
code. I cannot speak for others, but beginning a thread this way
discourages me entirely to look at what you have sent.
Okay, spoiler: I did look at the code, and your LLM has just been
hard-coding a new vartag_external, plumbing it into the TOAST
internals without caring about any concept of backward-compatibility.
Posting patches based on HEAD and not a stable branch would be a
better idea, as well, as a starter. I understand that this is a POC,
still.
Please do not take it bad, this is just my opinion. I think that
time is the most important resource we have. It is limited. However,
beginning a thread this way does not give the impression that you
value the time of other people at all.
My 2c.
--
Michael
Re: Direct Toast PoC
От:
Nikita Malakhov <hukutoc@gmail.com>
Дата:
Hi!
I keep thinking about this. Hannu, have you thought about a mixed approach?
In [1] above Michael mentioned the very serious drawback of using direct TIDs -
while vacuuming the TOAST table we have to modify the original table as well,
so I don't see a way to avoid using some kind of index at all. My direct TOAST
patch was just a PoC to show it is possible.
On Thu, Jul 30, 2026 at 10:30 AM Hannu Krosing <hannuk@google.com> wrote:
Re-sending my last reply to the list
On Thu, Jul 30, 2026 at 8:24 AM Nikita Malakhov <hukutoc@gmail.com> wrote:
>
> Hi Hannu!
>
> Haven't looked at the code yet but want to mention - I've tried 'direct' approach some time ago [1]
> using list-like representation. Despite giving speedup for relatively small values and does not having
> TOAST index table at all, the performance degraded over standard TOAST with large ones,
For a linked list, this degradation was to be expected , as you can
only start requesting the next page once you have fetched the previous
one.
This is why I implemented it as tidarray (or N-ary tree of TID arrays
for larger data), which does not have this fundamental problem.
You get a large span of tids for pages at once, an could be at least
as fast as index scan and possibly faster, as you get the tid array
slightly cheaper
> and dependency on TIDs have the immediate effect of VACUUM FULL breaking the overall structure,
> so it should be modified accordingly too.
Yes, VACUUM FULL of the toast table is one known thing that has to be
modified for this
OTOH the current behaviour of VACUUM FULL is not even very useful for
fixing heavily out-of-order toast table anyway, as it just compacts
free space but does not do anything about putting the toasted fields
in same order as main heap fields, so your slow queries stay slow even
after VACUUM FULL.
Re: Direct Toast PoC
От:
Nikita Malakhov <hukutoc@gmail.com>
Дата:
I have to remind that currently there is no UPDATE implemented
for the TOASTed values, and TOAST replication is an issue too.
On Thu, Jul 30, 2026 at 11:25 AM Hannu Krosing <hannuk@google.com> wrote:
To recap the main goals for Direct Toast
Why do this
-----------
# performance
- 5% - 25% for in-memory vector queries withoutindexes for vector sizes where indexing isn'tpossible
- 2x for simple in-memory queries where fetchingfetching toast is a significant part of the work
- 1.5x to 100x for cases where toast index doesnot fit in memory the worst case would be afull table with an out-of-order index thatdoesn't fit in memory where each toasted fieldcauses an extra disk access for index.Assuming 1 ms for that the extra disk accessit adds 46 days to the full scan.I have not seen a dump or copy operation that long,but I have seen one taking over a week.
Chris Travers had some anecdotal evidence ofa case where sequential scans degraded tosingle-digit rows per second rows per secondon a database with large external SCSI arrays# no running out of OIDs at 4B
- added bonus - not slowing down finding scarcefree oids when close to 4B
# space savings
- if your toasted fields are smallthe index space usage can make up a significantportion of the data size
Migration
---------
As direct toast just adds one more VARATT pointer type
and does not change anything else it is fully backwards
compatible. The toast table format change is also backwards
compatible as it adds a field at the end of the tuple
VACUUM FULL needs to be modified to refuse to work on toast tables.CLUSTER already refuses as now the toast index is partial
VACUUM FULL and CLUSTER need to get an option to simultaneouslyalso rewrite toast table in main table row order.
Re: Direct Toast PoC
Yes, the fact that TOASTed values are fully replaced on update helped to keep the patch short :)
The physical replication should have no issues, as the patch just removes some operations when inserting or updating in direct mode.
Logical decoding indeed may need to change the toast lookup if it uses its own functions instead of the standard ones.
The physical replication should have no issues, as the patch just removes some operations when inserting or updating in direct mode.
Logical decoding indeed may need to change the toast lookup if it uses its own functions instead of the standard ones.
On Thu, Jul 30, 2026 at 11:47 AM Nikita Malakhov <hukutoc@gmail.com> wrote:
I have to remind that currently there is no UPDATE implementedfor the TOASTed values, and TOAST replication is an issue too.On Thu, Jul 30, 2026 at 11:25 AM Hannu Krosing <hannuk@google.com> wrote:To recap the main goals for Direct Toast
Why do this
-----------
# performance
- 5% - 25% for in-memory vector queries withoutindexes for vector sizes where indexing isn'tpossible
- 2x for simple in-memory queries where fetchingfetching toast is a significant part of the work
- 1.5x to 100x for cases where toast index doesnot fit in memory the worst case would be afull table with an out-of-order index thatdoesn't fit in memory where each toasted fieldcauses an extra disk access for index.Assuming 1 ms for that the extra disk accessit adds 46 days to the full scan.I have not seen a dump or copy operation that long,but I have seen one taking over a week.
Chris Travers had some anecdotal evidence ofa case where sequential scans degraded tosingle-digit rows per second rows per secondon a database with large external SCSI arrays# no running out of OIDs at 4B
- added bonus - not slowing down finding scarcefree oids when close to 4B
# space savings
- if your toasted fields are smallthe index space usage can make up a significantportion of the data size
Migration
---------
As direct toast just adds one more VARATT pointer type
and does not change anything else it is fully backwards
compatible. The toast table format change is also backwards
compatible as it adds a field at the end of the tuple
VACUUM FULL needs to be modified to refuse to work on toast tables.CLUSTER already refuses as now the toast index is partial
VACUUM FULL and CLUSTER need to get an option to simultaneouslyalso rewrite toast table in main table row order.--