exec
CREATE TABLE t.orders (oid INT PRIMARY KEY, cid INT, value DECIMAL, date DATE)
----

# In the string version, the constants are not anonymized.
plan-string
SELECT oid FROM t.orders WHERE oid = 123
----
----
planning time: 0µs
execution time: 0µs
distribution: local
vectorized: false
plan type: custom
maximum memory usage: 0 B
network usage: 0 B (0 messages)
isolation level: serializable
priority: normal
quality of service: regular

• scan
  columns: (oid int)
  estimated row count: 1 (missing stats)
  table: orders@orders_pkey
  spans: /123/0
----
----

plan-tree
SELECT oid FROM t.orders WHERE oid = 123
----
name: scan
attrs:
- key: missing stats
  value: ""
- key: table
  value: orders@orders_pkey
- key: spans
  value: 1 span
children: []

plan-string
SELECT cid, date, value FROM t.orders
----
----
planning time: 0µs
execution time: 0µs
distribution: local
vectorized: false
plan type: custom
maximum memory usage: 0 B
network usage: 0 B (0 messages)
isolation level: serializable
priority: normal
quality of service: regular

• scan
  columns: (cid int, date date, value decimal)
  estimated row count: 1,000 (missing stats)
  table: orders@orders_pkey
  spans: FULL SCAN
----
----

plan-tree
SELECT cid, date, value FROM t.orders
----
name: scan
attrs:
- key: missing stats
  value: ""
- key: table
  value: orders@orders_pkey
- key: spans
  value: FULL SCAN
children: []

plan-string
SELECT cid, sum(value) FROM t.orders WHERE date > '2015-01-01' GROUP BY cid ORDER BY 1 - sum(value)
----
----
planning time: 0µs
execution time: 0µs
distribution: local
vectorized: false
plan type: custom
maximum memory usage: 0 B
network usage: 0 B (0 messages)
isolation level: serializable
priority: normal
quality of service: regular

• project
│ columns: (cid int, sum decimal)
│
└── • sort
    │ columns: (column10 decimal, cid int, sum decimal)
    │ estimated row count: 98 (missing stats)
    │ order: +column10
    │
    └── • render
        │ columns: (column10 decimal, cid int, sum decimal)
        │ render column10: ((1)[decimal] - (sum)[decimal])[decimal]
        │ render cid: (cid)[int]
        │ render sum: (sum)[decimal]
        │
        └── • group (hash)
            │ columns: (cid int, sum decimal)
            │ estimated row count: 98 (missing stats)
            │ aggregate 0: sum(value)
            │ group by: cid
            │
            └── • project
                │ columns: (cid int, value decimal)
                │
                └── • filter
                    │ columns: (cid int, value decimal, date date)
                    │ estimated row count: 333 (missing stats)
                    │ filter: ((date)[date] > ('2015-01-01')[date])[bool]
                    │
                    └── • scan
                          columns: (cid int, value decimal, date date)
                          estimated row count: 1,000 (missing stats)
                          table: orders@orders_pkey
                          spans: FULL SCAN
----
----

plan-tree
SELECT cid, sum(value) FROM t.orders WHERE date > '2015-01-01' GROUP BY cid ORDER BY 1 - sum(value)
----
name: sort
attrs:
- key: order
  value: +column10
children:
- name: render
  attrs: []
  children:
  - name: group (hash)
    attrs:
    - key: group by
      value: cid
    children:
    - name: filter
      attrs:
      - key: filter
        value: date > _
      children:
      - name: scan
        attrs:
        - key: missing stats
          value: ""
        - key: table
          value: orders@orders_pkey
        - key: spans
          value: FULL SCAN
        children: []

plan-string
SELECT value FROM (SELECT cid, date, value FROM t.orders)
----
----
planning time: 0µs
execution time: 0µs
distribution: local
vectorized: false
plan type: custom
maximum memory usage: 0 B
network usage: 0 B (0 messages)
isolation level: serializable
priority: normal
quality of service: regular

• scan
  columns: (value decimal)
  estimated row count: 1,000 (missing stats)
  table: orders@orders_pkey
  spans: FULL SCAN
----
----

plan-tree
SELECT value FROM (SELECT cid, date, value FROM t.orders)
----
name: scan
attrs:
- key: missing stats
  value: ""
- key: table
  value: orders@orders_pkey
- key: spans
  value: FULL SCAN
