From 3cce6a80c92b3c7f5dbc6d9ad56bf856e9a93624 Mon Sep 17 00:00:00 2001 From: "Joshua D. Drake" Date: Fri, 28 Aug 2026 14:46:38 -0600 Subject: [PATCH] test: anchor the cost read on the scan node, not on the first plan line (#753) Review nit from #820, and it is the same class of defect the suite exists to catch, so it should not have been in the suite. serial_cost read the cost with `grep -m1`, which returns whatever node comes first. The plan under test is a bare columnar scan today, so the first node IS the scan. The moment a node appears above it the helper reports that node's cost instead, silently and with a plausible value. Demonstrated on a plan with an aggregate above the scan: Aggregate (cost=66119.86..66119.87 ...) -> Custom Scan (PgColumnarScan) on c753 (cost=0.00..61101.78 ...) grep -m1 form 66119.87 <- the aggregate anchored form 61101.78 <- the scan The helper now selects the PgColumnarScan line first. Two premises assert the anchor found exactly one such node on each arm, so a plan that stops being a single columnar scan reds the premise instead of quietly costing something else. The suite is 9 of 9, up from 7, and the two new checks are premises rather than assertions about the product. Reported by OffgridwithJD in review of #820. Co-Authored-By: Claude Opus 5 (1M context) Claude-Session: https://claude.ai/code/session_017Y7gXubmW8DDDZPZNPXJHm --- test/doc_parallel_premise.sh | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/test/doc_parallel_premise.sh b/test/doc_parallel_premise.sh index 250a465..5ffb17b 100755 --- a/test/doc_parallel_premise.sh +++ b/test/doc_parallel_premise.sh @@ -98,11 +98,20 @@ total_groups() { explain_of "$1" | sed -n 's/.*Chunk Groups Total: \([0-9]*\).*/ # The post-#821 figure is 4212 x 3/10, and EXPLAIN ANALYZE reports "Chunk Groups # Read: 3 of 10", so the estimate now agrees with the scan it prices. The check # below asserts the ORDERING of the two costs, which holds on either side. -serial_cost() { +# Anchored on the scan node rather than on the first cost= in the plan. +# `grep -m1` returns whatever node comes first, so the moment the plan gains a +# node above the scan it reports that node's cost instead, silently and with the +# right shape. That is the same class of defect this suite exists to catch, so +# the suite should not contain one. +plan_of() { q "SET max_parallel_workers_per_gather = 0; SET pgcolumnar.stripe_row_limit = 20000; - EXPLAIN SELECT sel, a, b FROM c753 WHERE $1 <= $(p25 "$1")" \ - | grep -m1 -oE 'cost=[0-9.]+\.\.[0-9.]+' | sed 's/.*\.\.//' + EXPLAIN SELECT sel, a, b FROM c753 WHERE $1 <= $(p25 "$1")" +} +scan_lines() { plan_of "$1" | grep -c 'PgColumnarScan'; } +serial_cost() { + plan_of "$1" | grep 'PgColumnarScan' \ + | grep -oE 'cost=[0-9.]+\.\.[0-9.]+' | sed 's/.*\.\.//' | head -1 } doc_read=$(read_groups "$doc_col"); doc_tot=$(total_groups "$doc_col") @@ -132,6 +141,10 @@ check "the documented column is not the one stored in order" \ # Exact rather than bounded: reading more groups must cost more. A bound here # would need calibrating and the direction does not. if [ "$doc_col" != "sel" ]; then + for _c in "$doc_col" sel; do + check "premise: the $_c plan is exactly one columnar scan node" \ + "$(scan_lines "$_c")" "1" + done dc=$(serial_cost "$doc_col"); sc=$(serial_cost sel) echo "-- serial cost: $doc_col $dc, sel $sc" check "and the documented column is costed above the ordered one" \