Everlasting SQL query
| От | Joost Kraaijeveld |
|---|---|
| Тема | Everlasting SQL query |
| Дата | |
| Msg-id | A3D1526C98B7C1409A687E0943EAC41001EA55@obelix.askesis.nl обсуждение исходный текст |
| Ответы |
Re: Everlasting SQL query
Re: Everlasting SQL query Re: Everlasting SQL query Re: Everlasting SQL query |
| Список | 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
thatdid 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.Kraaijeveld@Askesis.nl
web: www.askesis.nl
В списке pgsql-general по дате отправления: