Re: why does this select hang postgres??? - Mailing list pgsql-general

From Joe Conway
Subject Re: why does this select hang postgres???
Date
Msg-id 00b101c121cb$b5aac570$b4d210ac@jecw2k1
Whole thread Raw
In response to why does this select hang postgres???  (Jeremy Hansen <jeremy@xxedgexx.com>)
List pgsql-general
>
> select * from env_info,summary,plat_info;
>
> Is my statement broken?  Is this not legal?  Postgres just sits there....
>
> My goal is to select everything from multiple tables with one sql
> statement.
>
> Thank You!
> -jeremy
>

Well, you'll get everything and then some ;)

This statement is called a cartesian join. What that means you will get the
<# of rows in env_info> *times* <# of rows in summary> *times* <# of rows in
plat_info>. So if env_info has 1000 rows,summary has 5000 rows, and
plat_info has 200 rows, the query will try to return 1000 * 5000 * 200 =
1,000,000,000 rows! So while it may *seem* to just sit there, Postgres is
actually probably just working *really* hard.

HTH,

Joe



pgsql-general by date:

Previous
From: Fernando Schapachnik
Date:
Subject: Re: why does this select hang postgres???
Next
From: Dado Feigenblatt
Date:
Subject: Re: Returned mail: Service unavailable