rendered paste bodymusicbrainz=> \d artist;
Table "public.artist"
Column | Type | Modifiers
-----------------+------------------------+--------------------------------------------------------
id | integer | not null default nextval('public.artist_id_seq'::text)
name | character varying(255) | not null
gid | character(36) | not null
modpending | integer | default 0
sortname | character varying(255) | not null
page | integer | not null
resolution | character varying(64) |
begindate | character(10) |
enddate | character(10) |
type | smallint |
quality | smallint | default -1
modpending_qual | integer | default 0
Indexes:
"artist_pkey" PRIMARY KEY, btree (id)
"artist_gidindex" UNIQUE, btree (gid)
"artist_lower" btree (lower(name::text))
"artist_nameindex" btree (name)
"artist_pageindex" btree (page)
"artist_sortnameindex" btree (sortname)
musicbrainz=> \d track;
Table "public.track"
Column | Type | Modifiers
------------+------------------------+-------------------------------------------------------
id | integer | not null default nextval('public.track_id_seq'::text)
artist | integer | not null
name | character varying(255) | not null
gid | character(36) | not null
length | integer | default 0
year | integer | default 0
modpending | integer | default 0
Indexes:
"track_pkey" PRIMARY KEY, btree (id)
"track_gidindex" UNIQUE, btree (gid)
"track_artistindex" btree (artist)
"track_length" btree (length)
"track_lower" btree (lower(name::text))
"track_nameindex" btree (name)
EXPLAIN SELECT
artist.id,
artist.name AS artist,
artist.gid AS artist_gid,
track.artist AS track_artist
FROM
artist
INNER JOIN track ON track.artist = artist.id
WHERE lower(artist.name) = 'beck'
QUERY PLAN
Hash Join (cost=5687.20..211232.46 rows=29520 width=66)
Hash Cond: ("outer".artist = "inner".id)
-> Seq Scan on track (cost=0.00..146238.03 rows=5901203 width=4)
-> Hash (cost=5683.20..5683.20 rows=1600 width=62)
-> Index Scan using artist_lower on artist (cost=0.00..5683.20 rows=1600 width=62)
Index Cond: (lower((name)::text) = 'beck'::text)
6 rij(en)
Total runtime: 7.324 ms
EXPLAIN SELECT
artist.id,
artist.name AS artist,
artist.gid AS artist_gid,
track.artist AS track_artist
FROM
artist
LEFT JOIN track ON track.artist = artist.id
WHERE lower(artist.name) = 'beck'
QUERY PLAN
Merge Left Join (cost=1156952.71..1186761.93 rows=29520 width=66)
Merge Cond: ("outer".id = "inner".artist)
-> Sort (cost=5768.35..5772.35 rows=1600 width=62)
Sort Key: artist.id
-> Index Scan using artist_lower on artist (cost=0.00..5683.20 rows=1600 width=62)
Index Cond: (lower((name)::text) = 'beck'::text)
-> Sort (cost=1151184.36..1165937.37 rows=5901203 width=4)
Sort Key: track.artist
-> Seq Scan on track (cost=0.00..146238.03 rows=5901203 width=4)
9 rij(en)
Total runtime: 7.325 ms