Skip to Main Content

Oracle Database Discussions

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Analytic function performance vs Aggregation function performance

User_3DSZWMay 11 2021

Hi, I'm new to analytic functions, and there's something I don't understand about their performance compared to aggregation functions.
I have a LINEITEM table with 1,800,093 rows, and I am trying to find any row whose l_extendedprice is within the range of min(l_extendedprice) and max(l_extendedprice).
I have tried two queries, one with an aggregation function and one with an analytic function, and there's a significant difference in terms of the CPU costs when I list the query processing plans.
The query that uses the aggregation function is as follows:
image.pngimage.pngThe query that uses analytic functions is as follows:
image.pngimage.pngCan anyone please help me explain the difference in terms of CPU costs? Why does the second query cost less even though it is trying to access the table three times, while the first query only accesses the table twice?
My best guess is that the second query reads the data into the buffer, sorts the data for the first time to find the min_price, then uses the previously sorted data which is still in the buffer to find the max_price. It might explain why the first table access full for the second query is expensive but the subsequence operations are not. But I am not sure if that's the case, and I couldn't find any source that would support my guess.
Can anyone please help me explain it? I would deeply appreciate it.

This post has been answered by Jonathan Lewis on May 12 2021
Jump to Answer
Comments
Post Details
Added on May 11 2021
1 comment
437 views