根据MySQL中的字段设计基于事件的触发器
目前,我正在研究一个系统,该系统每隔几个小时运行一次CRON工作来触发API调用。此调用可运行SQL查询,以获取今天或过去到期的所有活动收据。查询连接了3张表,并在30秒内完成甚至偶数时间,对DB造成了损失。由于可靠性问题,我并不是真正的粉丝,并且想重新设计它。
查询如下(我正在掩盖查询中的其他详细信息,但我收到了其他一些列等。) -
SELECT r.id, s.statementId, r.customerId
FROM receipt r
INNER JOIN statement s ON r.statementId = s.Id
LEFT JOIN customer c ON c.Id = r.customerId
WHERE c.location = 'US'
AND s.status = 'Active'
AND s.dueDate <= UTC_TIMESTAMP AND s.Canceled IS NULL
最初,我考虑在其上使用Redis并将到期日设置为到期日期。因此,每当钥匙到期时,我都可以收听按键事件并相应地处理数据。但是,这种方法首先是半烘焙的,因为它是缓存的,因此并非真正可靠。其次,我将不得不在失败的过程等上进行重试逻辑。
以前,在类似的问题中,我使用了DynamoDB的流来侦听在TTL上过期的数据。
我不是MySQL的专业人士,无论如何将其扔到那里看看你们是否对如何解决这个问题有任何想法?关于设计有什么建议吗?
Currently I am working on a system which runs a cron job every few hours to trigger an API call. This call runs a SQL query to get all the active receipts that are due end of today or past due. The query joins 3 tables and takes a toll on the DB as it takes >30 seconds to finish or even times out. I am not really a fan of this because of reliability issues and want to redesign it.
The query is as follows (I am masking other details from the query but I get a few other columns etc..)-
SELECT r.id, s.statementId, r.customerId
FROM receipt r
INNER JOIN statement s ON r.statementId = s.Id
LEFT JOIN customer c ON c.Id = r.customerId
WHERE c.location = 'US'
AND s.status = 'Active'
AND s.dueDate <= UTC_TIMESTAMP AND s.Canceled IS NULL
Initially I was thinking of using Redis on top of it and setting the due date as the expiration date. So whenever, a key expires, I could just listen to keyspace events and process data accordingly. However, this approach is half baked cuz first it's cache, so not really reliable. Second, I will have to do retry logic on failed processes etc..
Previously, in a similar problem I used DynamoDB's streams to listen to data that was getting expired at the ttl.
I am not a pro at MySQL by any means so throwing it out there to see if you guys have any ideas on how to work around this? Any suggestions on the design?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论