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 ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| 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 |
| |||
| 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 |
| ||||
| 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) |