From: Sokolov Yura <funny.falcon@postgrespro.ru>
To: Alvaro Herrera <alvherre@2ndquadrant.com>
Cc: Heikki Linnakangas <hlinnaka@iki.fi>
Cc: pgsql-hackers@postgresql.org, Heikki Linnakangas <hlinnaka@gmail.com>
Cc: pgsql-hackers-owner@postgresql.org
Subject: Re: Small improvement to compactify_tuples
Date: Fri, 21 Jul 2017 13:49:40 +0300
Message-ID: <9c4bc2ff302be669717101bc33127fd0@postgrespro.ru> (raw)
In-Reply-To: <468f371fe05c1de09c4dc101435ef93d@postgrespro.ru>
References: <20170515171331.taa44gjbc7p3aaul@alvherre.pgsql>
<468f371fe05c1de09c4dc101435ef93d@postgrespro.ru>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-hackers>
On 2017-05-17 17:46, Sokolov Yura wrote:
> Alvaro Herrera писал 2017-05-15 20:13:
>> As I understand, these patches are logically separate, so putting them
>> together in a single file isn't such a great idea. If you don't edit
>> the patches further, then you're all set because we already have the
>> previously archived patches. Next commitfest starts in a few months
>> yet, and if you feel the need to submit corrected versions in the
>> meantime, please do submit in separate files. (Some would even argue
>> that each should be its own thread, but I don't think that's
>> necessary.)
>
> Thank you for explanation.
>
> I'm adding new version of first patch with minor improvement:
> - I added detection of a case when all buckets are trivial
> (ie 0 or 1 element). In this case no need to sort buckets at all.
I'm putting rebased version of second patch.
--
Sokolov Yura aka funny_falcon
Postgres Professional: https://postgrespro.ru
The Russian Postgres Company
--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackersAttachments:
[text/x-diff] 0002-Simplify-PageRepairFragmentation.patch (3.5K, ../9c4bc2ff302be669717101bc33127fd0@postgrespro.ru/2-0002-Simplify-PageRepairFragmentation.patch)
download | inline diff:
From 3ae5aa0401fc5028cc916d55c4b18e53bf6aa9fb Mon Sep 17 00:00:00 2001
From: Sokolov Yura <funny.falcon@postgrespro.ru>
Date: Mon, 15 May 2017 16:04:14 +0300
Subject: [PATCH 2/2] Simplify PageRepairFragmentation
In assumption that page usually doesn't become empty, merge second loop
body (collecting items with storage) into first (counting kinds of
items).
---
src/backend/storage/page/bufpage.c | 47 +++++++++++++++-----------------------
1 file changed, 19 insertions(+), 28 deletions(-)
diff --git a/src/backend/storage/page/bufpage.c b/src/backend/storage/page/bufpage.cindex f28f18cff3..77cef51d02 100644--- a/src/backend/storage/page/bufpage.c+++ b/src/backend/storage/page/bufpage.c@@ -497,6 +497,7 @@ sort_itemIds(itemIdSort itemidbase, int nitems)
if (max == 1)
goto end;
+
/*
* count[k+2] is start of bucket k, count[k+1] is end of bucket k, and
* count[k+1]-count[k+2] is length of bucket k.
@@ -563,10 +564,11 @@ PageRepairFragmentation(Page page)
Offset pd_special = ((PageHeader) page)->pd_special;
ItemId lp;
int nline,
- nstorage,
nunused;
int i;
Size totallen;
+ itemIdSortData itemidbase[MaxHeapTuplesPerPage];+ itemIdSort itemidptr = itemidbase;
/*
* It's worth the trouble to be more paranoid here than in most places,
@@ -586,14 +588,26 @@ PageRepairFragmentation(Page page)
pd_lower, pd_upper, pd_special)));
nline = PageGetMaxOffsetNumber(page);
- nunused = nstorage = 0;+ nunused = totallen = 0;
for (i = FirstOffsetNumber; i <= nline; i++)
{
lp = PageGetItemId(page, i);
if (ItemIdIsUsed(lp))
{
if (ItemIdHasStorage(lp))
- nstorage++;+ {+ itemidptr->offsetindex = i - 1;+ itemidptr->itemoff = ItemIdGetOffset(lp);+ if (unlikely(itemidptr->itemoff < (int) pd_upper ||+ itemidptr->itemoff >= (int) pd_special))+ ereport(ERROR,+ (errcode(ERRCODE_DATA_CORRUPTED),+ errmsg("corrupted item pointer: %u",+ itemidptr->itemoff)));+ itemidptr->alignedlen = MAXALIGN(ItemIdGetLength(lp));+ totallen += itemidptr->alignedlen;+ itemidptr++;+ }
}
else
{
@@ -603,7 +617,7 @@ PageRepairFragmentation(Page page)
}
}
- if (nstorage == 0)+ if (itemidptr == itemidbase)
{
/* Page is completely empty, so just reset it quickly */
((PageHeader) page)->pd_upper = pd_special;
@@ -611,36 +625,13 @@ PageRepairFragmentation(Page page)
else
{
/* Need to compact the page the hard way */
- itemIdSortData itemidbase[MaxHeapTuplesPerPage];- itemIdSort itemidptr = itemidbase;-- totallen = 0;- for (i = 0; i < nline; i++)- {- lp = PageGetItemId(page, i + 1);- if (ItemIdHasStorage(lp))- {- itemidptr->offsetindex = i;- itemidptr->itemoff = ItemIdGetOffset(lp);- if (itemidptr->itemoff < (int) pd_upper ||- itemidptr->itemoff >= (int) pd_special)- ereport(ERROR,- (errcode(ERRCODE_DATA_CORRUPTED),- errmsg("corrupted item pointer: %u",- itemidptr->itemoff)));- itemidptr->alignedlen = MAXALIGN(ItemIdGetLength(lp));- totallen += itemidptr->alignedlen;- itemidptr++;- }- }-
if (totallen > (Size) (pd_special - pd_lower))
ereport(ERROR,
(errcode(ERRCODE_DATA_CORRUPTED),
errmsg("corrupted item lengths: total %u, available space %u",
(unsigned int) totallen, pd_special - pd_lower)));
- compactify_tuples(itemidbase, nstorage, page);+ compactify_tuples(itemidbase, (int) (itemidptr - itemidbase), page);
}
/* Set hint bit for PageAddItem */
--
2.11.0
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-hackers@postgresql.org
Cc: funny.falcon@postgrespro.ru, alvherre@2ndquadrant.com, hlinnaka@iki.fi, hlinnaka@gmail.com, pgsql-hackers-owner@postgresql.org
Subject: Re: Small improvement to compactify_tuples
In-Reply-To: <9c4bc2ff302be669717101bc33127fd0@postgrespro.ru>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox