Skip to content

Fix missing null check and wrong cast in TimestampType comparisons#883

Open
Chessing234 wants to merge 1 commit intocmu-db:masterfrom
Chessing234:fix/timestamp-compare-bugs
Open

Fix missing null check and wrong cast in TimestampType comparisons#883
Chessing234 wants to merge 1 commit intocmu-db:masterfrom
Chessing234:fix/timestamp-compare-bugs

Conversation

@Chessing234
Copy link
Copy Markdown

Summary

Two correctness bugs in timestamp_type.cpp:

1. CompareNotEquals missing left.IsNull() check (line 34)

Only right.IsNull() is checked. If left is NULL and right is not, the function reads the NULL value's bit pattern and returns CmpTrue/CmpFalse instead of CmpNull. This violates SQL null semantics (NULL != x must be NULL). Every other Compare* method in this file checks left.IsNull() || right.IsNull().

2. CompareGreaterThan uses int64_t instead of uint64_t (line 61)

Timestamps are stored as uint64_t. Signed comparison via int64_t causes values with bit 63 set to be interpreted as negative, inverting the ordering for large timestamps. Every other Compare* method uses uint64_t.

Test plan

  • Verified all 6 Compare* methods — only these two are inconsistent
  • Confirmed timestamps use uint64_t storage (value_.timestamp_, SerializeTo, DeserializeFrom)
  • 2-line fix, pattern-consistent with sibling methods

1. CompareNotEquals: missing left.IsNull() check. Only right.IsNull()
   is checked, so comparing a NULL left timestamp against a non-NULL
   right returns CmpTrue/CmpFalse instead of CmpNull, violating SQL
   null semantics. Every other Compare* method checks both sides.

2. CompareGreaterThan: uses int64_t instead of uint64_t. Timestamps
   are stored as uint64_t; signed comparison causes large timestamp
   values (bit 63 set) to be treated as negative, inverting the
   ordering. Every other Compare* method uses uint64_t.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant