{
  "schema": "vedokrok.public-item.v1",
  "release_id": "VEDOKROK-SEL-5d86e1b23401e578",
  "url": "/knowledge/predict-rows-from-the-join-condition",
  "id": "MHC-D-RESEARCH-9715",
  "version": "0.1.0",
  "title": "Predict rows from the join condition",
  "summary": "A matching key does not promise a matching row.",
  "kind": "heuristic",
  "body": "For an inner join using only = on the full key, multiply the left and right counts for each shared key and add the products. Exclude NULL keys: = does not match them. Extra conditions can reduce this count; check them before treating fewer rows as an error.",
  "limits": [
    "Count using the actual key expressions and comparison rules. Outer joins or null-safe equality need a different calculation."
  ],
  "topics": [
    "critical-thinking"
  ],
  "intents": [],
  "source_ids": [
    "pg-joins",
    "pg-null"
  ],
  "evidence": [
    {
      "claim": "In PostgreSQL, a qualifying join produces an output row for each matching row pair; joining two independent one-to-many detail tables through the same parent can multiply rows before aggregation.",
      "source_id": "pg-joins",
      "role": "supports",
      "note": "Claim limit: This describes row multiplicity, not a universal query planner rule; choose aggregation only when the report needs one total per parent, and preserve row pairings when they are meaningful.\nSource reading history: selected_passages; 2026-10-11; Sections 7.2.1.1 Joined Tables; 7.2.1.3 Subqueries; 7.2.2 WHERE; 7.2.3 GROUP BY. Version 18 passages rechecked on 2026-10-11: matching row pairs, full ON conditions, derived tables, filtering and grouping. Grounds SQL semantics, not every engine's behavior or the effectiveness of the drafted reporting workflow.\nAgent release review: PostgreSQL 18 table expressions, NULL comparisons and aggregates, the UK Government Data Quality Framework and Microsoft Power Query profiling documentation were checked at the cited sections. The original examples and scope limits remain attached.",
      "locator": "Sections 7.2.1.1 Joined Tables and 7.2.1.3 Subqueries"
    },
    {
      "claim": "In PostgreSQL, ordinary comparisons involving NULL yield unknown; IS [NOT] DISTINCT FROM treats NULL as a comparable value.",
      "source_id": "pg-null",
      "role": "supports",
      "note": "Claim limit: Scalar comparisons in PostgreSQL 18. Composite keys and other engines require their own matching rules; this is not a query-planner guarantee.\nSource reading history: selected_passages; 2026-10-11; Section 9.2 Comparison Functions and Operators. Version 18 comparison passages rechecked on 2026-10-11: ordinary comparisons involving NULL and IS [NOT] DISTINCT FROM. Source reading is not production testing or proof of the drafted workflow.\nAgent release review: PostgreSQL 18 table expressions, NULL comparisons and aggregates, the UK Government Data Quality Framework and Microsoft Power Query profiling documentation were checked at the cited sections. The original examples and scope limits remain attached.",
      "locator": "Section 9.2 Comparison Functions and Operators"
    }
  ],
  "use_when": [
    "A join returns more or fewer rows than you expected."
  ],
  "avoid_when": [
    "Count using the actual key expressions and comparison rules. Outer joins or null-safe equality need a different calculation."
  ],
  "steps": [
    "Write the complete ON condition and any later filters.",
    "Compute per-key products for a plain inner equality join with non-null keys.",
    "Apply remaining conditions before comparing with the final output."
  ],
  "example": "Two left rows and two right rows give four pairs. An extra value condition may leave only one.",
  "check": "The count follows the actual matching rules and the intended row meaning.",
  "published_at": "2026-11-12T18:37:40Z",
  "review": {
    "kind": "agent",
    "label": "Agent editorial and scoped source review",
    "reviewed_at": "2026-11-12T18:37:40Z"
  },
  "knowledge_origin": {
    "release_id": "MHC-RPUB-20261112-20287590",
    "corpus_commit": "20287590ddd3999b7492df232822b6a0f7d114b1",
    "manifest_sha256": "2a987660d12de0ce2bde77a421424f7762af1ff77872ef41093fecc33db74a95",
    "projection_sha256": "2807da39bbe6a3dee2db32a76675ac5185f5a33e8b0a5cdd0c22a4731f3378a0",
    "published_at": "2026-11-12T18:37:40Z"
  },
  "editorial_overlay": null,
  "editorial": null,
  "notices": [],
  "sources": [
    {
      "id": "pg-joins",
      "title": "PostgreSQL 18: Table Expressions",
      "url": "https://www.postgresql.org/docs/18/queries-table-expressions.html"
    },
    {
      "id": "pg-null",
      "title": "PostgreSQL 18: Comparison Functions and Operators",
      "url": "https://www.postgresql.org/docs/18/functions-comparison.html"
    }
  ],
  "relations": [
    {
      "from": "MHC-D-RESEARCH-9715",
      "to": "MHC-D-RESEARCH-9719",
      "type": "use_before",
      "url": "/knowledge/aggregate-each-detail-table-before-joining-two-totals"
    }
  ],
  "collections": [
    {
      "id": "RC-MHC-UNION-DATA-JOINS-QUALITY-DIAGNOSTICS-2026",
      "title": "Diagnose data joins and quality before trusting a report",
      "url": "/collections/diagnose-data-joins-and-quality-before-trusting-a-report"
    }
  ],
  "topic_hubs": [
    {
      "id": "critical-thinking",
      "title": "Critical thinking and evidence",
      "url": "/topics/critical-thinking"
    }
  ],
  "solution_packs": []
}
