PostgreSQL에서 쿼리 성능 개선하기
Amy McCarty
Instructor
무엇
왜
어디에
| ingredient | recipe |
|---|---|
| tomatoes | spaghetti & meatballs |
| green onions | fried rice |
| eggs | fried rice |
| ground beef | spaghetti & meatballs |
| pasta | spaghetti & meatballs |
| rice | fried rice |
| soy sauce | fried rice |
SELECT *
FROM cookbook
WHERE recipe = 'fried rice'

SELECT * FROM pg_indexes
| schemaname | tablename | indexname | tablespace | indexdef |
|---|---|---|---|---|
| food | dinner | recipe_index | null | CREATE INDEX recipe_index ... |

CREATE INDEX recipe_index
ON cookbook (recipe);
CREATE INDEX CONCURRENTLY recipe_index
ON cookbook (recipe, serving_size);
인덱스 사용 권장
인덱스 지양
갱신이 잦은 테이블

쿼리 플래너
EXPLAIN
SELECT *
FROM cookbook
쿼리 계획
Seq scan on cookbook (cost=0.00...22.70
rows = 1270 width = 36)
PostgreSQL에서 쿼리 성능 개선하기