Proposal: Allow foreign key constraints with limited actions #244
Replies: 3 comments 1 reply
-
I’ve some thoughts about this proposal. I’ll separate them with markers! I might be missing something, but I think the best way for me to summarize my point is by providing the following SQLite3 example:
I think this example is quite self-explanatory. Maybe I'm missing something here, LMK! Agree with you that I’d say For This then means that all FK columns must be Any SELECT that did a JOIN in that column should expect at any point without coordination to stop joining and “disappear” from that SELECT result. Also, accepting to have that "orphaned" table row (whatever that means for the app). Is this way what we wanted to solve originally in the tension? From a birds-eye, I think any FK option can create a big risk for Tables. For example, if 1000 tables reference some popular table, and the parent table owner decides is a good idea (or by mistake) to execute a DELETE or UPDATE, it will indirectly affect the 1000 tables. You could say: “Well, those 1000 tables should already know where they were getting into,” but I’m not entirely sure that’s a friendly answer if we enabled a potentially risky feature. I’m a bit afraid it could break the ecosystem apps badly. That’s why I’m suspicious about magically-allowing cascading options such as This is debatable and subjective; just leaving it as a general comment. Regarding:
I think we need to also dig deeper into what that means:
|
Beta Was this translation helpful? Give feedback.
-
Allow foreign keys
Based on #243 Tableland should support foreign key constraints on child tables, such that these constraints do not impose any constraints on operations on the parent (or upstream reference) table. Ideally, this proposal will also ensure that there are no unexpected downstream effects on child tables due to changes on the parent table. To this effect, the following changes to the Tableland spec are proposed, requiring updates to the Tableland SQL parser, and likely some additional runtime checks on the validator.
Limit actions
The proposal is to introduce a subset of the standard SQL foreign key constraint clause to the Tableland SQL specification. Namely, to enable the following syntax within the
table-constrain
clause of theCREATE TABLE
statement:Where column-name can be any table column name, foreign-table is any valid table name (including tables create via other chains), and action can be one of:
SET NULL
NO ACTION
I am also accepting arguments in favor of including:
SET DEFAULT
CASCADE
Though there is no way that we can support
RESTRICT
.The default behavior when either of
ON DELETE
orON UPDATE
are not provided, would beNO ACTION
.Related tension
Beta Was this translation helpful? Give feedback.
All reactions