pgsql: Tweak TOAST code so that columns marked with MAIN storage

Lists: pgsql-committerspgsql-hackers
From: tgl(at)postgresql(dot)org (Tom Lane)
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Tweak TOAST code so that columns marked with MAIN storage
Date: 2009-07-22 01:21:22
Message-ID: 20090722012122.5F9E275331E@cvs.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers pgsql-hackers

Log Message:
-----------
Tweak TOAST code so that columns marked with MAIN storage strategy are
not forced out-of-line unless that is necessary to make the row fit on a
page. Previously, they were forced out-of-line if needed to get the row
down to the default target size (1/4th page).

Kevin Grittner

Modified Files:
--------------
pgsql/doc/src/sgml:
storage.sgml (r1.29 -> r1.30)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/doc/src/sgml/storage.sgml?r1=1.29&r2=1.30)
pgsql/src/backend/access/heap:
tuptoaster.c (r1.93 -> r1.94)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/backend/access/heap/tuptoaster.c?r1=1.93&r2=1.94)
pgsql/src/include/access:
tuptoaster.h (r1.43 -> r1.44)
(http://anoncvs.postgresql.org/cvsweb.cgi/pgsql/src/include/access/tuptoaster.h?r1=1.43&r2=1.44)


From: Simon Riggs <simon(at)2ndQuadrant(dot)com>
To: Tom Lane <tgl(at)postgresql(dot)org>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: TOAST code ignores freespace (was Tweak TOAST code)
Date: 2010-05-02 12:45:45
Message-ID: 1272804345.4161.31190.camel@ebony
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers pgsql-hackers

On Wed, 2009-07-22 at 01:21 +0000, Tom Lane wrote:

> Tweak TOAST code so that columns marked with MAIN storage strategy are
> not forced out-of-line unless that is necessary to make the row fit on a
> page. Previously, they were forced out-of-line if needed to get the row
> down to the default target size (1/4th page).

A comment from Selena made me notice this patch from last year.

I notice that this patch might result in longer rows in the heap, which
in many cases is good. For updates, it can result in a row too large to
fit on the current block and for us to move block to one in which it
will fit.

Not commenting further on that patch, but I notice that when we UPDATE
the toasting algorithm takes no account of the available freespace on
the current block. If we are updating and the space available would make
a difference to the row length chosen, it seems like it would be more
beneficial to trim the row and encourage HOT updates.

--
Simon Riggs www.2ndQuadrant.com


From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Simon Riggs <simon(at)2ndQuadrant(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: TOAST code ignores freespace (was Tweak TOAST code)
Date: 2010-05-02 14:34:43
Message-ID: 10783.1272810883@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers pgsql-hackers

Simon Riggs <simon(at)2ndQuadrant(dot)com> writes:
> Not commenting further on that patch, but I notice that when we UPDATE
> the toasting algorithm takes no account of the available freespace on
> the current block. If we are updating and the space available would make
> a difference to the row length chosen, it seems like it would be more
> beneficial to trim the row and encourage HOT updates.

That doesn't strike me as a terribly good idea: it would make the
behavior of TOAST significantly more difficult to predict. Also, what
happens if we force a row to a smaller size and then it doesn't fit
anyway (eg because someone else inserted another row on the page while
we were busy doing this)? Spend even more cycles to un-toast back to
the normal size, to be consistent with ordinary cross-page updates?

Pretty much every previous discussion of tweaking the TOAST behavior
has focused on giving the user more control (indeed, the patch you
mention could be seen as doing that). What you're suggesting here
would give the user less control, as well as less predictability.

regards, tom lane


From: Simon Riggs <simon(at)2ndQuadrant(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: TOAST code ignores freespace (was Tweak TOAST code)
Date: 2010-05-02 15:20:55
Message-ID: 1272813656.4161.31585.camel@ebony
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers pgsql-hackers

On Sun, 2010-05-02 at 10:34 -0400, Tom Lane wrote:
> Simon Riggs <simon(at)2ndQuadrant(dot)com> writes:
> > Not commenting further on that patch, but I notice that when we UPDATE
> > the toasting algorithm takes no account of the available freespace on
> > the current block. If we are updating and the space available would make
> > a difference to the row length chosen, it seems like it would be more
> > beneficial to trim the row and encourage HOT updates.
>
> That doesn't strike me as a terribly good idea: it would make the
> behavior of TOAST significantly more difficult to predict. Also, what
> happens if we force a row to a smaller size and then it doesn't fit
> anyway (eg because someone else inserted another row on the page while
> we were busy doing this)? Spend even more cycles to un-toast back to
> the normal size, to be consistent with ordinary cross-page updates?
>
> Pretty much every previous discussion of tweaking the TOAST behavior
> has focused on giving the user more control (indeed, the patch you
> mention could be seen as doing that). What you're suggesting here
> would give the user less control, as well as less predictability.

As long as we've considered it, I'm happy either way. You know I'm
happier with more user control.

--
Simon Riggs www.2ndQuadrant.com


From: Jan Wieck <JanWieck(at)Yahoo(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Simon Riggs <simon(at)2ndQuadrant(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: TOAST code ignores freespace (was Tweak TOAST code)
Date: 2010-05-04 03:36:24
Message-ID: 4BDF9638.9090501@Yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers pgsql-hackers

On 5/2/2010 10:34 AM, Tom Lane wrote:
> Simon Riggs <simon(at)2ndQuadrant(dot)com> writes:
>> Not commenting further on that patch, but I notice that when we UPDATE
>> the toasting algorithm takes no account of the available freespace on
>> the current block. If we are updating and the space available would make
>> a difference to the row length chosen, it seems like it would be more
>> beneficial to trim the row and encourage HOT updates.
>
> That doesn't strike me as a terribly good idea: it would make the
> behavior of TOAST significantly more difficult to predict. Also, what
> happens if we force a row to a smaller size and then it doesn't fit
> anyway (eg because someone else inserted another row on the page while
> we were busy doing this)? Spend even more cycles to un-toast back to
> the normal size, to be consistent with ordinary cross-page updates?
>
> Pretty much every previous discussion of tweaking the TOAST behavior
> has focused on giving the user more control (indeed, the patch you
> mention could be seen as doing that). What you're suggesting here
> would give the user less control, as well as less predictability.

Correct. And on top of that, the cost/benefit of the proposed change
will be extremely hard to evaluate since freespace and the value of HOT
depend very much on access patterns.

If we want to substantially do better, we need to use a bigger hammer.

TOAST's largest performance benefit lies in the fact that it reduces the
size of the main tuple, which is the data that travels in intermediate
result sets throughout the executor. Reducing that size results in
smaller sort sets, more in memory operations, fewer blocks seqscanned
for keys and all that.

Suppose we had something similar to the NULL value bitmap, specifying
plain or compressed values (not TOAST references), that are moved to a
shadow tuple inside the toast table. Suppose further we had some
statistics about how often attributes appear in a qualification (i.e.
end up in a scan key or scan filter or other parts of the qual
expression list). Not sure, maybe we even want to know how often or
seldom an attribute is heap_getattr()'d at all. Those don't need to be
accurate counts. Small random samples will probably do. ANALYZE could
evaluate those statistics and adjust the "shadow" storage settings per
attribute accordingly.

I can imagine many applications, where this would shrink the main tuples
to almost nothing at all.

There are for sure a lot of "if's" and "suppose" in the above and the
impact of a fundamental on disk storage format change needs to be
justified by a really big gain. And yes, Simon, this also depends a lot
on access patterns. But if you try to gain more from TOAST, I'd look for
something like this instead of making the target tuple size dynamic.

Jan

--
Anyone who trades liberty for security deserves neither
liberty nor security. -- Benjamin Franklin


From: Simon Riggs <simon(at)2ndQuadrant(dot)com>
To: Jan Wieck <JanWieck(at)Yahoo(dot)com>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: TOAST code ignores freespace (was Tweak TOAST code)
Date: 2010-05-04 08:14:25
Message-ID: 1272960865.4535.325.camel@ebony
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-committers pgsql-hackers

On Mon, 2010-05-03 at 23:36 -0400, Jan Wieck wrote:

> Suppose we had something similar to the NULL value bitmap, specifying
> plain or compressed values (not TOAST references), that are moved to a
> shadow tuple inside the toast table. Suppose further we had some
> statistics about how often attributes appear in a qualification (i.e.
> end up in a scan key or scan filter or other parts of the qual
> expression list). Not sure, maybe we even want to know how often or
> seldom an attribute is heap_getattr()'d at all. Those don't need to be
> accurate counts. Small random samples will probably do. ANALYZE could
> evaluate those statistics and adjust the "shadow" storage settings per
> attribute accordingly.
>
> I can imagine many applications, where this would shrink the main
> tuples to almost nothing at all.

Automatic vertical partitioning. Like it.

TODO item for further detailed research.

--
Simon Riggs www.2ndQuadrant.com