Skip to content

Fix: MySQL/MariaDB TIMESTAMP precision for message ordering (#3442) #3443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

seungwone
Copy link

Fixes #3442

The AddBatchPreparedStatement class uses AtomicLong.getAndIncrement() to create sequential millisecond timestamps, but MySQL/MariaDB's default TIMESTAMP precision (0) truncates this information, causing message ordering issues.

Added fractional seconds precision (TIMESTAMP(3)) to MySQL and MariaDB schemas to support millisecond-based message ordering in JdbcChatMemoryRepository.

Changes

  • schema-mysql.sql: Changed TIMESTAMP to TIMESTAMP(3)
  • schema-mariadb.sql: Changed TIMESTAMP to TIMESTAMP(3)

Copy link
Contributor

@sunyuhan1998 sunyuhan1998 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this PR itself is fine, but as @markpollack previously mentioned:

#3154 (comment)

this field is actually being used as an auto-incrementing sequence to ensure message ordering, rather than representing time in a temporal sense. Perhaps we should consider renaming this field in the future.

@YunKuiLu
Copy link
Contributor

YunKuiLu commented Jun 6, 2025

There is a common belief that TIMESTAMP can only be used until 2038. Perhaps it should be changed to BIGINT or DATETIME.

https://stackoverflow.com/questions/409286/should-i-use-the-datetime-or-timestamp-data-type-in-mysql

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

MySQL/MariaDB schema TIMESTAMP precision causes message ordering issues in JdbcChatMemoryRepository
5 participants