children: []

plan-string
SELECT cid, date, value FROM t.orders WHERE date IN (SELECT date FROM t.orders)
----
----
planning time: 0µs
execution time: 0µs
distribution: local
vectorized: false
plan type: custom
maximum memory usage: 0 B
network usage: 0 B (0 messages)
isolation level: serializable
priority: normal
quality of service: regular

• project
│ columns: (cid int, date date, value decimal)
│
└── • hash join (inner)
    │ columns: (cid int, value decimal, date date, date date)
    │ estimated row count: 980 (missing stats)
    │ equality: (date) = (date)
    │ right cols are key
    │
    ├── • scan
    │     columns: (cid int, value decimal, date date)
    │     estimated row count: 1,000 (missing stats)
    │     table: orders@orders_pkey
    │     spans: FULL SCAN
    │
    └── • distinct
        │ columns: (date date)
        │ estimated row count: 100 (missing stats)
        │ distinct on: date
        │
        └── • scan
              columns: (date date)
              estimated row count: 1,000 (missing stats)
              table: orders@orders_pkey
              spans: FULL SCAN
----
----

plan-tree
SELECT cid, date, value FROM t.orders WHERE date IN (SELECT date FROM t.orders)
----
name: hash join
attrs:
- key: equality
  value: (date) = (date)
- key: right cols are key
  value: ""
children:
- name: scan
  attrs:
  - key: missing stats
    value: ""
  - key: table
    value: orders@orders_pkey
  - key: spans
    value: FULL SCAN
  children: []
- name: distinct
  attrs:
  - key: distinct on
    value: date
  children:
  - name: scan
    attrs:
    - key: missing stats
      value: ""
    - key: table
      value: orders@orders_pkey
    - key: spans
      value: FULL SCAN
    children: []

exec
CREATE TABLE t.movies (
  id SERIAL PRIMARY KEY,
  title TEXT,
  released INT
)
----

exec
CREATE TABLE t.actors (
  id SERIAL PRIMARY KEY,
  name TEXT
)
----

# Subquery.
plan-string
SELECT id AS movie_id, title, (SELECT name FROM t.actors WHERE name = 'Foo') FROM t.movies
----
----
planning time: 0µs
execution time: 0µs
distribution: local
vectorized: false
plan type: custom
maximum memory usage: 0 B
network usage: 0 B (0 messages)
isolation level: serializable
priority: normal
quality of service: regular

• root
│ columns: (movie_id int, title string, name string)
│
├── • render
│   │ columns: (movie_id int, title string, name string)
│   │ render name: (@S1)[string]
│   │ render id: (id)[int]
│   │ render title: (title)[string]
│   │
│   └── • scan
│         columns: (id int, title string)
│         estimated row count: 1,000 (missing stats)
│         table: movies@movies_pkey
│         spans: FULL SCAN
│
└── • subquery
    │ id: @S1
    │ original sql: (SELECT name FROM t.actors WHERE name = 'Foo')
    │ exec mode: one row
    │
    └── • max1row
        │ columns: (name string)
        │ estimated row count: 1
        │
        └── • filter
            │ columns: (name string)
            │ estimated row count: 10 (missing stats)
            │ filter: ((name)[string] = ('Foo')[string])[bool]
            │
            └── • scan
                  columns: (name string)
                  estimated row count: 1,000 (missing stats)
                  table: actors@actors_pkey
                  spans: FULL SCAN
----
----

plan-tree
SELECT id AS movie_id, title, (SELECT name FROM t.actors WHERE name = 'Foo') FROM t.movies
----
name: root
attrs: []
children:
- name: render
  attrs: []
  children:
  - name: scan
    attrs:
    - key: missing stats
      value: ""
    - key: table
      value: movies@movies_pkey
    - key: spans
      value: FULL SCAN
    children: []
- name: subquery
  attrs:
  - key: id
    value: '@S1'
  - key: original sql
    value: (SELECT name FROM t.actors WHERE name = '_')
  - key: exec mode
    value: one row
  children:
  - name: max1row
    attrs:
    - key: estimated row count
      value: "1"
    children:
    - name: filter
      attrs:
      - key: filter
        value: name = _
      children:
      - name: scan
        attrs:
        - key: missing stats
          value: ""
        - key: table
          value: actors@actors_pkey
        - key: spans
          value: FULL SCAN
        children: []
