Re: [HACKERS] GSoC 2017: Foreign Key Arrays - Mailing list pgsql-hackers

From Mark Rofail
Subject Re: [HACKERS] GSoC 2017: Foreign Key Arrays
Date
Msg-id CAJvoCuuzY7a=Eqv0nCQjYEz3TE2gzd4j+rDTBn2S5yBjcvZ=KQ@mail.gmail.com
Whole thread Raw
In response to Re: [HACKERS] GSoC 2017: Foreign Key Arrays  (Mark Rofail <markm.rofail@gmail.com>)
Responses Re: [HACKERS] GSoC 2017: Foreign Key Arrays  (Mark Rofail <markm.rofail@gmail.com>)
List pgsql-hackers
To better understand a limitation I ask 5 questions

What is the limitation?
Why is there a limitation?
Why is it a limitation?
What can we do?
Is it feasible? 

Through some reading:

What is the limitation?
presupposes that count(distinct y) has exactly the same notion of equality that the PK unique index has. In reality, count(distinct) will fall back to the default btree opclass for the array element type. 

the planner may choose an optimization of this sort when the index's opclass matches the one
DISTINCT will use, ie the default for the data type.

Why is there a limitation?
necessary because ri_triggers.c relies on COUNT(DISTINCT x) on the element type, as well as on array_eq() on the array type, and we need those operations to have the same notion of equality that we're using otherwise.

Why is it a limitation?
That's wrong: DISTINCT should use the equality operator that corresponds
to the index' operator class instead, not the default one.

What can we do ?
I'm sure that we can replace array_eq() with a newer polymorphic version but I don't know how we could get around COUNT(DISTINCT x)

Is it feasible? 
I don't think I have the experience to answer that

Best Regards,
Mark Rofail

pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: [HACKERS] Hash Functions
Next
From: Tom Lane
Date:
Subject: Re: [HACKERS] PL_stashcache, or, what's our minimum Perl version?