Mysql InnoDB表到elasticsearch : ON UPDATE CURRENT TIMESTAMP inside transaction

标签 mysql elasticsearch

我想让我的 MySQL 数据库表与相应的 elasticsearch 索引保持同步。我正在尝试编写自己的 cron 作业。 MySQL表有InnoDB引擎。我添加了 updated_at 列,即 CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP。我使用此查询来执行同步:

SELECT * FROM table WHERE updated_at>=bookmark;

我测试了一下,发现有些插入已经丢失了。

CURRENT_TMESTAMP 是否在 COMMIT 之前计算?

最佳答案

CURRENT_TIMESTAMP——NOW()的同义词——在调用它的查询执行开始时捕获它的值。无论查询运行多长时间,这些函数都会保持一个恒定值 - 因此在长时间运行更新等情况下,所有受影响的行都将具有相同的值,并且该值应该是每个单独的查询开始执行时的值 - 而不是提交时间。

NOW() returns a constant time that indicates the time at which the statement began to execute. (Within a stored function or trigger, NOW() returns the time at which the function or triggering statement began to execute.) This differs from the behavior for SYSDATE(), which returns the exact time at which it executes.

https://dev.mysql.com/doc/refman/5.7/en/date-and-time-functions.html#function_now

关于Mysql InnoDB表到elasticsearch : ON UPDATE CURRENT TIMESTAMP inside transaction,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40252077/

相关文章:

MySQL:更改外键列 - 但保持数据引用完整

elasticsearch - Elasticsearch -查询值

elasticsearch - 无法创建Elasticsearch映射

solr - 对mergefactor对搜索和索引的影响感到困惑

search - 在ElasticSearch中实现位置搜索

c++ - mysql_stmt_store_result() 上的 MySQL C API 崩溃

mysql - Active Record 模型与同一类的 2 个实例有关系

python - 为 Web 应用程序实现张量分解的最有效语言

javascript - 类似 Twitter 的推文框?

amazon-web-services - ELK堆栈(Elasticsearch,Logstash,Kibana)-logstash是必需的组件吗?