Re: [SQL] Table indexes in a SELECT with JOIN´s

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: JORGE MALDONADO <jorgemal1960(at)gmail(dot)com>
Cc: postgres list <pgsql-sql(at)postgresql(dot)org>
Subject: Re: [SQL] Table indexes in a SELECT with JOIN´s
Date: 2013-04-20 16:59:05
Message-ID: CAFj8pRAgLc_AM6WE3_EgzhKziUx+SieYN5b8CCWGu4Nd8pnfwQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hello

2013/4/20 JORGE MALDONADO <jorgemal1960(at)gmail(dot)com>

> Let´s suppose that I have a SELECT statement that joins more than one
> table and such a statement is order by fields that belong not only to the
> table in the FROM but also by fields in the tables that are part of the
> JOIN´s. How does indexes should be considered in a case like this? For
> example:
>
> SELECT artist_name, author_name, producer_name, song_name
> FROM tbl_songs
> INNER JOIN tbl_artists ON tbl_artists.artistid = tbl_songs_artistid
> INNER JOIN tbl_authors ON tbl_authors.authorid = tbl_songs_authorid
> INNER JOIN tbl_producers ON tbl_producers.producerid = tbl_songs_producerid
> ORDER BY song_name
>
>

It depends on size of relations - you don't need indexes on small tables -
hash join will be used. For bigger tables indexes on PK (automatically) and
FK are good idea.

Regards

Pavel

> Respectfully,
> Jorge Maldonado
>

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Wolfgang Meiners 2013-04-22 10:19:17 check for overlapping time intervals
Previous Message JORGE MALDONADO 2013-04-20 16:32:00 Table indexes in a SELECT with JOIN´s