Re: MD5 aggregate - Mailing list pgsql-hackers

From Marko Kreen
Subject Re: MD5 aggregate
Date
Msg-id CACMqXCKZJmPPsFm2G8wp-0BZ93ua06uz9m+1txMHrM1yEcmSZw@mail.gmail.com
Whole thread Raw
In response to MD5 aggregate  (Dean Rasheed <dean.a.rasheed@gmail.com>)
Responses Re: MD5 aggregate
List pgsql-hackers
On Thu, Jun 13, 2013 at 12:35 PM, Dean Rasheed <dean.a.rasheed@gmail.com> wrote:
> Attached is a patch implementing a new aggregate function md5_agg() to
> compute the aggregate MD5 sum across a number of rows. This is
> something I've wished for a number of times. I think the primary use
> case is to do a quick check that 2 tables, possibly on different
> servers, contain the same data, using a query like
>
>   SELECT md5_agg(foo.*::text) FROM (SELECT * FROM foo ORDER BY id) foo;
>
> or
>
>   SELECT md5_agg(foo.*::text ORDER BY id) FROM foo;
>
> these would be equivalent to
>
>   SELECT md5(string_agg(foo.*::text, '' ORDER BY id)) FROM foo;
>
> but without the excessive memory consumption for the intermediate
> concatenated string, and the resulting 1GB table size limit.

It's more efficient to calculate per-row md5, and then sum() them.
This avoids the need for ORDER BY.

-- 
marko



pgsql-hackers by date:

Previous
From: Greg Stark
Date:
Subject: Re: Patch for fail-back without fresh backup
Next
From: Amit Kapila
Date:
Subject: Issue with PGC_BACKEND parameters