{
  "experiment_date": "2026-10-18",
  "environment": {
    "python": "3.12.14",
    "implementation": "CPython",
    "sqlite": "3.53.1",
    "platform": "macOS-27.0.1-arm64-arm-64bit"
  },
  "scope": "Synthetic in-memory examples; no production data, benchmark, or other DB engine tested.",
  "foreign_keys_enabled": true,
  "fixture_sql": "PRAGMA foreign_keys = ON;\nCREATE TABLE orders (\n    id INTEGER PRIMARY KEY,\n    total_cents INTEGER NOT NULL CHECK(total_cents >= 0)\n);\nCREATE TABLE payments (\n    id INTEGER PRIMARY KEY,\n    order_id INTEGER NOT NULL REFERENCES orders(id),\n    amount_cents INTEGER NOT NULL CHECK(amount_cents >= 0),\n    status TEXT NOT NULL CHECK(status IN ('settled', 'pending'))\n);\nCREATE TABLE order_items (\n    id INTEGER PRIMARY KEY,\n    order_id INTEGER NOT NULL REFERENCES orders(id),\n    label TEXT NOT NULL\n);\nINSERT INTO orders VALUES (1, 10000), (2, 10000), (3, 6000), (4, 4000);\nINSERT INTO payments VALUES\n    (11, 1, 6000, 'settled'), (12, 1, 4000, 'settled'),\n    (21, 2, 10000, 'pending'), (31, 3, 6000, 'settled');\nINSERT INTO order_items VALUES (101, 1, 'A'), (102, 1, 'B'), (103, 1, 'C');",
  "queries": {
    "baseline": "SELECT COUNT(*) AS order_count, SUM(total_cents) AS order_cents\nFROM orders;",
    "joined_rows": "SELECT o.id AS order_id, o.total_cents,\n       p.id AS payment_id, p.amount_cents\nFROM orders AS o\nLEFT JOIN payments AS p\n  ON p.order_id = o.id AND p.status = 'settled'\nORDER BY o.id, p.id;",
    "joined_totals": "SELECT COUNT(*) AS joined_rows,\n       COUNT(p.id) AS payment_count,\n       COUNT(DISTINCT o.id) AS order_count,\n       SUM(o.total_cents) AS wrong_order_cents,\n       SUM(DISTINCT o.total_cents) AS distinct_amount_cents\nFROM orders AS o\nLEFT JOIN payments AS p\n  ON p.order_id = o.id AND p.status = 'settled';",
    "per_order_counts": "SELECT o.id AS order_id, COUNT(*) AS joined_rows,\n       COUNT(p.id) AS payment_count\nFROM orders AS o\nLEFT JOIN payments AS p\n  ON p.order_id = o.id AND p.status = 'settled'\nGROUP BY o.id\nORDER BY o.id;",
    "grouped_order_totals": "SELECT o.id AS order_id, SUM(o.total_cents) AS wrong_order_cents\nFROM orders AS o\nLEFT JOIN payments AS p\n  ON p.order_id = o.id AND p.status = 'settled'\nGROUP BY o.id\nORDER BY o.id;",
    "preaggregated_rows": "WITH paid AS (\n  SELECT order_id, COUNT(*) AS payment_count,\n         SUM(amount_cents) AS paid_cents\n  FROM payments\n  WHERE status = 'settled'\n  GROUP BY order_id\n)\nSELECT o.id AS order_id, o.total_cents,\n       COALESCE(paid.payment_count, 0) AS payment_count,\n       COALESCE(paid.paid_cents, 0) AS paid_cents\nFROM orders AS o\nLEFT JOIN paid ON paid.order_id = o.id\nORDER BY o.id;",
    "preaggregated_totals": "WITH paid AS (\n  SELECT order_id, SUM(amount_cents) AS paid_cents\n  FROM payments\n  WHERE status = 'settled'\n  GROUP BY order_id\n)\nSELECT COUNT(*) AS order_count,\n       COALESCE(SUM(o.total_cents), 0) AS order_cents,\n       COALESCE(SUM(paid.paid_cents), 0) AS paid_cents\nFROM orders AS o\nLEFT JOIN paid ON paid.order_id = o.id;",
    "exists_orders": "SELECT o.id AS order_id, o.total_cents\nFROM orders AS o\nWHERE EXISTS (\n  SELECT 1 FROM payments AS p\n  WHERE p.order_id = o.id AND p.status = 'settled'\n)\nORDER BY o.id;",
    "where_filter": "SELECT o.id AS order_id, p.id AS payment_id\nFROM orders AS o\nLEFT JOIN payments AS p ON p.order_id = o.id\nWHERE p.status = 'settled'\nORDER BY o.id, p.id;",
    "where_or_null": "SELECT o.id AS order_id, p.id AS payment_id\nFROM orders AS o\nLEFT JOIN payments AS p ON p.order_id = o.id\nWHERE p.status = 'settled' OR p.id IS NULL\nORDER BY o.id, p.id;",
    "two_children_rows": "SELECT o.id AS order_id, p.id AS payment_id, i.id AS item_id\nFROM orders AS o\nLEFT JOIN payments AS p\n  ON p.order_id = o.id AND p.status = 'settled'\nLEFT JOIN order_items AS i ON i.order_id = o.id\nWHERE o.id = 1\nORDER BY p.id, i.id;",
    "two_children_totals": "SELECT COUNT(*) AS joined_rows,\n       SUM(o.total_cents) AS wrong_order_cents,\n       SUM(p.amount_cents) AS wrong_paid_cents\nFROM orders AS o\nLEFT JOIN payments AS p\n  ON p.order_id = o.id AND p.status = 'settled'\nLEFT JOIN order_items AS i ON i.order_id = o.id\nWHERE o.id = 1;",
    "two_children_preaggregated": "WITH paid AS (\n  SELECT order_id, SUM(amount_cents) AS paid_cents\n  FROM payments WHERE status = 'settled' GROUP BY order_id\n), items AS (\n  SELECT order_id, COUNT(*) AS item_count\n  FROM order_items GROUP BY order_id\n)\nSELECT o.id AS order_id, o.total_cents,\n       COALESCE(paid.paid_cents, 0) AS paid_cents,\n       COALESCE(items.item_count, 0) AS item_count\nFROM orders AS o\nLEFT JOIN paid ON paid.order_id = o.id\nLEFT JOIN items ON items.order_id = o.id\nWHERE o.id = 1;"
  },
  "results": {
    "baseline": {
      "columns": [
        "order_count",
        "order_cents"
      ],
      "rows": [
        [
          4,
          30000
        ]
      ]
    },
    "joined_rows": {
      "columns": [
        "order_id",
        "total_cents",
        "payment_id",
        "amount_cents"
      ],
      "rows": [
        [
          1,
          10000,
          11,
          6000
        ],
        [
          1,
          10000,
          12,
          4000
        ],
        [
          2,
          10000,
          null,
          null
        ],
        [
          3,
          6000,
          31,
          6000
        ],
        [
          4,
          4000,
          null,
          null
        ]
      ]
    },
    "joined_totals": {
      "columns": [
        "joined_rows",
        "payment_count",
        "order_count",
        "wrong_order_cents",
        "distinct_amount_cents"
      ],
      "rows": [
        [
          5,
          3,
          4,
          40000,
          20000
        ]
      ]
    },
    "per_order_counts": {
      "columns": [
        "order_id",
        "joined_rows",
        "payment_count"
      ],
      "rows": [
        [
          1,
          2,
          2
        ],
        [
          2,
          1,
          0
        ],
        [
          3,
          1,
          1
        ],
        [
          4,
          1,
          0
        ]
      ]
    },
    "grouped_order_totals": {
      "columns": [
        "order_id",
        "wrong_order_cents"
      ],
      "rows": [
        [
          1,
          20000
        ],
        [
          2,
          10000
        ],
        [
          3,
          6000
        ],
        [
          4,
          4000
        ]
      ]
    },
    "preaggregated_rows": {
      "columns": [
        "order_id",
        "total_cents",
        "payment_count",
        "paid_cents"
      ],
      "rows": [
        [
          1,
          10000,
          2,
          10000
        ],
        [
          2,
          10000,
          0,
          0
        ],
        [
          3,
          6000,
          1,
          6000
        ],
        [
          4,
          4000,
          0,
          0
        ]
      ]
    },
    "preaggregated_totals": {
      "columns": [
        "order_count",
        "order_cents",
        "paid_cents"
      ],
      "rows": [
        [
          4,
          30000,
          16000
        ]
      ]
    },
    "exists_orders": {
      "columns": [
        "order_id",
        "total_cents"
      ],
      "rows": [
        [
          1,
          10000
        ],
        [
          3,
          6000
        ]
      ]
    },
    "where_filter": {
      "columns": [
        "order_id",
        "payment_id"
      ],
      "rows": [
        [
          1,
          11
        ],
        [
          1,
          12
        ],
        [
          3,
          31
        ]
      ]
    },
    "where_or_null": {
      "columns": [
        "order_id",
        "payment_id"
      ],
      "rows": [
        [
          1,
          11
        ],
        [
          1,
          12
        ],
        [
          3,
          31
        ],
        [
          4,
          null
        ]
      ]
    },
    "two_children_rows": {
      "columns": [
        "order_id",
        "payment_id",
        "item_id"
      ],
      "rows": [
        [
          1,
          11,
          101
        ],
        [
          1,
          11,
          102
        ],
        [
          1,
          11,
          103
        ],
        [
          1,
          12,
          101
        ],
        [
          1,
          12,
          102
        ],
        [
          1,
          12,
          103
        ]
      ]
    },
    "two_children_totals": {
      "columns": [
        "joined_rows",
        "wrong_order_cents",
        "wrong_paid_cents"
      ],
      "rows": [
        [
          6,
          60000,
          30000
        ]
      ]
    },
    "two_children_preaggregated": {
      "columns": [
        "order_id",
        "total_cents",
        "paid_cents",
        "item_count"
      ],
      "rows": [
        [
          1,
          10000,
          10000,
          3
        ]
      ]
    }
  },
  "boundaries": {
    "at_most_one_settled_payment": {
      "baseline": {
        "columns": [
          "order_count",
          "order_cents"
        ],
        "rows": [
          [
            4,
            30000
          ]
        ]
      },
      "joined_totals": {
        "columns": [
          "joined_rows",
          "payment_count",
          "order_count",
          "wrong_order_cents",
          "distinct_amount_cents"
        ],
        "rows": [
          [
            4,
            2,
            4,
            30000,
            20000
          ]
        ]
      },
      "preaggregated_totals": {
        "columns": [
          "order_count",
          "order_cents",
          "paid_cents"
        ],
        "rows": [
          [
            4,
            30000,
            12000
          ]
        ]
      }
    },
    "no_payments": {
      "baseline": {
        "columns": [
          "order_count",
          "order_cents"
        ],
        "rows": [
          [
            4,
            30000
          ]
        ]
      },
      "joined_totals": {
        "columns": [
          "joined_rows",
          "payment_count",
          "order_count",
          "wrong_order_cents",
          "distinct_amount_cents"
        ],
        "rows": [
          [
            4,
            0,
            4,
            30000,
            20000
          ]
        ]
      },
      "preaggregated_totals": {
        "columns": [
          "order_count",
          "order_cents",
          "paid_cents"
        ],
        "rows": [
          [
            4,
            30000,
            0
          ]
        ]
      }
    },
    "no_orders": {
      "baseline": {
        "columns": [
          "order_count",
          "order_cents"
        ],
        "rows": [
          [
            0,
            null
          ]
        ]
      },
      "joined_totals": {
        "columns": [
          "joined_rows",
          "payment_count",
          "order_count",
          "wrong_order_cents",
          "distinct_amount_cents"
        ],
        "rows": [
          [
            0,
            0,
            0,
            null,
            null
          ]
        ]
      },
      "preaggregated_totals": {
        "columns": [
          "order_count",
          "order_cents",
          "paid_cents"
        ],
        "rows": [
          [
            0,
            0,
            0
          ]
        ]
      }
    }
  },
  "checks": "passed"
}
