Unix Technical Forum

FunctionCallN improvement.

This is a discussion on FunctionCallN improvement. within the pgsql Hackers forums, part of the PostgreSQL category; --> When SQL that returns many tuples with character code conversion is executed, the FunctionCall3/FunctionCall5 becomes a bottleneck. Because MemSet ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Hackers

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-11-2008, 03:33 AM
a_ogawa
 
Posts: n/a
Default FunctionCallN improvement.


When SQL that returns many tuples with character code conversion
is executed, the FunctionCall3/FunctionCall5 becomes a bottleneck.
Because MemSet is used to initialize FunctionCallInfoData in these
functions, a lot of cycles are spent.

<test query>
set client_encoding to 'SJIS';
select * from pg_class, pg_amop;
(This SQL is used only to get a lot of tuples, and there is no
logical meaning)

<result of profile>
Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls s/call s/call name
22.91 1.29 1.29 1562351 0.00 0.00 FunctionCall5
18.29 2.32 1.03 1602006 0.00 0.00 FunctionCall3
5.06 2.60 0.28 4892127 0.00 0.00 AllocSetAlloc
4.88 2.88 0.28 9781322 0.00 0.00 AllocSetFreeIndex
4.35 3.12 0.24 1587600 0.00 0.00 ExecEvalVar

Most of calls of these functions are from printtup.
FunctionCall3 is used to generate the text.
FunctionCall5 is used to character code conversion.
(printtup -> pq_sendcountedtext -> pg_server_to_client ->
perform_default_encoding_conversion -> FunctionCall5)

I think that we should initialize only the fields of
FunctionCallInfoData that must be initialized.
(Such as FunctionCall1)

I have two plans to modify the code.
(a)Change FunctionCall3/FunctionCall5 like FunctionCall1.
It is simple, minimum change.

(b)Define the macro that initialize FunctionCallInfoData, and use it
instead of MemSet in all FunctionCallN, DirectFunctionCallN,
OidFunctionCallN.
This macro is the following.

#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs) \
do { \
(Fcinfo)->flinfo = Flinfo; \
(Fcinfo)->context = NULL; \
(Fcinfo)->resultinfo = NULL; \
(Fcinfo)->isnull = false; \
(Fcinfo)->nargs = Nargs; \
MemSet((Fcinfo)->argnull, 0, Nargs * sizeof(bool)); \
} while(0)

I think that plan(b) is better, because source code consistency
and efficiency improve.

Any comments?

regards,

---
A.Ogawa ( a_ogawa@hi-ho.ne.jp )


---------------------------(end of broadcast)---------------------------
TIP 5: Have you checked our extensive FAQ?

http://www.postgresql.org/docs/faq

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-11-2008, 03:33 AM
Neil Conway
 
Posts: n/a
Default Re: FunctionCallN improvement.

On Mon, 2005-01-31 at 23:38 +0900, a_ogawa wrote:
> (b)Define the macro that initialize FunctionCallInfoData, and use it
> instead of MemSet in all FunctionCallN, DirectFunctionCallN,
> OidFunctionCallN.
> This macro is the following.
>
> #define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs) \
> do { \
> (Fcinfo)->flinfo = Flinfo; \
> (Fcinfo)->context = NULL; \
> (Fcinfo)->resultinfo = NULL; \
> (Fcinfo)->isnull = false; \
> (Fcinfo)->nargs = Nargs; \
> MemSet((Fcinfo)->argnull, 0, Nargs * sizeof(bool)); \
> } while(0)
>
> I think that plan(b) is better, because source code consistency
> and efficiency improve.


I agree; I think the macro is a nice improvement to readability. It
would be good to see some benchmarks once the patch is written to verify
that this really does improve performance, but I think it's a good idea.

-Neil



---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
joining column's datatypes do not match

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-11-2008, 03:35 AM
Tom Lane
 
Posts: n/a
Default Re: FunctionCallN improvement.

Neil Conway <neilc@samurai.com> writes:
> On Mon, 2005-01-31 at 23:38 +0900, a_ogawa wrote:
>> (b)Define the macro that initialize FunctionCallInfoData, and use it
>> instead of MemSet in all FunctionCallN, DirectFunctionCallN,
>> OidFunctionCallN.
>> This macro is the following.
>>
>> #define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs) \
>> do { \
>> (Fcinfo)->flinfo = Flinfo; \
>> (Fcinfo)->context = NULL; \
>> (Fcinfo)->resultinfo = NULL; \
>> (Fcinfo)->isnull = false; \
>> (Fcinfo)->nargs = Nargs; \
>> MemSet((Fcinfo)->argnull, 0, Nargs * sizeof(bool)); \
>> } while(0)
>>
>> I think that plan(b) is better, because source code consistency
>> and efficiency improve.


> I agree; I think the macro is a nice improvement to readability.


But a dead loss for performance, since it does a MemSet *and* some other
operations. What's worse, it changes a word-aligned MemSet into a
non-aligned one, knocking out all the optimizations therein.

regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:21 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com