Re: [HACKERS] Idea on how to simplify comparing two sets - Mailing list pgsql-hackers

From Nico Williams
Subject Re: [HACKERS] Idea on how to simplify comparing two sets
Date
Msg-id 20170223212743.GD30233@localhost
Whole thread Raw
In response to Re: [HACKERS] Idea on how to simplify comparing two sets  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-hackers
On Tue, Feb 07, 2017 at 10:58:41AM -0500, Tom Lane wrote:
> Joel Jacobson <joel@trustly.com> writes:
> > Currently there is no simple way to check if two sets are equal.
> 
> Uh ... maybe check whether SELECT set1 EXCEPT SELECT set2
> and SELECT set2 EXCEPT SELECT set1 are both empty?

Even better, NATURAL(*) FULL OUTER JOIN the two table sources and check
that the result is empty.  If the two sources have useful indices (or if
PG constructs suitable automatic indices for them) for this then the
query should be O(N).

(*) However, if you do this then there'd better not be any NULLs in
columns, otherwise you'll get false positives for differences.  Of
course, if the two table sources have common primary key prefixes and
you only care about equality in those columns, then just FULL OUTER JOIN
USING (<primary key prefix>).

Nico
-- 



pgsql-hackers by date:

Previous
From: Jim Nasby
Date:
Subject: Re: [HACKERS] PinBuffer() no longer makes use of strategy
Next
From: Corey Huinker
Date:
Subject: Re: [HACKERS] Idea on how to simplify comparing two sets