let's assume we have a simple table:
Table "public.test"
Column | Type | Modifiers
--------+---------+-----------
a | integer | not null
b | integer | not null
Indexes:
"test_pkey" PRIMARY KEY, btree (a, b)
"q" UNIQUE, btree (b, a)
now, let's insert some rows to it:
# insert into test select * from generate_series(1,100) as a, generate_series(1,100) as b^J;
INSERT 0 10000
remove rows with a = b:
# delete from test where a = b;
DELETE 100
and prepare test-case by randomly removing some rows:
# delete from test where random() < 0.002;
DELETE 17
the question is – find all pairs of (a,b) where there is no row (a',b') where (a'=b and b'=a).
in other words – every row (a,b) should be paired. rows with a = 2 and b = 3, is paired by row with a = 3 and b = 2.
how to find incomplete pairs?
Continue reading finding missing pairs