← 1.0.0 backlogs ISS-1

The covering index is built, decoded per entry, then discarded

Type
Debt
Found while
SAPE-20
Triage
Defer
Status
Open
Severity
Low — wasted work on every scan, never a wrong answer

Description

An index may be declared to carry fields (Index.Include). The write path builds that payload for every entry: Collection.include (internal/store/collection.go:489) marshals the carried fields into the entry's value. The read path decodes it — Collection.Scan (internal/store/scan.go:137-141) unmarshals it into Found.Include for every entry it visits — and then the only caller that matters throws it away.

internal/store/invoke.go:246-253, the scan branch of a declared operation:

return collection.Scan(operation.Index, within, func(entry Found) bool {
	document, found, err := collection.Get(entry.Key)
	...
	return visit(entry.Key, document)
})

So the cost is paid three times — written on every put, decoded on every entry of every scan, and then a full document fetch anyway — and the saving it exists for is never taken.

Evidence

Triage

Does it lose data, break a promise on a public surface, or stop somebody installing and running? No, no, and no. Every answer is correct; the document fetch returns the same fields the index carried plus the rest. Nobody can observe this except by measuring how long a scan takes, and no declared behaviour changes when it is fixed.

The one thing that is a promise is the sentence in scan.go's doc — but it is a Go doc comment on an internal/ package, not a public surface. Fixing the sentence costs nothing and can happen any time; fixing the mechanism is a change to the hottest loop in the store and wants a benchmark first. Defer.

If deferred, what it costs to wait