16 квітня 2010 р. 16:21 Yeb Havinga <yebhavi...@gmail.com> написав:

> Віталій Тимчишин wrote:
>
>>
>> BTW: Changing slow query to inner joins do not make it fast
>>
> I'm interested to see the query andplan of the slow query with inner joins.
>
>
> Here you are. The query:

select * from company this_ inner join company_tag this_1_ on
this_.id=this_1_.company_id
inner join company_measures companymea2_ on
this_.id=companymea2_.company_id
inner join company_descr ces3_ on this_.id=ces3_.company_id
where this_1_.tag_id = 7 and this_.id>50000000
order by this_.id asc
limit 1000
;
Total runtime: 14088.942 ms
(plan is attached)

Best regards, Vitalii Tymchyshyn
Limit  (cost=227.15..883.22 rows=1000 width=1209) (actual 
time=14062.106..14087.375 rows=1000 loops=1)
  ->  Merge Join  (cost=227.15..4355277.70 rows=6638046 width=1209) (actual 
time=14062.101..14084.577 rows=1000 loops=1)
        Merge Cond: (this_.id = (this_1_.company_id)::bigint)
        ->  Merge Join  (cost=185.14..4025978.59 rows=6757358 width=1193) 
(actual time=10692.975..10708.923 rows=1054 loops=1)
              Merge Cond: ((companymea2_.company_id)::bigint = this_.id)
              ->  Merge Join  (cost=0.00..1784574.44 rows=6821672 width=570) 
(actual time=0.111..9138.804 rows=1097096 loops=1)
                    Merge Cond: ((companymea2_.company_id)::bigint = 
(ces3_.company_id)::bigint)
                    ->  Index Scan using pk_comp_ms on company_measures 
companymea2_  (cost=0.00..456350.36 rows=6821672 width=68) (actual 
time=0.066..1747.291 rows=1097096 loops=1)
                    ->  Index Scan using cws_company_descr_unique on 
company_descr ces3_  (cost=0.00..1225899.00 rows=6821672 width=502) (actual 
time=0.033..1822.085 rows=1097096 loops=1)
              ->  Index Scan using pk_comp_m on company this_  
(cost=0.00..2139324.53 rows=6886598 width=623) (actual time=0.026..1.853 
rows=1054 loops=1)
                    Index Cond: (this_.id > 50000000)
        ->  Index Scan using company_tag_company_id_idx on company_tag this_1_  
(cost=0.00..229167.56 rows=6765004 width=16) (actual time=0.028..1859.967 
rows=1075634 loops=1)
              Filter: ((this_1_.tag_id)::bigint = 7)
Total runtime: 14088.942 ms

-- 
Sent via pgsql-performance mailing list (pgsql-performance@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-performance

Reply via email to