equivalence of aggregate and analytic functions?

Moderator: NorbertKrupa

Post Reply
dbmsuser7
Intermediate
Intermediate
Posts: 71
Joined: Tue Jan 28, 2014 3:03 am

equivalence of aggregate and analytic functions?

Post by dbmsuser7 » Tue Aug 19, 2014 4:01 pm

Are the following generally equivalent?

Code: Select all

SELECT DISTINCT
  a1,
  a2,
  COUNT(*) OVER w AS cnt,
  SUM(b) OVER w AS sum_b
FROM
  ...
WHERE
  ...
WINDOW w AS (PARTITION BY a1, a2);
and

Code: Select all

SELECT
  a1,
  a2,
  COUNT(*) AS cnt,
  SUM(b) AS sum_b
FROM
  ...
WHERE
  ...
GROUP BY a1, a2;
Or are there edge cases where they might not be?

id10t
GURU
GURU
Posts: 732
Joined: Mon Apr 16, 2012 2:44 pm

Re: equivalence of aggregate and analytic functions?

Post by id10t » Wed Aug 20, 2014 11:02 am

Hi!

[DELETED]
Last edited by id10t on Wed May 06, 2015 4:45 pm, edited 1 time in total.

dbmsuser7
Intermediate
Intermediate
Posts: 71
Joined: Tue Jan 28, 2014 3:03 am

Re: equivalence of aggregate and analytic functions?

Post by dbmsuser7 » Wed Aug 20, 2014 1:22 pm

sKwa,

Thanks for the reply (as usual!).

So there might be performance differences, but no differences in result?

scutter
Master
Master
Posts: 302
Joined: Tue Aug 07, 2012 2:15 am

Re: equivalence of aggregate and analytic functions?

Post by scutter » Wed Aug 20, 2014 1:41 pm

There is a difference in the results. Re-read what sKwa wrote:
Analytical function returns result for each row, while aggregative calculates for group and returns result per group. If you have "good" projection so aggregative function should work much more faster, i.e. with analytical function you returns a result per row and after it you are doing a grouping, while aggregate function calculates a value per group
—Sharon
Sharon Cutter
Vertica Consultant, Zazz Technologies LLC

dbmsuser7
Intermediate
Intermediate
Posts: 71
Joined: Tue Jan 28, 2014 3:03 am

Re: equivalence of aggregate and analytic functions?

Post by dbmsuser7 » Wed Aug 20, 2014 2:30 pm

Understood. But I'm not referring to the differences in output between aggregate and analytic functions in general, but rather the differences in output between the two queries I posted above.

scutter
Master
Master
Posts: 302
Joined: Tue Aug 07, 2012 2:15 am

Re: equivalence of aggregate and analytic functions?

Post by scutter » Wed Aug 20, 2014 2:55 pm

I see now what you’re asking - if using the DISTINCT keyword produces the same results as the analytical function. Yes - it would for these two queries.

—Sharon
Sharon Cutter
Vertica Consultant, Zazz Technologies LLC

dbmsuser7
Intermediate
Intermediate
Posts: 71
Joined: Tue Jan 28, 2014 3:03 am

Re: equivalence of aggregate and analytic functions?

Post by dbmsuser7 » Wed Aug 20, 2014 3:45 pm

Yes - it would for these two queries.
And there's no funny edge cases that are treated differently (e.g. NULLs in the grouping columns)?

Post Reply

Return to “Vertica SQL”