I am using PostgreSQL 9.5.19.
I have a simple SQL statement that is doing a query that returns 1 row on a table that only has 10 rows.
EXPLAIN
SELECT * FROM table_a a
WHERE a.col_a ='a';
Returns
"Seq Scan on table_a a (cost=0.00..1.12 rows=1 width=524)"
" Filter: ((col_a)::text = 'a'::text)"
Question
Why is it using a Seq scan and not an Index scan?
I thought for only one row, it would do an Index scan.
More info:
I changed the table to have only 2 rows, so that the result set would be 50% of the rows, and it still did a Seq scan. I also changed it to have 100 rows, same thing it was still using a Seq scan.
The table does have the following index (removing the index makes no difference):
CREATE INDEX idx_a
ON table_a
USING btree
(col_a);
UPDATE:
If I increase the number of rows in the table to 100000, it does a bitmap heap scan.
"Bitmap Heap Scan on table_a a (cost=4.66..119.19 rows=30 width=25)"
How do I get it to do an index scan?