75 points · by grep_it · 3y ago · 35 comments
https://dev.mysql.com/doc/refman/8.0/en/ansi-diff-foreign-ke...
Anyone have any background on why this exists? For what purpose would you want a non-unique FK; what are the semantics of a FK that resolves to multiple different records?
In a reporting/ROLAP dimensional data model, you may have a slowly changing dimension where you have something a table design like:
customer_id (varchar(N)),
current_record_flag boolean,
record_effective_start_date,
record_effective_end_date,
attribute1,
attribute2, etc
and a sales transaction table: customer_id -- non-unique FK
product_id
sale_date
sold_quantity
unit_price
total_sales_amount
The customer ID in the sales table really relates back to the customer ID in the customer dimension table but not to a single UNIQUE row in the customer dimension table... unless you are, as you always are, either querying on current_record_flag='Y' (for seeing current customer attribute values), or a specific date value that falls between record_effective_date and record_end_date (for seeing customer attribute values at the time of the sales transaction_date).(And optimal query performance for these types of analytic use case often involves using a columnar storage engine rather than InnoDB.)
only public news so far is extremely brief twitter mention of future switch to separate LTS releases from feature releases
big picture, hard to see what would motivate them to major re-invest in current mysql product model! amazon, planetscale, and co all profit off of oracle’s mysql server development efforts. and oracle does not get anything in return
assume this why more and more mysql dev efforts go to saas-only product like “mysql heatwave”!
Note that there's more than one 'MySQL FOREIGN KEY' implementation. MySQL Ndb Cluster also supports foreign keys with some differences wrt the InnoDB implementation :
- NDB, therefore not limited to a single MySQL Server, shard etc - Not limited to references between tables in a single database - Supports NoAction deferred constraint checks - Cascaded changes Binlogged independently as part of RBR (Nice side effect of reducing replica apply time work) ...
https://dev.mysql.com/blog-archive/foreign-keys-in-mysql-clu...
Some of the issues described wrt DDL limitations are shared.
Many schemas seem to overuse foreign keys perhaps under the assumption that they are required for or accelerate joins?
can be terrible in mysql 8 though due to metadata locks now extending across foreign key boundaries. this means alter in one schema can block things in other schema if foreign key across databases
speaking of, am surprised that blog post author doesnt discuss the new mysql 8 metadata locking behavior, is new major problem with mysql foreign keys!
Out of curiosity, is there a scenario you can share in which using a binary blob as a PK/FK would be the best solution?
> MySQL is pushing towards INSTANT DDL
When I need MySQL these days I automatically go for MariaDB instead, but I guess they are going to diverge more and more. Does anyone more involved in the MySQL/MariaDB world have any thoughts about how they choose and the future of those two projects?