Subject 2 Queries which should return the same
Author Ivar Abrahamsen <ivar@mindless.com>
I have these two queries.
And I was comparing the speeds ,
when I realised they were not returning the same value.

Both plans are natural.


select count(distinct ad.session) from accessdetails ad
where ad.recorded > current_timestamp - 10

union

select count(distinct ad.session) from accessdetails ad
having max(ad.recorded) > current_timestamp - 10



The first, which could be helped with an index, returns a smaller
value than the second from the accessdetails, which is a large table
of
1000s of simulatesd test users. The differance was 400 when the second
returned 5000 counts.

Anyone got an idea why they are different ?

Cheers,
Ivar