plan_optimize

The plan rewritten as plan_run runs it: the same bytes and errors, filters moved down, constants folded; the canonical plan and the rules applied.

QueryDeterministic

Flags

Flag Value
Kind query: reads values
Rows one result, not a table
Deterministic yes
Order matters no
Decomposable no
Makes no value

Parameters

Parameter Type Required Notes
plan object yes A plan in the IR hint.plan/1.
inputs map of reference | object no Each table a read names: its reference, or its schema and content hash.
response_format "concise" | "detailed" no The byte budget: 64 KiB concise, 512 KiB detailed.

Example

Over the example tables orders; ${input:name} is an input's reference and ${verb} the value an earlier call made.

JSON
plan_optimize {
  "plan": {
    "version": "hint.plan/1",
    "nodes": [
      {
        "id": "r",
        "op": "read",
        "params": {
          "input": "t"
        }
      },
      {
        "id": "s",
        "op": "sort",
        "inputs": [
          "r"
        ],
        "params": {
          "keys": [
            {
              "expr": {
                "col": 0
              },
              "descending": false,
              "nulls_first": false
            }
          ]
        }
      },
      {
        "id": "f",
        "op": "filter",
        "inputs": [
          "s"
        ],
        "params": {
          "predicate": {
            "fn": "eq",
            "args": [
              {
                "col": 7
              },
              {
                "lit": "paid",
                "type": {
                  "kind": "utf8"
                }
              }
            ]
          }
        }
      }
    ],
    "outputs": {
      "paid": "f"
    }
  },
  "inputs": {
    "t": "${input:orders}"
  }
}

Result

1 rewrite

JSON
{
  "plan": {
    "version": "hint.plan/1",
    "nodes": [
      {
        "id": "n0",
        "op": "read",
        "inputs": [],
        "params": {
          "input": "t"
        }
      },
      {
        "id": "n1",
        "op": "filter",
        "inputs": [
          "n0"
        ],
        "params": {
          "predicate": {
            "fn": "eq",
            "args": [
              {
                "col": 7
              },
              {
                "lit": "paid",
                "type": {
                  "kind": "utf8"
                }
              }
            ]
          }
        }
      },
      {
        "id": "n2",
        "op": "sort",
        "inputs": [
          "n1"
        ],
        "params": {
          "keys": [
            {
              "expr": {
                "col": 0
              },
              "descending": false,
              "nulls_first": false
            }
          ]
        }
      }
    ],
    "outputs": {
      "paid": "n2"
    }
  },
  "rules": [
    "filter_through_sort"
  ],
  "planHash": "sha256:01b90e0434acbfd01c5c0301f97d7af0a4d64d610d84574259b845e729ef4633",
  "rewrittenHash": "sha256:02ac252c2e0e77997f0803bdd2c6e50b2428ed2f09c4405009bb712a4b1802d1"
}

Diagnostics

A refusal comes back as ok: false with coded diagnostics; every code, with its fix, is on the diagnostics page. A parameter that does not match the schema above is ARG_INVALID, with the parameter's path.