|
| 1 | +# TASK-110: Zig PK UPDATE — Compound/Text PK tombstone fix |
| 2 | + |
| 3 | +## Status |
| 4 | +- [x] Planned |
| 5 | +- [ ] Assigned |
| 6 | +- [ ] In Progress |
| 7 | +- [ ] Blocked (reason: ...) |
| 8 | +- [ ] Complete |
| 9 | + |
| 10 | +## Priority |
| 11 | +medium |
| 12 | + |
| 13 | +## Assigned To |
| 14 | +(unassigned) |
| 15 | + |
| 16 | +## Parent Docs / Cross-links |
| 17 | +- Parent task: `.tasks/done/TASK-105-zig-pk-update-must-emit-tombstone-and-insert.md` |
| 18 | +- Test harness: `zig/harness/test-pk-update.sh` |
| 19 | +- Zig implementation: `zig/src/as_crr.zig` |
| 20 | + |
| 21 | +## Description |
| 22 | +TASK-105 implemented PK UPDATE tombstone semantics for integer PKs, but compound/text PK updates still fail. |
| 23 | + |
| 24 | +### Root Cause |
| 25 | +When rowid doesn't change (compound/text PKs), the new sentinel overwrites the tombstone because: |
| 26 | +- Clock table uses `rowid` as the key |
| 27 | +- For integer PKs, rowid = pk value (changes on update) |
| 28 | +- For compound/text PKs, rowid is auto-assigned (doesn't change on update) |
| 29 | +- When creating tombstone then new entries, they share the same rowid |
| 30 | + |
| 31 | +### Failing Tests (5) |
| 32 | +- Test 1d: Clock table queries for integer PK (test issue — uses blob-encoded pk) |
| 33 | +- Test 2b: Compound PK (a,b) tombstone not created |
| 34 | +- Test 3b: Full compound PK update tombstone not created |
| 35 | +- Test 4b: Text PK (sku) tombstone not created |
| 36 | + |
| 37 | +### Potential Solutions |
| 38 | +1. **Store pk blob in clock table** instead of rowid |
| 39 | +2. **Use separate tombstone tracking table** |
| 40 | +3. **Create separate pks entries for tombstoned pk blobs** |
| 41 | + |
| 42 | +## Files to Modify |
| 43 | +- `zig/src/as_crr.zig` — trigger generation |
| 44 | +- `zig/src/changes_vtab.zig` — potentially clock table schema |
| 45 | +- `zig/harness/test-pk-update.sh` — may need test fixes |
| 46 | + |
| 47 | +## Acceptance Criteria |
| 48 | +- [ ] All 16 tests in `bash zig/harness/test-pk-update.sh` pass |
| 49 | +- [ ] No regression in `make -C zig test-parity` |
| 50 | +- [ ] Compound PK update creates tombstone for old PK |
| 51 | +- [ ] Text PK update creates tombstone for old PK |
| 52 | + |
| 53 | +## Reproducible Command |
| 54 | +```bash |
| 55 | +cd /Users/tom/Developer/effect-native/cr-sqlite |
| 56 | +bash zig/harness/test-pk-update.sh |
| 57 | +# Current: 11 PASS, 5 FAIL |
| 58 | +# Target: 16 PASS, 0 FAIL |
| 59 | +``` |
| 60 | + |
| 61 | +## Progress Log |
| 62 | +### 2025-12-20 |
| 63 | +- Task created as follow-up from TASK-105 |
| 64 | + |
| 65 | +## Completion Notes |
0 commit comments