HarperFast / HarperFast/harper

Composite/array-valued PK tables: secondary-index lookup by an array value returns 0 rows (breaks @relationship to/from them)

Open
#1,485 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
89
Forks
10
Avg merge
2d 6h
Merged PRs (30d)
200

Description

Tables keyed by a **composite / array-valued primary key** (`["tenantA","rec1"]` — the documented composite-key pattern) work for range/prefix scans and ordering, but a **secondary-index lookup by an array value returns 0 rows**, which makes composite-PK tables unusable as `@relationship` targets.

**The defect:** `search_by_conditions` `equals` on an `Any @indexed` field holding an **array** value returns **0 rows** despite matching records existing — the secondary-index path doesn't match array-valued index keys. Consequences:
1. A `@relationship(to:)` **reverse** expansion over a composite-PK target returns **0 refs silently** (looks like "no relations", not an error — the dangerous leg).
2. **Forward** expansion via an array-valued FK 500s (`TypeError ...reading 'then'` at `Resource.ts:808` — the same crash as #1415).

**Correct/clean:** `search_type:'prefix'` on the first component works (the high-value per-tenant range scan); numeric 2nd-component ordering is numeric (not string-coerced); boundary cases round-trip.

**Secondary:** an ops `insert` of a **duplicate composite PK** silently overwrites (200) rather than 409-ing as a scalar PK does.

**Severity:** medium — composite-PK + relationships is a real (if not ubiquitous) combination; the silent-empty reverse expansion is the dangerous part.

**Fix:** fix secondary-index equality matching for array-valued index keys (so `search_by_value`/conditions and `@relationship` reverse-expansion find composite-PK rows). The forward-expansion 500 is #1415.

**Also (doc):** REST addressing of a composite PK needs `encodeURIComponent(JSON.stringify(pk))`, and an ops-seeded composite-PK row is not REST-GETtable.

**Repro:** `npm run test:integration -- "integrationTests/qa-scratch/qa348-composite-pk.test.ts"`

— filed by KrAIs (Claude) on Kris's behalf (qa-explorer campaign, main @ 28db4fde4 v5.1.12)

Contributor guide

Open the contributing guide

Research direction

Start by running npm run test:integration -- "integrationTests/qa-scratch/qa348-composite-pk.test.ts" and trace search_by_conditions equality through the secondary-index path. Inspect the array-valued lookup behavior and the relationship expansion involving Resource.ts:808; done means matching composite-PK rows are found by secondary-index equality and the reverse relationship expansion no longer returns zero rows silently.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
api, backend, databases, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.