Skip site navigation (1) Skip section navigation (2)

pgsql: Speed up operations on numeric,mostly by avoiding palloc() over

From: Heikki Linnakangas <heikki(dot)linnakangas(at)iki(dot)fi>
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: Speed up operations on numeric,mostly by avoiding palloc() over
Date: 2012-11-21 14:05:04
Message-ID: E1TbAvI-0001Ze-Qx@gemulon.postgresql.org (view raw or flat)
Thread:
Lists: pgsql-committers
Speed up operations on numeric, mostly by avoiding palloc() overhead.

In many functions, a NumericVar was initialized from an input Numeric, to be
passed as input to a calculation function. When the NumericVar is not
modified, the digits array of the NumericVar can point directly to the digits
array in the original Numeric, and we can avoid a palloc() and memcpy(). Add
init_var_from_num() function to initialize a var like that.

Remove dscale argument from get_str_from_var(), as all the callers just
passed the dscale of the variable. That means that the rounding it used to
do was not actually necessary, and get_str_from_var() no longer scribbles on
its input. That makes it safer in general, and allows us to use the new
init_var_from_num() function in e.g numeric_out().

Also modified numericvar_to_int8() to no scribble on its input either. It
creates a temporary copy to avoid that. To compensate, the callers no longer
need to create a temporary copy, so the net # of pallocs is the same, but this
is nicer.

In the passing, use a constant for the number 10 in get_str_from_var_sci(),
when calculating 10^exponent. Saves a palloc() and some cycles to convert
integer 10 to numeric.

Original patch by Kyotaro HORIGUCHI, with further changes by me. Reviewed
by Pavel Stehule.

Branch
------
master

Details
-------
http://git.postgresql.org/pg/commitdiff/5cb0e335976befdcedd069c59dd3858fb3e649b3

Modified Files
--------------
src/backend/utils/adt/numeric.c |  259 ++++++++++++++++-----------------------
1 files changed, 104 insertions(+), 155 deletions(-)

pgsql-committers by date

Next:From: Tom LaneDate: 2012-11-21 20:19:43
Subject: pgsql: Don't launch new child processes after we've been told to shutd
Previous:From: Tom LaneDate: 2012-11-20 02:22:34
Subject: pgsql: Improve handling of INT_MIN / -1 and related cases.

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group