Skip to content

server: an index with a timestamp in it is looked up by every field - #4

Merged
lesomnus merged 1 commit into
mainfrom
pick-time-in-index
Oct 10, 2026
Merged

lesomnus merged 1 commit into
mainfrom
pick-time-in-index

Conversation

@lesomnus

Copy link
Copy Markdown
Member

Fixes #2.

The bug

In the generated pick<Entity> for a unique index, every field appended its predicate and the case ended in And(ps...). A timestamp was the exception: it returned its own predicate where it stood.

return ShiftStartsAtEQ(k.GetStartsAt().AsTime()), nil

For an index made of one timestamp that was right by accident. For (desk, starts_at) it dropped the desk, so a reference matched every row at that time, and Get answered whichever row the database returned first. With the timestamp in the middle of an index, the fields after it were never read either.

The fix

The timestamp is appended like the others:

ps = append(ps, ShiftStartsAtEQ(k.GetStartsAt().AsTime()))

Tests

  • internal/apptest gains Shift, unique over (desk, starts_at).
  • TestRefByAnIndexWithATimestamp adds two shifts at one time at desks a and b, and checks that each is found by its own desk. A third desk, or the same desk at another minute, is NotFound. It fails on the old code.
  • buf generate (twice), go generate, build, and tests in the root, runtime and internal/apptest pass, with internal/apptest also run on PostgreSQL 17.

Also in this PR

Generating Shift needed protoc-gen-orm-go f9ac5b6 (protobuf-orm/protoc-gen-orm-go#2, merged). Before it, the query constructors took a timestamp by value and did not compile (protobuf-orm/protoc-gen-orm-go#1). The tool pin in go.mod is bumped for that.

🤖 Generated with Claude Code

https://claude.ai/code/session_01KxtnpRW533bdErnW8QPhsk

In the lookup by a unique index, every field appended its predicate and
the case ended in `And(ps...)` -- except a timestamp, which returned its
own predicate where it stood. For an index of one timestamp that was the
right answer by accident. For (desk, starts_at) it dropped the desk, so a
reference matched every row at that time and Get answered whichever the
database returned first. It is appended like the rest now.

internal/apptest has a Shift, unique over (desk, starts_at), and a test
that two shifts at one time are told apart by their desks; it fails on
the old code. Generating it needed protoc-gen-orm-go f9ac5b6, whose
constructors took a timestamp by value and did not compile
(protobuf-orm/protoc-gen-orm-go#1), so the tool is bumped with it.

Fixes #2

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01KxtnpRW533bdErnW8QPhsk
@lesomnus
lesomnus merged commit 6735880 into main Oct 10, 2026
2 checks passed
@lesomnus
lesomnus deleted the pick-time-in-index branch October 10, 2026 07:08
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.

A unique index with a timestamp among its fields is looked up by the timestamp alone

1 participant