Subject | Re: performance of subselect with group by |
---|---|
Author | Dmitry Yemanov |
Post date | 2014-12-16T07:27:42Z |
15.12.2014 23:27, bjoern.reimer@... wrote:
it's transformed into a correlated EXISTS equivalent:
select * from test where exists (
select * FROM test t
group by t.reference, t.key
having count(*) > 1 and min(t.Id) = ::id
)
Dmitry
>IN predicate is always evaluated for the every row, because internally
> select min(t.Id) FROM test t
> group by t.reference, t.key
> having count(*) > 1
>
> costs 1000 Non indexed reads
>
> select * from test where Id in (
> select min(t.Id) FROM test t
> group by t.reference, t.key
> having count(*) > 1
> )
>
> costs 1001000 non indexed reads
>
> Why?
it's transformed into a correlated EXISTS equivalent:
select * from test where exists (
select * FROM test t
group by t.reference, t.key
having count(*) > 1 and min(t.Id) = ::id
)
Dmitry