Unix Technical Forum

optimize md5_text

This is a discussion on optimize md5_text within the Pgsql Patches forums, part of the PostgreSQL category; --> This patch optimizes the md5_text() function (which is used to implement the md5() SQL-level function). The old code did ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > Pgsql Patches

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-18-2008, 12:04 AM
Neil Conway
 
Posts: n/a
Default optimize md5_text

This patch optimizes the md5_text() function (which is used to implement
the md5() SQL-level function). The old code did the following:

1. de-toast the datum
2. convert it to a cstring via textout()
3. get the length of the cstring via strlen()

Since we are treating the datum context as a blob of binary data, the
latter two steps are unnecessary. Once the data has been detoasted, we
can just use it as-is, and derive its length from the varlena metadata.

This patch improves some run-of-the-mill md5() computations by just
under 10% in my limited tests, and passes the regression tests.

I also noticed that md5_text() wasn't checking the return value of
md5_hash(); encountering OOM at precisely the right moment could result
in returning a random md5 hash. This patch corrects that. A better fix
would be to make md5_hash() only return on success (and/or allocate via
palloc()), but since it's used in the frontend as well I don't see an
easy way to do that.

Barring any objections, I'll apply this to HEAD tomorrow.

-Neil


---------------------------(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
  #2 (permalink)  
Old 04-18-2008, 12:05 AM
Neil Conway
 
Posts: n/a
Default Re: optimize md5_text

Neil Conway wrote:
> This patch optimizes the md5_text() function (which is used to implement
> the md5() SQL-level function).


Applied.

-Neil

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

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 05:01 PM.


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