Strange behavior when using "limit" with example tables.

Started by Nonamealmost 24 years ago1 messages
#1Noname
domingo@dad-it.com

In the previous post I didn't provide the tables to make the test,
here I put the tables available at:

http://unolotiene.com/test_tables.sql.bz2

As well I redid the test with only two tables and the problem is still
there.

Using "limit" makes postgresql eats all cpu for a while.

Is that a bug or a mistake from my part ?

------------------------------------------------------------------------------
-- Without limit
explain select ca.*, cmm.name
from car_adverts as ca, car_models as cmm
where ca.maker=cmm.id;

NOTICE: QUERY PLAN:

Merge Join (cost=2498.96..2773.64 rows=162540 width=192)
-> Index Scan using car_models_pkey on car_models cmm
(cost=0.00..59.00 rows=1000 width=16)
-> Sort (cost=2498.96..2498.96 rows=16254 width=176)
--------------------------------------------------------------------------------
-- Now with limit
explain select ca.*, cmm.name
from car_adverts as ca, car_models as cmm
where ca.maker=cmm.id limit 10;

NOTICE: QUERY PLAN:

Limit (cost=0.00..32.53 rows=10 width=192)
-> Nested Loop (cost=0.00..528760.54 rows=162540 width=192)
-> Seq Scan on car_adverts ca (cost=0.00..505.54 rows=16254
width=176)
-> Seq Scan on car_models cmm (cost=0.00..20.00 rows=1000
width=16) -> Seq Scan on car_adverts ca (cost=0.00..505.54
rows=16254 width=176)