Re: Weird query plan - Mailing list pgsql-general

From Dmitry Tkach
Subject Re: Weird query plan
Date
Msg-id 3F68B6EB.7060708@openratings.com
Whole thread Raw
In response to Re: Weird query plan  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Weird query plan
List pgsql-general
Hmmm...
Indeed. I tried it in 7.2.4 on a couple of empty tables, and it does do
the right thing...
Also, I have another copy (not exact copy, but identical schema, and
similar content... but about twice smaller) of the original database...
I tried my query on it, and it works right too.
So, there must be something wrong with that particular database I suppose...

Any ideas what I should look at?

Thanks a lot!

Dima

Tom Lane wrote:

>Dmitry Tkach <dmitry@openratings.com> writes:
>
>
>>The query plan looks identical in both cases:
>>
>>
>
>
>
>>Limit  (cost=0.00..12.51 rows=1 width=8)
>>  ->  Nested Loop  (cost=0.00..1009772807.91 rows=80740598 width=8)
>>        ->  Index Scan using b_pkey on b  (cost=0.00..375410773.29
>>rows=80740598 width=4)
>>        ->  Index Scan using a_pkey on a  (cost=0.00..6.85 rows=1 width=4)
>>
>>
>
>
>
>>... which makes me think that it decides to use  b as the outer table
>>for both cases (which would obviously make it suck in the first one)... :-(
>>
>>
>
>That's what it says, all right, which seems odd to me.  Are you sure you
>looked at the right plans?
>
>
>
>>This happens on 7.2.4... I have a 7.3 database with the same schema, but
>>it is not populated with data, so I could not test it on 7.3...
>>
>>
>
>I could not reproduce a problem on 7.2.4.  I get (using toy tables, and
>suppressing the planner's urge to use mergejoin instead)
>
>lo=# explain select * from a, b where a.id >=  7901288 and a.id=b.id limit 1;
>NOTICE:  QUERY PLAN:
>
>Limit  (cost=0.00..4.97 rows=1 width=8)
>  ->  Nested Loop  (cost=0.00..1657.34 rows=333 width=8)
>        ->  Index Scan using a_pkey on a  (cost=0.00..45.50 rows=333 width=4)
>        ->  Index Scan using b_pkey on b  (cost=0.00..4.82 rows=1 width=4)
>
>EXPLAIN
>lo=# explain select * from a, b where b.id >=  7901288 and a.id=b.id limit 1;
>NOTICE:  QUERY PLAN:
>
>Limit  (cost=0.00..4.97 rows=1 width=8)
>  ->  Nested Loop  (cost=0.00..1657.34 rows=333 width=8)
>        ->  Index Scan using b_pkey on b  (cost=0.00..45.50 rows=333 width=4)
>        ->  Index Scan using a_pkey on a  (cost=0.00..4.82 rows=1 width=4)
>
>EXPLAIN
>
>which looks like the right thing.
>
>            regards, tom lane
>
>



pgsql-general by date:

Previous
From: Network Administrator
Date:
Subject: Re: Database Recovery Procedures
Next
From: info@casestudio.com (Vaclav Frolik)
Date:
Subject: Re: Visual database structure browser for postgresql?