![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||||||
| |||||||
|
|
AND con.contype = 'f' AND con.confrelid = pkc.conrelid I think this is correct as far as it goes, but there are more problems. |
|
For one, I believe we also need to check the contype of the pkc row; otherwise matches against check constraints are possible. |
|
Another problem is that the view will fail to list FK constraints at all if it cannot identify a matching unique constraint. |
|
Which there may not be (the backend code for creating an FK checks for a matching unique index, quite a different animal). |
|
And the check for match is inadequate anyway, because it is using "con.confkey = pkc.conkey", which only matches if the unique constraint lists the same columns *in the same order* as the FK constraint does. The backend code does not require that. |
|
A more robust way to handle things would be to make use of pg_depend to find the index the FK constraint depends on and then chain to the unique constraint associated with that index. |
|
Another question is whether to force an initdb after making this change. If we don't, existing beta testers may continue to use the incorrect view definition. |
#2
| |||
| |||
|
|
Which there may not be (the backend code for creating an FK checks for a matching unique index, quite a different animal). I think that should be changed. No, because that would entail a genuine loss of capability: FK constraints couldn't be built using indexes that were made by CREATE UNIQUE INDEX rather than through the unique/pk constraint syntax. In particular this would mean that non-btree indexes could not be used. |
|
(Yes, I know that as of today we don't have UNIQUE support in any of the non-btree index types, but that will change. IIRC Neil Conway has already been working on unique hashes, and I'm sure GIST will support it eventually as well.) |
![]() |
| Thread Tools | |
| Display Modes | |
| |