Skip site navigation (1) Skip section navigation (2)

pgsql: This patch optimizes the md5_text() function (which is used to

From: neilc(at)svr1(dot)postgresql(dot)org (Neil Conway)
To: pgsql-committers(at)postgresql(dot)org
Subject: pgsql: This patch optimizes the md5_text() function (which is used to
Date: 2005-02-23 22:46:17
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-committers
Log Message:
This patch optimizes the md5_text() function (which is used to
implement the md5() SQL-level function). The old code did the

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.

Modified Files:
        md5.c (r1.27 -> r1.28)
        varlena.c (r1.118 -> r1.119)

pgsql-committers by date

Next:From: Neil ConwayDate: 2005-02-23 23:27:55
Subject: pgsql: Minor code cleanup: remove a variable that was assigned to but
Previous:From: Tom LaneDate: 2005-02-23 16:23:08
Subject: pgsql: Un-break plpgsql build by removing unwanted _() usage.

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group