From: | "Joost Kraaijeveld" <J(dot)Kraaijeveld(at)Askesis(dot)nl> |
---|---|
To: | <pgsql-general(at)postgresql(dot)org> |
Subject: | Everlasting SQL query |
Date: | 2004-07-28 10:08:23 |
Message-ID: | A3D1526C98B7C1409A687E0943EAC41001EA55@obelix.askesis.nl |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi everyone,
I have a customer table (17518 records) and an orders table (88393 records). One of the columns of orders is customerid, containing the customerid (what else, but it is not a foreign key as this table is imported from a database that did not support foreign keys).
If I do this query (with pgadmin III):
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).
Explain gives me this (why 7 rows?):
QUERY PLAN
-------------------------------------------------------------------------------------
Limit (cost=722506879.16..722506879.22 rows=25 width=44)
-> Sort (cost=722506879.16..726378050.59 rows=1548468574 width=44)
Sort Key: klt_alg.klantnummer, orders.ordernummer
-> Nested Loop (cost=9408.93..36288661.59 rows=1548468574 width=44)
-> Seq Scan on klt_alg (cost=0.00..1927.18 rows=17518 width=40)
-> Materialize (cost=9408.93..10595.86 rows=88393 width=4)
-> Seq Scan on orders (cost=0.00..9105.93 rows=88393 width=4)
(7 rows)
If I only order by customer.id or by orders.is the query return within a second.
Can anyone give me a reason why this all happens?
Groeten,
Joost Kraaijeveld
Askesis B.V.
Molukkenstraat 14
6524NB Nijmegen
tel: 024-3888063 / 06-51855277
fax: 024-3608416
e-mail: J(dot)Kraaijeveld(at)Askesis(dot)nl
web: www.askesis.nl
From | Date | Subject | |
---|---|---|---|
Next Message | Együd Csaba | 2004-07-28 10:19:26 | Re: pgadmin III ? |
Previous Message | John Sidney-Woollett | 2004-07-28 09:49:37 | Re: Data model for Postfix v2 |