| From: | Michael Glaesemann <grzm(at)myrealbox(dot)com> |
|---|---|
| To: | "Joost Kraaijeveld" <J(dot)Kraaijeveld(at)Askesis(dot)nl> |
| Cc: | <pgsql-general(at)postgresql(dot)org> |
| Subject: | Re: Everlasting SQL query |
| Date: | 2004-07-28 10:58:27 |
| Message-ID: | 0DA5D0F4-E085-11D8-AA48-000A95C88220@myrealbox.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-general |
On Jul 28, 2004, at 7:08 PM, Joost Kraaijeveld wrote:
> select customer.id, customer.name, orders.id
> from customers, orders
> order by customer.id, orders.id
> limit 25
>
> The query runs forever (the longest I let it run is 500 seconds).
You have no join condition, so it's doing a full cartesian join (17518
x 88393 = 1,548,468,574 rows before the limit). Try this:
select customer.id, customer.name, orders.id
from customers c, orders o
where c.id = o.customerid
order by customer.id, orders.id
limit 25
Michael Glaesemann
grzm myrealbox com
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Chris | 2004-07-28 10:58:57 | Re: Everlasting SQL query |
| Previous Message | Pierre-Frédéric Caillaud | 2004-07-28 10:57:57 | Re: Trigger on Postgres for tables syncronization |