Mikey C uttered:


Is there any performance or other gain in writing:

select sum(column_a) + sum(column_b)

vs

select sum(column_a + column_b)


The second should be faster, as I'd expect aggregate functions to be more expensive than expression additions. The second would have half the aggregate function calls, but twice as many additions.



???????????


Your best bet is to try it. A quick test on my box using the schema:
  CREATE TABLE foo(a,b);

Then inserting 2^20 records of (1,2).

Doing the first select, I get about 1.0 seconds wall clock time. Using the second, I get 0.9 seconds wall clock time, so about 10% quicker.

Increasing the row count to 2^22, I get 3.95 and 3.45 respectively.

Christian


--
    /"\
    \ /    ASCII RIBBON CAMPAIGN - AGAINST HTML MAIL
     X                           - AGAINST MS ATTACHMENTS
    / \

Reply via email to