SQL:显示一段时间间隔内(接近)实时站点活动的最佳方式是什么?即“过去一小时内发送的消息”
目标是尽可能频繁地更新 UI,但性能是一个问题,并且应尽量减少对数据库的访问。
我使用索引视图来保持不是特定时间间隔的项目的最新统计信息,但这不适用,因为日期是不确定的。
其他选项是:
每 X 分钟运行一次作业来收集统计信息。
添加触发器以响应插入。
每次/以定义的频率运行存储过程。 (大多数相关表已在相关日期建立索引)
是否还有我尚未确定的其他选项以及针对此类问题是否有“首选”解决方案?作业/触发器/SP 选项如何比较?
The goal is to update the UI as frequently as possible but performance is a concern and hits to the database should be minimised.
I used Indexed Views to keep up to date stats on items that were not for a specific time interval however this in not applicable as the date is non-deterministic.
Other options would be to:
Run a job every X minutes to gather the stats.
Add triggers to respond to insertions.
Run a stored procedure every time / at a defined frequency. (Most of the tables concerned are already indexed on the date concerned)
Are there any other options I haven't identified and is there a 'preferred' solution to this kind of problem? How do the Job/Trigger/SP options compare?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您运行的时间间隔是“固定”的,则可以使用存储聚集索引键的查找表。假设密钥是
INT Identity
,您可以创建一个如下表:运行一个执行以下操作的查询:
然后使用
MAX(ClusterKey)
的新相关值更新该表。您需要计算出用例的详细信息,但是如果您有一个 1 行表,您只需在查询时保持最新状态,并且它使用簇键作为参考点,那么应该非常快地获得自上次更新以来行数的增量。
If you are running over "fixed" intervals, you can use a lookup table that stores your clustered index key. Assuming the key is an
INT Identity
you could make a table like:Run a query that executes:
Then update the table with the new relevant value for
MAX(ClusterKey)
.You would need to work out details for your use case, but if you have a 1 row table that you just keep up to date as you query, and it uses the cluster key as a reference point, it should be very fast to get a delta on the number of rows since the last update.