From: | Karel Zak - Zakkr <zakkr(at)zf(dot)jcu(dot)cz> |
---|---|
To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | Don Baccus <dhogaza(at)pacifier(dot)com>, pgsql-hackers <pgsql-hackers(at)postgreSQL(dot)org> |
Subject: | Re: [HACKERS] memory dilemma |
Date: | 1999-12-28 10:28:22 |
Message-ID: | Pine.LNX.3.96.991228102949.12706B-100000@ara.zf.jcu.cz |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Mon, 27 Dec 1999, Tom Lane wrote:
> That isn't necessarily an impressive demonstration --- what is the data
> type of your "d" column? Four of the six variants of date_part() are
> implemented as SQL functions, which naturally adds a lot of overhead...
Sorry. I better describe problem now.
The test-table 'tab':
CRAETE TABLE tab (d datetime);
The 'tab' contain _random_ datetime values (generate via my program
rand_datetime - it is in PG's contrib/dateformat/test). In this table
is 10000 rows.
Test:
time psql test -c "select d from tab;" -o /dev/null
real 0m0.530s
user 0m0.060s
sys 0m0.020s
time psql test -c "select date_part('second', d) from tab;" -o /dev/null
real 0m0.494s
user 0m0.060s
sys 0m0.030s
time psql test -c "select to_char(d, 'SS') from tab;" -o /dev/null
real 0m0.368s
user 0m0.080s
sys 0m0.000s
(to_char() is a little slowly now (than in previous test), because I rewrite
any parts)
This comparison is *not* show cache effect. This test show (probably) better
searching and datetime part extraction in to_char().
Cache has effect for long and complicated 'format-picture' in to_char().
With cache (Cache has implement via malloc/free.) :
~~~~~~~~~~
time psql test -c "select to_char(d, 'HH12:MI:SS YYYY FMMonth Day') from
tab;" -o /dev/null
real 0m0.545s
user 0m0.060s
sys 0m0.010s
Without cache:
~~~~~~~~~~~~~
time psql test -c "select to_char(d, 'HH12:MI:SS YYYY FMMonth Day') from
tab;" -o /dev/null
real 0m0.638s
user 0m0.060s
sys 0m0.010s
Hmm.. my internal to_char() parser is very fast (0.100s for 10000
calls only) :-))
Thank for all suggestion. I finaly use in to_char() cache via static buffer,
and if format-picture will bigger than this buffer, to_char will work as
without cache. This solution eliminate memory leak - this solution is used
in current datetime routines. It is good compromise.
I plan in future make small changes in datetime routines. The to_char is
probably fastly, because it use better search algorithm (has a simple index
for scanned array). The date_part() will fast too :-)
-
A last (PG's novice) question - how problem appear if PG is compilate with
(gcc) -O3 optimalization? Or why is not used in PG 'inline' function
declaration?
Karel
From | Date | Subject | |
---|---|---|---|
Next Message | Jan Wieck | 1999-12-28 13:35:45 | LZTEXT is removed |
Previous Message | Hiroshi Inoue | 1999-12-28 07:30:06 | can't link libpq.so(inet_aton() not found) |