Click here to Skip to main content
15,881,687 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a table named MetricTbl with fields as User_Id, Entity, Metric, ModifiedDate, Value. Value, UserId are integer. Entity and Metric are nvarchar. Table has around 30 million rows.

I want to optimize the query -
SQL
select SUM(Value) from MetricTbl where UserId = 1 and Entity = 'Room' and Metric = 'Temperature'

I have to design a strategy for this kind of query. I am using azure federation. And this is a federated table.
I already created unique index on User_Id, Entity, Metric, ModifiedDate. Since it is azure federation so I cant have indexed views.
Please suggest some strategy.
If there is need I am allowed to create new table.
Thanks
Manish
Posted
Updated 28-Nov-13 3:18am
v2

1 solution

I would suggest you to use stored procedure[^] instead above query ;)
for example:
SQL
CREATE PROCEDURE GetSumOfUser
    @userid INT,
    @entity varchar(30),
    @metric varchar(30)
BEGIN
    SELECT SUM([Value])
    FROM MetricTabl
    WHERE userid = @userid AND entity=@entity AND metric =@metric
END


Useful articles:
Optimization Techniques for Windows Azure Role Sizes and Databases[^]
Windows Azure SQL Database Performance and Elasticity Guide[^]
Best Practices for Performance in Windows Azure Applications[^]
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 28-Nov-13 3:57am    
Good points, a 5.
—SA
Maciej Los 28-Nov-13 3:59am    
Thank you, Sergey ;)
ManishKr1608 28-Nov-13 7:18am    
Thanks Maciej Los,
I will read the links and try out with procedures. Let you know the findings...
Regards,
Manish
gvprabu 28-Nov-13 9:16am    
good collections....
Maciej Los 28-Nov-13 9:32am    
Thank you, Gopal ;)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900