Menu

Post image 1
Post image 2
1 / 2
0

Part 11: Indexes and Performance

DEV Community: sql·Mohamed Idris·3 days ago
#Los8pnvh
#dev#index#fullscreen#orders#user_id#article
Reading 0:00
15s threshold

Part of the "SQL: Zero to Ninja" series, written for junior web devs. Your app worked great with 200 users. Then it got popular, hit a million rows, and one page started taking 8 whole seconds to load. Same query, same code, nothing changed. So what happened? Your database was quietly reading every single row, every single time. Let's fix that with indexes, and then squash the sneaky N+1 bug that haunts almost every ORM app. The idea in one line An index is a sorted shortcut that lets the database jump straight to the rows you want, instead of reading the whole table to find them. The metaphor: a dictionary Imagine you want the word "ninja" in a paper dictionary. You do not start at page 1 and read every word until you hit "ninja". That would take all day. Instead, you flip to the "N" section, then narrow down fast. The dictionary is sorted , so you jump close and zoom in. Now imagine a dictionary with the words in random order. To find "ninja" you would have to read it cover to cover. Painful.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.

Read More