You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
psql -h localhost -p 5432 -W -U postgres
postgres=# CREATE TABLE test1 (id integer primary key, group_id integer, name text);
postgres=# CREATE INDEX idx_group_id ON test1 USING btree (group_id);
postgres=# \copy test1 (id, group_id, name) from 'sample.csv' with csv;
EXPLAIN query
seasrch with 'general' values
postgres=# EXPLAIN ANALYZE select * from test1 where group_id = 10;
QUERY PLAN
----------------------------------------------------------------------------------------------------------------------
Index Scan using idx_group_id on test1 (cost=0.42..9.31 rows=33 width=14) (actual time=0.039..0.039 rows=1 loops=1)
Index Cond: (group_id = 10)
Planning time: 0.222 ms
Execution time: 0.053 ms
seasrch with 'rare' values
postgres=# EXPLAIN ANALYZE select * from test1 where group_id = 5;
QUERY PLAN
-----------------------------------------------------------------------------------------------------------------
Seq Scan on test1 (cost=0.00..17907.25 rows=999900 width=14) (actual time=0.010..109.217 rows=1000001 loops=1)
Filter: (group_id = 5)
Rows Removed by Filter: 99
Planning time: 0.063 ms
Execution time: 141.340 ms
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters