pgsql: Speed up in-memory tuplesorting.

Started by Robert Haasabout 14 years ago4 messageshackers
Jump to latest
#1Robert Haas
robertmhaas@gmail.com

Speed up in-memory tuplesorting.

Per recent work by Peter Geoghegan, it's significantly faster to
tuplesort on a single sortkey if ApplySortComparator is inlined into
quicksort rather reached via a function pointer. It's also faster
in general to have a version of quicksort which is specialized for
sorting SortTuple objects rather than objects of arbitrary size and
type. This requires a couple of additional copies of the quicksort
logic, which in this patch are generate using a Perl script. There
might be some benefit in adding further specializations here too,
but thus far it's not clear that those gains are worth their weight
in code footprint.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/337b6f5ecf05b21b5e997986884d097d60e4e3d0

Modified Files
--------------
src/backend/Makefile | 4 +-
src/backend/utils/sort/.gitignore | 1 +
src/backend/utils/sort/Makefile | 8 +
src/backend/utils/sort/gen_qsort_tuple.pl | 232 +++++++++++++++++++++++++++++
src/backend/utils/sort/tuplesort.c | 68 +++++----
src/port/qsort.c | 2 +-
src/port/qsort_arg.c | 2 +-
src/tools/msvc/Solution.pm | 8 +
8 files changed, 289 insertions(+), 36 deletions(-)

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Robert Haas (#1)
Re: [COMMITTERS] pgsql: Speed up in-memory tuplesorting.

Robert Haas <rhaas@postgresql.org> writes:

Speed up in-memory tuplesorting.

This patch appears to have broken those members of the buildfarm that
use VPATH builds. I assume you didn't think about the path to
qsort_tuple.c very carefully.

regards, tom lane

#3Robert Haas
robertmhaas@gmail.com
In reply to: Tom Lane (#2)
Re: [COMMITTERS] pgsql: Speed up in-memory tuplesorting.

On Wed, Feb 15, 2012 at 2:24 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Robert Haas <rhaas@postgresql.org> writes:

Speed up in-memory tuplesorting.

This patch appears to have broken those members of the buildfarm that
use VPATH builds.  I assume you didn't think about the path to
qsort_tuple.c very carefully.

So it appears. I copied the rule that modifies errcodes.h, but clearly
that's not enough. I think I might need to steal and adapt the
following logic from src/backend/catalog/Makefile:

# locations of headers that genbki.pl needs to read
pg_includes = -I$(top_srcdir)/src/include/catalog
-I$(top_builddir)/src/include/catalog

I'll go test that now.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company

#4Robert Haas
robertmhaas@gmail.com
In reply to: Robert Haas (#3)
Re: [COMMITTERS] pgsql: Speed up in-memory tuplesorting.

On Wed, Feb 15, 2012 at 2:54 PM, Robert Haas <robertmhaas@gmail.com> wrote:

On Wed, Feb 15, 2012 at 2:24 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:

Robert Haas <rhaas@postgresql.org> writes:

Speed up in-memory tuplesorting.

This patch appears to have broken those members of the buildfarm that
use VPATH builds.  I assume you didn't think about the path to
qsort_tuple.c very carefully.

So it appears. I copied the rule that modifies errcodes.h, but clearly
that's not enough.   I think I might need to steal and adapt the
following logic from src/backend/catalog/Makefile:

# locations of headers that genbki.pl needs to read
pg_includes = -I$(top_srcdir)/src/include/catalog
-I$(top_builddir)/src/include/catalog

I'll go test that now.

Nope, that's not it. Committed what seems to be the correct fix,
after testing it locally.

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company