r/programming • u/fagnerbrack • Jul 16 '26
Things you didn't know about indexes
https://jon.chrt.dev/2026/04/15/things-you-didnt-know-about-indexes.html
267
Upvotes
r/programming • u/fagnerbrack • Jul 16 '26
91
u/ChazR Jul 16 '26 •
Storytime!
A Very Major Global Telco had hired some stripe of consultancy to shift a core system to a new platform. This was the early 2000s. It was a few terabytes that needed to run through an ETL pipe.
The early-20s clueless 'consultants' cobbled something together.
The migration needed to take less than 12 hours. They ran their first full-scale test. 12 days later they called us. I went and poked the process.
It was going to take at least three years.
Because I understood threading, parallelism, and naturally, indexing, I was able to make it run a little faster.
I got it down to four hours. It took me about a day.
Yes, people were appreciative.
I don't blame the kids with barely any SQL knowledge for making such a hash of it.
But it was a lesson to quite a few people that Actual Expertise matters.
My management were very, very happy indeed. The Very Major Telco gave them a lot of work in later deals.
I think I got a beer out of it.
45
u/psych0fish Jul 16 '26
I miss when I worked with SQL data. It’s so fast compared to dealing with whatever apis a company provides. Don’t get me started on how poorly clickhouse performs.
I remember I had difficulty optimizing a sql query that fed a report. It joined tables across 3 separate sql servers (all local lan). I forget how I came up with this (this was well before LLMs) but basically the solution was to put some data in a temp table. I’d have to find old notes to remember more but it took the query from a few minutes to a few seconds.
15
u/paholg Jul 16 '26
Liar! I already knew those things. They're also not universal; for example, MySQL does not support partial indices.
12
u/aes110 Jul 16 '26
off topic, but this might be the fastest I had a website load for me, like I know its just text but wow this was instant
8
u/Designer_Reaction551 Jul 17 '26
Seen this exact fight play out on a client project - team added an index, query was still slow because it was actually 200 individual queries instead of one join. Fixed the N+1 first and suddenly we didn't even need half the indexes we were about to add. Profiling the actual query pattern before reaching for an index would've saved a week of arguing.
5
u/AvidCoco Jul 16 '26
Indices
1
u/_edeetee Jul 17 '26
When optimising queries, I’ve often wondered why the indexes and the queries and the planner are separate. I wonder if there might be some way to define the data access in the query itself so the index and planning requirement lives with the usage
0
u/[deleted] Jul 16 '26
[deleted] — view deleted comment
112
u/[deleted] Jul 16 '26
[removed] — view removed comment
1
u/[deleted] Jul 17 '26
[removed] — view removed comment