轮询MySQL表中新行的最快方法是什么? [英] What's the fastest way to poll a MySQL table for new rows?

查看:175
本文介绍了轮询MySQL表中新行的最快方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序需要轮询MySQL数据库以查找新行.每次添加新行时,都应检索它们.我正在考虑创建一个触发器,以将对新行的引用放置在单独的表上.原始表有超过300,000行.

My application needs to poll a MySQL database for new rows. Every time new rows are added, they should be retrieved. I was thinking of creating a trigger to place references to new rows on a separate table. The original table has over 300,000 rows.

该应用程序是用PHP构建的.

The application is built in PHP.

一些好的答案,我认为这个问题值得赏识.

Some good answers, i think the question deserves a bounty.

推荐答案

对于外部应用程序,我发现使用TimeStamp列是一种更强大的方法,与自动id和其他主键问题无关

For external applications I find using a TimeStamp column is a more robust method that is independent of auto id and other primary key issues

将列添加到表中,例如:

Add columns to the tables such as:

insertedOn TIMESTAMP DEFAULT CURRENT_TIMESTAMP

或跟踪插入和更新

updatedOn TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP

在外部应用程序中,您要做的只是跟踪进行轮询时的最后一个时间戳.然后从该时间戳中选择所有相关表.在大型表中,您可能需要索引时间戳列

In the external application all you need to do is track the last timestamp when you did a poll. Then select from that timestamp forward on all the relevant tables. In large tables you may need to index the timestamp column

这篇关于轮询MySQL表中新行的最快方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