.... ...........

Contributed by Calpont, InfiniDB Community Edition is an open source, scale-up analytics database engine for your data warehousing, business intelligence and read-intensive application needs. Enabled via MySQLTM and purpose-built for an analytical workload with column-oriented technology at its core, the multi-threaded capabilities of InfiniDB Community Edition fully encompass query, transactional support and bulk load operations.  So come on in, grab a download and get started.

InfiniDB
Welcome, Guest
Please Login or Register.    Lost Password?
Conditions in aggregate/sum functions
(1 viewing) 1 Guest
Go to bottom
TOPIC: Conditions in aggregate/sum functions
#491
rasel200209
Senior Boarder
Posts: 56
graphgraph
User Offline Click here to see the profile of this user
Conditions in aggregate/sum functions 6 Months ago Karma: -1
we use many forms of this...

SUM( (case when (year = '2009' and week<=40
OR year = '2008' and week>=1) then 1 else 0
end) * myvalue ) as TYEAR

so there is a condition in the Sum function.

can infini enhance the speed where there are Case in the Sum?
 
Logged Logged
 
Last Edit: 2010/03/11 15:21 By rasel200209.
  The administrator has disabled public write access.
#492
jtommaney
Senior Boarder
Posts: 48
graphgraph
User Offline Click here to see the profile of this user
Re:Conditions in aggregate/sum functions 6 Months ago Karma: 4
The cost of the operation is likely related to the # of qualifying rows * the number of operations. You may be able to reduce the time slightly if you can simplify the number of steps in the expression. Here I have a compound date field I can express as a between clause rather than the compound logic show below.

Code:

mysql> select  sum(case when lo_orderdate between 19920101 and 19920630
    -> then 1 else 0 end  * lo_extendedprice) 1992_Q1_Q2_sum, count(*)
    -> from lineorder where lo_orderdate <= 19921231;
+--------------------+----------+
| 1992_Q1_Q2_sum     | count(*) |
+--------------------+----------+
| 138804076164817.00 | 91248844 |
+--------------------+----------+
1 row in set (5.90 sec)

mysql>
mysql>
mysql> select  sum(case when (year = 1992 and month <= 6 ) and (year = 1992 and month >= 1)
    -> then 1 else 0 end * lo_extendedprice) 1992_Q1_Q2_sum, count(*)
    -> from lineorder where lo_orderdate <= 19921231;
+--------------------+----------+
| 1992_Q1_Q2_sum     | count(*) |
+--------------------+----------+
| 138804076164817.00 | 91248844 |
+--------------------+----------+
1 row in set (7.81 sec)

mysql> select  sum(lo_extendedprice) 1992_Q1_Q2_sum, count(*)
    -> from lineorder where lo_orderdate <= 19921231;
+--------------------+----------+
| 1992_Q1_Q2_sum     | count(*) |
+--------------------+----------+
| 279113147753549.00 | 91248844 |
+--------------------+----------+
1 row in set (2.29 sec)

mysql> select  sum(1 * lo_extendedprice) 1992_Q1_Q2_sum, count(*)   from lineorder where lo_orderdate <= 19921231;
+--------------------+----------+
| 1992_Q1_Q2_sum     | count(*) |
+--------------------+----------+
| 279113147753549.00 | 91248844 |
+--------------------+----------+
1 row in set (4.54 sec)



There is definitely some overhead for inclusion of even a trivial function expression.
I'm not sure what else to recommend for you without access to the data model/queries.

Thanks - Jim Tommaney
Chief Product Architect
 
Logged Logged
  The administrator has disabled public write access.
Go to top