开发者

A way to store a frequently queried column in SQLite?

开发者 https://www.devze.com 2023-03-19 04:01 出处:网络
I have a query that involves finding response times several times in a row, like so: ROUND(AVG(T.FinishTime-T.StartTime),3) AS \'Average\', MAX(T.FinishTime-T.StartTime) AS \'Max\', MIN(T.FinishTime-

I have a query that involves finding response times several times in a row, like so:

ROUND(AVG(T.FinishTime-T.StartTime),3) AS 'Average', MAX(T.FinishTime-T.StartTime) AS 'Max', MIN(T.FinishTime-T.StartTime)

Now, I don't fully understand how SQL processes this stuff in the background, but from my general knowledge of coding, is it not better to make the sub开发者_开发技巧traction T.FinishTime-T.StartTime more efficient? i.e. can the calculation be done once and then the aggregates found on that list of calculations? Or is it already done this way? I just want to try and cut my queries down into more efficient and readable chunks. I thought at first a view of T.FinishTime-T.StartTime could be made and that aggregates carried out on this, but then I read that views still calculate each time they are used.

Help appreciated!


Why do you think that calculation such a simple expression slows down your application by any significant amount?

Premature optimization is the root of all evil, they say. You may be wasting your time on something completely ineffectual. Profile first, optimize later. If you don't profile, don't optimize, period.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号