~/talk

Implementing Native Composite Primary Key Support in Rails 7.1

Talkat RailsConf 2024 · 2024-05-07..05-09· [ruby-on-rails, databases]
links:none on file
slides:none on file

Rails 7.1 adds native composite primary key support plus an ID_value accessor to read an ID column when the primary key becomes an array, a bulk where by triple query syntax for fetching many composite keys, and a query_constraints association option that acts as a virtual composite foreign key. Real-world use at Shopify shows a ~5× query speedup for orders after prepending tenant key to the PK at the cost of roughly ~10× slower inserts. Join tables and multitenant tables are common winning cases.

AI-written summary · about

  1. 0:00Introduction
  2. 1:24Composite primary keys
  3. 3:52Join table keys
  4. 5:16Multitenant apps
  5. 9:31Tradeoffs of composite keys
  6. 11:18Sharding similarities
  7. 13:43Rails 7.1 composite keys
  8. 16:55Querying composite keys
  9. 18:18Virtual keys with constraints
  10. 19:42When to use composite keys
  11. 20:24Closing
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.