I inserted 10k rows into my test DB. I'm doing some perf testing with some sample indexes. Currently, I created a clustered index on the primary key to see if exact-match filter would make a difference and it still takes > 800ms to retrieve this result:
Note: This is just high-level sample test, so all varchar columns are padded with > 100.
CREATE UNIQUE INDEX people_idx ON people (id);
CLUSTER people USING people_idx;
select * from people
where id = 2;
CREATE TABLE "people" (
id SERIAL PRIMARY KEY,
first_name varchar(255) default NULL,
last_name varchar(255) default NULL,
email varchar(255) default NULL,
created_date varchar(255),
phone varchar(100) default NULL,
customer_id integer NULL
);
Am I thinking about this correctly?
I updated cluster index to add to last_name
:
CREATE INDEX people_idx ON people (last_name);
EXPLAIN ANALYZE select * from people
where first_name = 'Sophia';
EXPLAIN ANALYZE select * from people
where last_name ILIKE 'd%';
The analyze output is as follows:
"Seq Scan on people (cost=0.00..170.00 rows=416 width=76) (actual time=0.042..6.807 rows=414 loops=1)"
" Filter: ((last_name)::text ~~* 'd%'::text)"
" Rows Removed by Filter: 9586"
"Planning Time: 0.191 ms"
"Execution Time: 6.857 ms"