database-scan

Why does PostgreSQL perform sequential scan on indexed column?

左心房为你撑大大i 提交于 2019-11-26 15:07:39
Very simple example - one table, one index, one query: CREATE TABLE book ( id bigserial NOT NULL, "year" integer, -- other columns... ); CREATE INDEX book_year_idx ON book (year) EXPLAIN SELECT * FROM book b WHERE b.year > 2009 gives me: Seq Scan on book b (cost=0.00..25663.80 rows=105425 width=622) Filter: (year > 2009) Why it does NOT perform index scan instead? What am I missing? If the SELECT returns more than approximately 5-10% of all rows in the table, a sequential scan is much faster than an index scan. This is because an index scan requires several IO operations for each row (look up

Why does PostgreSQL perform sequential scan on indexed column?

萝らか妹 提交于 2019-11-26 03:08:02
问题 Very simple example - one table, one index, one query: CREATE TABLE book ( id bigserial NOT NULL, \"year\" integer, -- other columns... ); CREATE INDEX book_year_idx ON book (year) EXPLAIN SELECT * FROM book b WHERE b.year > 2009 gives me: Seq Scan on book b (cost=0.00..25663.80 rows=105425 width=622) Filter: (year > 2009) Why it does NOT perform index scan instead? What am I missing? 回答1: If the SELECT returns more than approximately 5-10% of all rows in the table, a sequential scan is much