coverdb=# explain analyze SELECT id , title, artist, music, lyrics, year FROM search_song WHERE search_title IS NOT NULL LIMIT 20 OFFSET 0 ; QUERY PLAN --------------------------------------------------------------------------------------------------------------------------------------------------------- Limit (cost=0.00..1.18 rows=20 width=28) (actual time=0.47..9.57 rows=20 loops=1) -> Subquery Scan search_song (cost=0.00..390.11 rows=6593 width=28) (actual time=0.47..9.54 rows=21 loops=1) -> Index Scan using song_title_idx on song r (cost=0.00..390.11 rows=6593 width=28) (actual time=0.47..9.47 rows=21 loops=1) Filter: (title IS NOT NULL) SubPlan -> Aggregate (cost=8.14..8.14 rows=1 width=25) (actual time=0.24..0.24 rows=1 loops=21) -> Nested Loop (cost=0.00..8.13 rows=2 width=25) (actual time=0.03..0.03 rows=1 loops=21) -> Index Scan using credit_song_idx on credit c (cost=0.00..3.08 rows=2 width=4) (actual time=0.01..0.02 rows=1 loops=21) Index Cond: (song_id = $0) Filter: (type_id = 0) -> Index Scan using artist_pkey on artist a (cost=0.00..3.02 rows=1 width=21) (actual time=0.01..0.01 rows=1 loops=21) Index Cond: ("outer".artist_id = a.id) -> Aggregate (cost=8.14..8.14 rows=1 width=25) (actual time=0.04..0.04 rows=1 loops=21) -> Nested Loop (cost=0.00..8.13 rows=2 width=25) (actual time=0.02..0.03 rows=1 loops=21) -> Index Scan using credit_song_idx on credit c (cost=0.00..3.08 rows=2 width=4) (actual time=0.01..0.01 rows=1 loops=21) Index Cond: (song_id = $0) Filter: (type_id = 0) -> Index Scan using artist_pkey on artist a (cost=0.00..3.02 rows=1 width=21) (actual time=0.01..0.01 rows=1 loops=21) Index Cond: ("outer".artist_id = a.id) -> Aggregate (cost=6.74..6.74 rows=1 width=25) (actual time=0.04..0.04 rows=1 loops=21) -> Nested Loop (cost=0.00..6.74 rows=1 width=25) (actual time=0.02..0.02 rows=1 loops=21) -> Index Scan using credit_song_idx on credit c (cost=0.00..3.08 rows=1 width=4) (actual time=0.01..0.01 rows=1 loops=21) Index Cond: (song_id = $0) Filter: (type_id = 1) -> Index Scan using artist_pkey on artist a (cost=0.00..3.02 rows=1 width=21) (actual time=0.01..0.01 rows=1 loops=15) Index Cond: ("outer".artist_id = a.id) -> Aggregate (cost=6.74..6.74 rows=1 width=25) (actual time=0.03..0.03 rows=1 loops=21) -> Nested Loop (cost=0.00..6.74 rows=1 width=25) (actual time=0.01..0.02 rows=1 loops=21) -> Index Scan using credit_song_idx on credit c (cost=0.00..3.08 rows=1 width=4) (actual time=0.01..0.01 rows=1 loops=21) Index Cond: (song_id = $0) Filter: (type_id = 1) -> Index Scan using artist_pkey on artist a (cost=0.00..3.02 rows=1 width=21) (actual time=0.01..0.01 rows=1 loops=15) Index Cond: ("outer".artist_id = a.id) -> Aggregate (cost=6.62..6.62 rows=1 width=25) (actual time=0.04..0.04 rows=1 loops=21) -> Nested Loop (cost=0.00..6.62 rows=1 width=25) (actual time=0.01..0.02 rows=1 loops=21) -> Index Scan using credit_song_idx on credit c (cost=0.00..3.08 rows=1 width=4) (actual time=0.01..0.01 rows=1 loops=21) Index Cond: (song_id = $0) Filter: (type_id = 2) -> Index Scan using artist_pkey on artist a (cost=0.00..3.02 rows=1 width=21) (actual time=0.01..0.01 rows=1 loops=15) Index Cond: ("outer".artist_id = a.id) -> Aggregate (cost=6.62..6.62 rows=1 width=25) (actual time=0.03..0.03 rows=1 loops=21) -> Nested Loop (cost=0.00..6.62 rows=1 width=25) (actual time=0.01..0.02 rows=1 loops=21) -> Index Scan using credit_song_idx on credit c (cost=0.00..3.08 rows=1 width=4) (actual time=0.01..0.01 rows=1 loops=21) Index Cond: (song_id = $0) Filter: (type_id = 2) -> Index Scan using artist_pkey on artist a (cost=0.00..3.02 rows=1 width=21) (actual time=0.01..0.01 rows=1 loops=15) Index Cond: ("outer".artist_id = a.id) Total runtime: 9.98 msec (48 rows)