Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

This is a horribly naive theory (I have no idea what I'm talking about) but if you have foreign keys you need to get those indexed anyway (otherwise inserts or updates will need to do a sequential scan), and with index-only scans, if the referenced key exists in the index, the tuple won't have to be visited, hence inserts and updates getting faster in tables with foreign keys?


I think that's a very keen insight. There may be a detail that gets in the way, but nothing comes to mind at the moment. Did you know that PostgreSQL's referential integrity checks are -- in the most literal sense -- implemented as triggers that construct SQL, and then plan and execute them just like a client program?

http://doxygen.postgresql.org/ri__triggers_8c_source.html#l0...

I don't think anyone has measured the effect, which seems it would be greatest on tables with wide rows, whereby the wide rows would cause cache thrashing but the smaller index would not.




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: