Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit011d60c

Browse files
committed
Speed up uuid_out() by not relying on a StringInfo
Since the size of the string representation of an uuid is fixed, thereis no benefit in using a StringInfo. This commit simplifies uuid_oud()to not rely on a StringInfo, where avoiding the overhead of the stringmanipulation makes the function substantially faster.A COPY TO on a relation with one UUID attribute can show up to a 40%speedup when the bottleneck is the COPY computation with uuid_out()showing up at the top of the profiles (numbered measure here, Laurenzhas mentioned something closer to 20% faster runtimes), for example whenthe data is fully in shared buffers or the OS cache.Author: Laurenz AlbeReviewed-by: Andres Freund, Michael PaquierDescription:https://postgr.es/m/679d5455cbbb0af667ccb753da51a475bae1eaed.camel@cybertec.at
1 parent943f7ae commit011d60c

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

‎src/backend/utils/adt/uuid.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,13 @@ uuid_out(PG_FUNCTION_ARGS)
5353
{
5454
pg_uuid_t*uuid=PG_GETARG_UUID_P(0);
5555
staticconstcharhex_chars[]="0123456789abcdef";
56-
StringInfoDatabuf;
56+
char*buf,
57+
*p;
5758
inti;
5859

59-
initStringInfo(&buf);
60+
/* counts for the four hyphens and the zero-terminator */
61+
buf=palloc(2*UUID_LEN+5);
62+
p=buf;
6063
for (i=0;i<UUID_LEN;i++)
6164
{
6265
inthi;
@@ -68,16 +71,17 @@ uuid_out(PG_FUNCTION_ARGS)
6871
* ("-"). Therefore, add the hyphens at the appropriate places here.
6972
*/
7073
if (i==4||i==6||i==8||i==10)
71-
appendStringInfoChar(&buf,'-');
74+
*p++='-';
7275

7376
hi=uuid->data[i] >>4;
7477
lo=uuid->data[i]&0x0F;
7578

76-
appendStringInfoChar(&buf,hex_chars[hi]);
77-
appendStringInfoChar(&buf,hex_chars[lo]);
79+
*p++=hex_chars[hi];
80+
*p++=hex_chars[lo];
7881
}
82+
*p='\0';
7983

80-
PG_RETURN_CSTRING(buf.data);
84+
PG_RETURN_CSTRING(buf);
8185
}
8286

8387
/*

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp