Repository navigation
test: latest_reading holds the GROUP BY recipe to reading the table once (#1339) - #1516
Merged
Merged
Conversation
…nce (#1339) docs/how-to.md says the GROUP BY form "reads the table once". Both twins compared only its rows, so a per-device subquery that returns the same rows and reads the table once per device passed every arm (#1339's test_latest_reading.py:96 entry, [weak]). New arm in both twins, "the GROUP BY form reads the table once": the form reads at least one block and no more than the table's pages. On PG17 it read 772 blocks of 922 (shell) and 677 of 812 (pytest). Mutation: the document's GROUP BY recipe as a per-device subquery over devices. Red on each of 15-19 in both twins (30695 and 16815 blocks), while "the GROUP BY form returns what DISTINCT ON returns" stayed green. The row arrives dated by it; census 4397 / 3055 never / 1342 dated. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
OffgridwithJD
approved these changes
Oct 16, 2026
OffgridwithJD
left a comment
Collaborator
There was a problem hiding this comment.
Measured
shell latest_reading.sh |
twin test_latest_reading.py |
|
|---|---|---|
| PG17 | 9/9 | 9 of 9 checks |
| PG18 | 9/9 | 9 of 9 checks |
- Reads: the shell's table is 922 pages and the GROUP BY read 772 blocks; the twin's is 812 pages and the GROUP BY read 677 blocks.
- Guards: 439 passed.
docs_style.shrc 0.
Red-first
I mutated the recipe in docs/how-to.md and ran main's suite and twin (old) against this PR's (new):
| recipe | old | new shell | new twin |
|---|---|---|---|
| your per-device subquery | green on both, PG17 and PG18 | read 30695 blocks … got [-29772] |
read 16815 … got -16002 |
reads the readings twice (UNION ALL with itself) |
green on both | read 1542 … got [-619] |
read 1356 … got -543 |
A reading of zero or nothing is refused on both sides: if grp else 0 makes at_least(0, 1) fail, and a non-numeric value fails check_num.
Ledger
- 4396 → 4397, with dated +1 and never unchanged at 3055.
- The gate is rc 0 against origin/main with both logs. Main's ledger with the new log reports "new this run=1", so the row is needed.
Non-blocking
The ceiling is "no more than the table's pages", and a clean run reads 84% of them. A recipe reading up to about 1.19× the table would still pass. That is fine for the claim "reads the table once".
Merge order
This changes the budget paragraph, as #1490, #1501, #1513 and #1517 do, so whichever lands later restates its counts. I'll restate mine.
🤖 Generated with Claude Code
This was referenced Oct 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the #1339 entry for
test_latest_reading.py:96[weak], in the High section, with the same fix in the shell twin.The defect
docs/how-to.mdsays the GROUP BY recipe "reads the table once". Both twins checked only that it returns the rowsDISTINCT ONreturns. A per-device subquery returns the same rows and reads the table once per device, and every arm stayed green.The fix
New arm in both twins: the GROUP BY form reads the table once. The form must read at least one block (a query that reads nothing is refused, as for the LATERAL arm) and no more than the table's pages.
Evidence
Mutation. I replaced the document's GROUP BY recipe with
SELECT d.device, (SELECT max(ts) FROM readings r WHERE r.device = d.device) FROM devices d ORDER BY 1.got [-29772] want [1]got -16002, wanted at least 1"The GROUP BY form returns what DISTINCT ON returns" stayed PASS on every major under the mutant. That proves the defect: the rows-only arm cannot see it.
Clean matrix. Shell 9/9 and pytest 9/9 on each of 15–19.
harness_selftest1246/1246. Collection 750 (unchanged). Guards 439 passed withPGC_REQUIRE=pyarrow.docs_style.shrc=0.Ledger. The new row arrives dated by the mutation above, majors 15–19. The census goes from 4396 to 4397 rows: 3055 never (unchanged) and 1342 dated. The gate has rc=0 and finds 0 orphans.
This conflicts with #1490 and #1501 in
check_ledger_budget.txtonly. Whichever lands later restates.🤖 Generated with Claude Code