sql: allow a FK relationship to work even without index on the referencing column
See the discussion here: https://forum.cockroachlabs.com/t/v2-0-alpha-20180129-foreign-key-column-requires-index/1326
Currently a FK relationship requires a unique index on the referenced column (common) and an index (potentially non-unique) on the referencing column (not common: oracle and pg do not have this requirement).
The explanation: we need this to accelerate lookups on the referencing table during updates or deletes on the referenced table.
However as the user points out:
- it's not directly compatible with pg
- in the case the referenced table is infrequently modified (or not at all), this is pure overhead
- it removes control from the hands of the programmer about the performance of their application
So instead we could make the requirement optional.
cc @awoods187 for tracking and prioritization
Ran into this pretty quickly when making a multi-table geo-partitioning dataset that uses composite FKs cc @awoods187
A lot of the ongoing work to enable this is on the optimizer side (to support cascades). I'm going to use this issue to track what needs to be done on the schema change side of things, which is just
- remove the restriction when creating FKs, and
- stop auto-creating indexes on new tables and empty tables with FKs.