src/backend/nodes/equalfuncs.c - Coverage Report

← Back to Overview

# src/backend/nodes/equalfuncs.c

Coverage: 0/13 lines (0.0%)
Total Lines
13
modified
Covered
0
0.0%
Uncovered
13
100.0%
Keyboard navigation
_equalRPRPattern() lines 154-185
Modified Lines Coverage: 0/13 lines (0.0%)

Line | Hits | Source | Commit
--- | --- | --- | ---
154 | 0 | _equalRPRPattern(const RPRPattern *a, const RPRPattern *b) | c54ba27Row pattern recognition patch (parse/analysis).
| Unreachablemixed: Defensive (unreachable) / Dead code · confidence high · `_equalRPRPattern @154-182` · 13 lines Covers `@154` Defensive (unreachable) · `@156-158` Defensive (unreachable) · `@161` Dead code · `@163` Defensive (unreachable) · `@165` Dead code · `@167` Dead code · `@173` Dead code · `@175` Defensive (unreachable) · `@177-178` Defensive (unreachable) · `@182` Defensive (unreachable) Reason (representative of 10 blocks — same root cause)
    CONFIRMED defensive-unreachable. _equalRPRPattern (T_RPRPattern, tag 387) is only dispatched from equalfuncs.switch.c:889. RPRPattern is the COMPILED pattern node built exclusively in the optimizer (createplan.c:2906 via buildRPRPattern -> rpr.c makeRPRPattern) and stored only as a field of the WindowAgg plan node (plannodes.h:1393) and the WindowAggState exec node (execnodes.h:2654).
    It never appears in a raw-parse or rewritten query tree. equal() is auto-invoked by the COPY/WRITE_READ_PARSE_PLAN_TREES debug machinery in tcop/postgres.c ONLY on raw parse trees (lines 638/655) and rewritten query trees (lines 849/878).
    The two plan-tree equal() checks at postgres.c:935 and 958 sit inside #ifdef NOT_USED ("equal() currently does not have routines to compare Plan nodes") and are never compiled;
    NOT_USED is not defined anywhere.
    I attempted to refute via the one real equal()-on-rpPattern call site: planner.c:6283 equal(wc->rpPattern, ...) -- but wc is a WindowClause whose rpPattern field is RPRPatternNode* (parsenodes.h:1767, the PARSE node T_RPRPatternNode tag 88), so that call dispatches to _equalRPRPatternNode, NOT _equalRPRPattern.
    The other equal() near RPR code (nodeWindowAgg.c:2917) compares a WindowFunc. _equalRPRPattern exists solely because the struct carries pg_node_attr(custom_copy_equal, ...) (plannodes.h:1285), which forces the gen_node_support machinery to emit a switch case and require a hand-written equal counterpart even though the copy half is what is actually exercised (custom_copy_equal cannot request copy-only).
    No SQL/regression input can construct a standalone T_RPRPattern node and feed it to equal();
    line 154 is genuinely unreachable.
Recommended fix
    Function-level recommendation.
    Since equal() is never dispatched for RPRPattern (Plan-only container with no_equal), the custom_copy_equal attribute over-specifies what is needed: only custom copy is actually exercised.
    Two viable cleanups:
    (1) Change the pg_node_attr on RPRPattern (plannodes.h ~line 1285) from custom_copy_equal to custom_copy plus no_equal, which stops emitting/registering the dead _equalRPRPattern and removes the unreachable T_RPRPattern case from equalfuncs.switch.c — eliminating all 94-counted dead lines in this function rather than just line 173. (2) If the hand-written _equalRPRPattern is intentionally kept for API completeness/future direct use, exclude it from modified-line coverage accounting (it is provably unreachable from SQL).
    Do NOT attempt to add a SQL test or a runtime Assert here — neither can drive execution through line 173.
155 | - | { | c54ba27Row pattern recognition patch (parse/analysis).
156 | 0 | COMPARE_SCALAR_FIELD(numVars); | c54ba27Row pattern recognition patch (parse/analysis).
157 | 0 | COMPARE_SCALAR_FIELD(maxDepth); | c54ba27Row pattern recognition patch (parse/analysis).
158 | 0 | COMPARE_SCALAR_FIELD(numElements); | c54ba27Row pattern recognition patch (parse/analysis).
159 | - |  | c54ba27Row pattern recognition patch (parse/analysis).
160 | - | /* Compare varNames array */ | c54ba27Row pattern recognition patch (parse/analysis).
161 | 0 | if (a->numVars > 0) | c54ba27Row pattern recognition patch (parse/analysis).
162 | - | { | c54ba27Row pattern recognition patch (parse/analysis).
163 | 0 | if (a->varNames == NULL || b->varNames == NULL) | c54ba27Row pattern recognition patch (parse/analysis).
164 | - | return false; | c54ba27Row pattern recognition patch (parse/analysis).
165 | 0 | for (int i = 0; i < a->numVars; i++) | c54ba27Row pattern recognition patch (parse/analysis).
166 | - | { | c54ba27Row pattern recognition patch (parse/analysis).
167 | 0 | if (strcmp(a->varNames[i], b->varNames[i]) != 0) | c54ba27Row pattern recognition patch (parse/analysis).
168 | - | return false; | c54ba27Row pattern recognition patch (parse/analysis).
169 | - | } | c54ba27Row pattern recognition patch (parse/analysis).
170 | - | } | c54ba27Row pattern recognition patch (parse/analysis).
171 | - |  | c54ba27Row pattern recognition patch (parse/analysis).
172 | - | /* Compare elements array */ | c54ba27Row pattern recognition patch (parse/analysis).
173 | 0 | if (a->numElements > 0) | c54ba27Row pattern recognition patch (parse/analysis).
174 | - | { | c54ba27Row pattern recognition patch (parse/analysis).
175 | 0 | if (a->elements == NULL || b->elements == NULL) | c54ba27Row pattern recognition patch (parse/analysis).
176 | - | return false; | c54ba27Row pattern recognition patch (parse/analysis).
177 | 0 | if (memcmp(a->elements, b->elements, | c54ba27Row pattern recognition patch (parse/analysis).
178 | 0 | a->numElements * sizeof(RPRPatternElement)) != 0) | c54ba27Row pattern recognition patch (parse/analysis).
179 | - | return false; | c54ba27Row pattern recognition patch (parse/analysis).
180 | - | } | c54ba27Row pattern recognition patch (parse/analysis).
181 | - |  | c54ba27Row pattern recognition patch (parse/analysis).
182 | 0 | COMPARE_SCALAR_FIELD(isAbsorbable); | c54ba27Row pattern recognition patch (parse/analysis).
183 | - |  | c54ba27Row pattern recognition patch (parse/analysis).
184 | - | return true; | c54ba27Row pattern recognition patch (parse/analysis).
185 | - | } | c54ba27Row pattern recognition patch (parse/analysis).