Re: avoiding tuple copying in btree index builds

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Robert Haas <robertmhaas(at)gmail(dot)com>
Cc: Amit Kapila <amit(dot)kapila16(at)gmail(dot)com>, Andres Freund <andres(at)2ndquadrant(dot)com>, "pgsql-hackers(at)postgresql(dot)org" <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: avoiding tuple copying in btree index builds
Date: 2014-06-17 00:10:49
Message-ID: 26651.1402963849@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Robert Haas <robertmhaas(at)gmail(dot)com> writes:
> On further review, this is definitely the way to go: it's a
> straight-up win. The isnull array is never more than one element in
> length, so testing the single element is quite trivial. The
> attached, revised patch provides a modest but useful speedup for both
> hash and btree index builds.

> Anyone see any reason NOT to do this? So far it looks like a
> slam-dunk from here.

If index_form_tuple leaks any memory in the sort context, this would be
not so much a slam-dunk win as a complete disaster. I'm not sure that
no-leak is a safe assumption, especially in cases where we do toast
compression of the index datums. (In fact, I'm pretty sure that the
reason it was coded like this originally was exactly to avoid that
assumption.)

Assuming that you inspect the code and determine it's safe, the patch
had better decorate index_form_tuple with dire warnings about not leaking
memory; because even if it's safe today, somebody might break it tomorrow.

On a micro-optimization level, it might be worth passing the TID as
ItemPointer not ItemPointerData (ie, pass a pointer until we get to
the point of actually inserting the TID into the index tuple).
I'm not sure that copying odd-size structs should be assumed to be
efficient.

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message zhouqq.postgres@gmail.com 2014-06-17 00:20:03 Re: Built-in support for a memory consumption ulimit?
Previous Message Peter Geoghegan 2014-06-16 23:31:56 Re: Doing better at HINTing an appropriate column within errorMissingColumn()