← 피드로
Let’s consider a table user. When we execute a query to find Emily, we are actually going through each record, looking whether the name column equals Emily. Indexes comes in when you want to speed this up.
Let’s create an Index with the name idx_users_name (the name can be anything, and it doesn’t matter functionally):
CREATE INDEX idx_users_name ON users (name);
Enter fullscreen mode Exit fullscreen mode
Now when you run
SELECT * FROM users WHERE name = 'Emily';
Enter fullscreen mode Exit fullscreen mode
Postgres will use the index we just created (not by the name, the name is just for us) to execute that query, and the time complexity is reduced from O(n) to O(log n).
추출 본문 · 출처: dev.to · https://dev.to/effessdev/indexes-quickstart-using-postgresql-min-read-55ee
답글 남기기