Markus Winand writes about SQL indexing, query performance and modern SQL features for application developers.
Commenters recommend it highly as a readable guide to database indexing, and some say they have new hires and interns read it.
Here's a recent discussion recommending a specific site that might help you as a resource, but I don't see much there regarding locality.
How far can you go with MySQL or MariaDB?
| https://news.ycombinator.com/item?id=14892184 (Aug 2017)
> dmux This is a great resource RE indexing: http://use-the-index-luke.com/
There is a detailed PostgreSQL optimization comment there that may be more what you had in mind:
https://news.ycombinator.com/item?id=14896154
> olavgg: Use multi-column/functional/partial indexes, as this will help you design a database where most of your 'hot' indexes can fit in RAM. If you have too many indexes, you will do index scan on disk, which is painfully slow. I[n] many cases a full table scan (sequential read) would be faster instead.
To learn yourself, also go over the execution plan when running a query and Google absolutely everything it tells you, and look through the MSSQL documentation at what it all means. It won't lead you to what you don't know, but it will fill in everything you're a bit cloudy on.
One of my favorites to get the very basics is Select Star, especially because you work with real and meaningful data: https://selectstarsql.com/
Use the Index, Luke has also really helped me make queries that don't waste a ton of time:
https://use-the-index-luke.com/
Microsoft also has a bunch of paid training classes for MSSQL, if you or your boss don't mind ponying up some $$$. MSSQL is an amazing tool, and it's worth it to really learn how to use it well.
Good luck!
There's a difference between operating the database [SRE type job] vs consuming a database [developer]. They're both very valuable skills, but learning the basics of SQL [i.e. being a consumer] is a no brainer. The skills will serve you well for the rest of your career. It's not something that changes every few years like frontend frameworks do.
This is my favorite learning material for ANY programming related skill ever: https://use-the-index-luke.com/, and it's all about SQL queries.
If what you are looking is a general book (not necessarily just for Postgres) I can't recommend the "Use The Index, Luke"[1] tutorial, and the accompanying book "SQL Performance Explained" by Markus Winand, enough.
It doesn't go into a lot of relational theory, but it does provide a somewhat low-level description on how indices and database data are stored, and why you want to use different kind of indices in different scenarios.
[1] http://use-the-index-luke.com
For practical knowledge start with databases. Declarative is a great way to program, and a good starting point is https://use-the-index-luke.com/
About CompSci, it might get a bit dry at times. Seduce yourself into it, watch some Computerphile YouTube videos instead of a textbook. Then when you get the interest bug, search for what you are interested in. Try to keep it fun.
Once you built stamina, TAOC and SICP.
https://web.mit.edu/alexmv/6.037/sicp.pdf
If you do backend web development in 99% of software companies then being very good at whatever your RDBMS is is a superpower.
It's definitely worth learning SQL very well, but you also need to learn the data structures your RDBMS uses, how queries translate into operations on that data, and what those operations look like in a query plan.
You can go surprisingly far with just that knowledge.
A great resource is https://use-the-index-luke.com/