From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
---|---|
To: | Greg Stark <stark(at)mit(dot)edu> |
Cc: | Atri Sharma <atri(dot)jiit(at)gmail(dot)com>, David Fetter <david(at)fetter(dot)org>, Paul Ramsey <pramsey(at)cleverelephant(dot)ca>, Pgsql Hackers <pgsql-hackers(at)postgresql(dot)org> |
Subject: | Re: Hashable custom types |
Date: | 2014-04-27 04:14:56 |
Message-ID: | 32495.1398572096@sss.pgh.pa.us |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
Greg Stark <stark(at)mit(dot)edu> writes:
> On Sat, Apr 26, 2014 at 6:39 PM, Atri Sharma <atri(dot)jiit(at)gmail(dot)com> wrote:
>> Without sorting, isnt the scope of a recursive UNION with custom datatypes
>> pretty restrictive?
> All the default data types are hashable. It's not hard to add a hash
> operator class. In a clean slate design it would probably have been
> simpler to just make it a requirement that any data type provide a
> default hash operator (and probably a default btree comparator).
> Postgres provides a lot of degrees of freedom but it should probably
> be considered best practice to just provide both even if you don't
> envision one or the other being used directly by users for indexes.
A btree opclass requires that you invent some one-dimensional sort order
for the datatype, which might be a difficult thing; so I think it's fully
reasonable not to require datatypes to have btree support. Hashing
doesn't require any semantic assumptions beyond having an equality rule,
which is clearly *necessary* if you want to do stuff like UNION or
DISTINCT. So from that standpoint it's perfectly reasonable for recursive
UNION to require a hashable equality operator, whereas the other case of
requiring a sortable operator would be a lot harder to defend.
Having said that, I can also believe that there might be datatypes for
which implementing a hash function would be a lot harder than implementing
sorting; this could be true if your equality rule allows for a lot of
different physical representations of "equal" values. But I'm not so
excited about such cases that I want to do the work of figuring out a
way to implement recursive UNION by sorting.
regards, tom lane
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2014-04-27 04:16:25 | Re: Should pg_stat_bgwriter.buffers_backend_fsync be removed? |
Previous Message | Peter Geoghegan | 2014-04-27 02:42:47 | Should pg_stat_bgwriter.buffers_backend_fsync be removed? |