exec-ddl
CREATE TABLE a (x INT PRIMARY KEY, y INT, s STRING)
----

exec-ddl
CREATE TABLE b (x INT, z INT NOT NULL, s STRING)
----

exec-ddl
CREATE TABLE c (x INT, z INT NOT NULL, s STRING)
----

exec-ddl
ALTER TABLE a INJECT STATISTICS '[
  {
    "columns": ["x"],
    "created_at": "2018-01-01 1:00:00.00000+00:00",
    "row_count": 5000,
    "distinct_count": 5000,
    "avg_size": 2
  },
  {
    "columns": ["y"],
    "created_at": "2018-01-01 1:30:00.00000+00:00",
    "row_count": 5000,
    "distinct_count": 400,
    "avg_size": 3
  },
  {
    "columns": ["s"],
    "created_at": "2018-01-01 1:30:00.00000+00:00",
    "row_count": 5000,
    "distinct_count": 10,
    "avg_size": 30
  },
  {
    "columns": ["y","s"],
    "created_at": "2018-01-01 1:30:00.00000+00:00",
    "row_count": 5000,
    "distinct_count": 1000
  }
]'
----

exec-ddl
ALTER TABLE b INJECT STATISTICS '[
  {
    "columns": ["x"],
    "created_at": "2018-01-01 1:00:00.00000+00:00",
    "row_count": 10000,
    "distinct_count": 5000,
    "avg_size": 4
  },
  {
    "columns": ["z"],
    "created_at": "2018-01-01 1:30:00.00000+00:00",
    "row_count": 10000,
    "distinct_count": 100,
    "avg_size": 2
  },
  {
    "columns": ["s"],
    "created_at": "2018-01-01 1:30:00.00000+00:00",
    "row_count": 10000,
    "distinct_count": 10,
    "avg_size": 20
  },
  {
    "columns": ["z","s"],
    "created_at": "2018-01-01 1:40:00.00000+00:00",
    "row_count": 10000,
    "distinct_count": 200
  },
  {
    "columns": ["rowid"],
    "created_at": "2018-01-01 1:30:00.00000+00:00",
    "row_count": 10000,
    "distinct_count": 10000
  }
]'
----

exec-ddl
ALTER TABLE c INJECT STATISTICS '[
  {
    "columns": ["x"],
    "created_at": "2018-01-01 1:00:00.00000+00:00",
    "row_count": 10000,
    "distinct_count": 5000,
    "avg_size": 3
  },
  {
    "columns": ["z"],
    "created_at": "2018-01-01 1:30:00.00000+00:00",
    "row_count": 10000,
    "distinct_count": 100,
    "avg_size": 1
  },
  {
    "columns": ["s"],
    "created_at": "2018-01-01 1:30:00.00000+00:00",
    "row_count": 10000,
    "distinct_count": 10,
    "avg_size": 30
  },
  {
    "columns": ["z","s"],
    "created_at": "2018-01-01 1:30:00.00000+00:00",
    "row_count": 10000,
    "distinct_count": 200
  }
]'
----

build
SELECT *, x FROM a UNION SELECT *, rowid FROM b
----
union
 ├── columns: x:12(int) y:13(int) s:14(string) x:15(int!null)
 ├── left columns: a.x:1(int) a.y:2(int) a.s:3(string) a.x:1(int)
 ├── right columns: b.x:6(int) z:7(int) b.s:8(string) rowid:9(int)
 ├── stats: [rows=15000, distinct(12-15)=15000, null(12-15)=0]
 ├── key: (12-15)
 ├── project
 │    ├── columns: a.x:1(int!null) a.y:2(int) a.s:3(string)
 │    ├── stats: [rows=5000, distinct(1-3)=5000, null(1-3)=0]
 │    ├── key: (1)
 │    ├── fd: (1)-->(2,3)
 │    └── scan a
 │         ├── columns: a.x:1(int!null) a.y:2(int) a.s:3(string) a.crdb_internal_mvcc_timestamp:4(decimal) a.tableoid:5(oid)
 │         ├── stats: [rows=5000, distinct(1-3)=5000, null(1-3)=0]
 │         ├── key: (1)
 │         └── fd: (1)-->(2-5)
 └── project
      ├── columns: b.x:6(int) z:7(int!null) b.s:8(string) rowid:9(int!null)
      ├── stats: [rows=10000, distinct(6-9)=10000, null(6-9)=0]
      ├── key: (9)
      ├── fd: (9)-->(6-8)
      └── scan b
           ├── columns: b.x:6(int) z:7(int!null) b.s:8(string) rowid:9(int!null) b.crdb_internal_mvcc_timestamp:10(decimal) b.tableoid:11(oid)
           ├── stats: [rows=10000, distinct(6-9)=10000, null(6-9)=0]
           ├── key: (9)
           └── fd: (9)-->(6-8,10,11)

build
SELECT *, x FROM a UNION ALL SELECT *, rowid FROM b
----
union-all
 ├── columns: x:12(int) y:13(int) s:14(string) x:15(int!null)
 ├── left columns: a.x:1(int) a.y:2(int) a.s:3(string) a.x:1(int)
 ├── right columns: b.x:6(int) z:7(int) b.s:8(string) rowid:9(int)
 ├── stats: [rows=15000]
 ├── project
 │    ├── columns: a.x:1(int!null) a.y:2(int) a.s:3(string)
 │    ├── stats: [rows=5000]
 │    ├── key: (1)
 │    ├── fd: (1)-->(2,3)
 │    └── scan a
 │         ├── columns: a.x:1(int!null) a.y:2(int) a.s:3(string) a.crdb_internal_mvcc_timestamp:4(decimal) a.tableoid:5(oid)
 │         ├── stats: [rows=5000]
 │         ├── key: (1)
 │         └── fd: (1)-->(2-5)
 └── project
      ├── columns: b.x:6(int) z:7(int!null) b.s:8(string) rowid:9(int!null)
      ├── stats: [rows=10000]
      ├── key: (9)
      ├── fd: (9)-->(6-8)
      └── scan b
           ├── columns: b.x:6(int) z:7(int!null) b.s:8(string) rowid:9(int!null) b.crdb_internal_mvcc_timestamp:10(decimal) b.tableoid:11(oid)
           ├── stats: [rows=10000]
           ├── key: (9)
           └── fd: (9)-->(6-8,10,11)

build
SELECT y, s FROM a UNION SELECT z, s FROM c
----
union
 ├── columns: y:12(int) s:13(string)
 ├── left columns: a.y:2(int) a.s:3(string)
 ├── right columns: z:7(int) c.s:8(string)
 ├── stats: [rows=1200, distinct(12,13)=1200, null(12,13)=0]
 ├── key: (12,13)
 ├── project
 │    ├── columns: a.y:2(int) a.s:3(string)
 │    ├── stats: [rows=5000, distinct(2,3)=1000, null(2,3)=0]
 │    └── scan a
 │         ├── columns: a.x:1(int!null) a.y:2(int) a.s:3(string) a.crdb_internal_mvcc_timestamp:4(decimal) a.tableoid:5(oid)
 │         ├── stats: [rows=5000, distinct(2,3)=1000, null(2,3)=0]
 │         ├── key: (1)
 │         └── fd: (1)-->(2-5)
 └── project
      ├── columns: z:7(int!null) c.s:8(string)
      ├── stats: [rows=10000, distinct(7,8)=200, null(7,8)=0]
      └── scan c
           ├── columns: c.x:6(int) z:7(int!null) c.s:8(string) rowid:9(int!null) c.crdb_internal_mvcc_timestamp:10(decimal) c.tableoid:11(oid)
           ├── stats: [rows=10000, distinct(7,8)=200, null(7,8)=0]
           ├── key: (9)
           └── fd: (9)-->(6-8,10,11)

build
SELECT y, s FROM a UNION SELECT z, s FROM b
----
union
 ├── columns: y:12(int) s:13(string)
 ├── left columns: a.y:2(int) a.s:3(string)
 ├── right columns: z:7(int) b.s:8(string)
 ├── stats: [rows=1200, distinct(12,13)=1200, null(12,13)=0]
 ├── key: (12,13)
 ├── project
 │    ├── columns: a.y:2(int) a.s:3(string)
 │    ├── stats: [rows=5000, distinct(2,3)=1000, null(2,3)=0]
 │    └── scan a
 │         ├── columns: a.x:1(int!null) a.y:2(int) a.s:3(string) a.crdb_internal_mvcc_timestamp:4(decimal) a.tableoid:5(oid)
 │         ├── stats: [rows=5000, distinct(2,3)=1000, null(2,3)=0]
 │         ├── key: (1)
 │         └── fd: (1)-->(2-5)
 └── project
      ├── columns: z:7(int!null) b.s:8(string)
      ├── stats: [rows=10000, distinct(7,8)=200, null(7,8)=0]
      └── scan b
           ├── columns: b.x:6(int) z:7(int!null) b.s:8(string) rowid:9(int!null) b.crdb_internal_mvcc_timestamp:10(decimal) b.tableoid:11(oid)
           ├── stats: [rows=10000, distinct(7,8)=200, null(7,8)=0]
           ├── key: (9)
           └── fd: (9)-->(6-8,10,11)

build
SELECT y, s FROM a UNION ALL SELECT z, s FROM b
----
union-all
 ├── columns: y:12(int) s:13(string)
 ├── left columns: a.y:2(int) a.s:3(string)
 ├── right columns: z:7(int) b.s:8(string)
 ├── stats: [rows=15000]
 ├── project
 │    ├── columns: a.y:2(int) a.s:3(string)
 │    ├── stats: [rows=5000]
 │    └── scan a
 │         ├── columns: a.x:1(int!null) a.y:2(int) a.s:3(string) a.crdb_internal_mvcc_timestamp:4(decimal) a.tableoid:5(oid)
 │         ├── stats: [rows=5000]
 │         ├── key: (1)
 │         └── fd: (1)-->(2-5)
 └── project
      ├── columns: z:7(int!null) b.s:8(string)
      ├── stats: [rows=10000]
      └── scan b
           ├── columns: b.x:6(int) z:7(int!null) b.s:8(string) rowid:9(int!null) b.crdb_internal_mvcc_timestamp:10(decimal) b.tableoid:11(oid)
           ├── stats: [rows=10000]
           ├── key: (9)
           └── fd: (9)-->(6-8,10,11)

build
SELECT x, y, x FROM a INTERSECT SELECT z, x, rowid FROM (SELECT *, rowid FROM b WHERE b.x=1) b
----
intersect
 ├── columns: x:12(int!null) y:13(int) x:14(int!null)
 ├── left columns: a.x:1(int) a.y:2(int) a.x:1(int)
 ├── right columns: z:7(int) b.x:6(int) rowid:9(int)
 ├── stats: [rows=2.000001, distinct(12-14)=2, null(12-14)=0]
 ├── key: (14)
 ├── fd: ()-->(13), (14)-->(12,13), (12)==(14), (14)==(12)
 ├── project
 │    ├── columns: a.x:1(int!null) a.y:2(int)
 │    ├── stats: [rows=5000, distinct(1,2)=5000, null(1,2)=0]
 │    ├── key: (1)
 │    ├── fd: (1)-->(2)
 │    └── scan a
 │         ├── columns: a.x:1(int!null) a.y:2(int) a.s:3(string) a.crdb_internal_mvcc_timestamp:4(decimal) a.tableoid:5(oid)
 │         ├── stats: [rows=5000, distinct(1,2)=5000, null(1,2)=0]
 │         ├── key: (1)
 │         └── fd: (1)-->(2-5)
 └── project
      ├── columns: b.x:6(int!null) z:7(int!null) rowid:9(int!null)
      ├── stats: [rows=2.000001, distinct(6,7,9)=2, null(6,7,9)=0]
      ├── key: (9)
      ├── fd: ()-->(6), (9)-->(7)
      └── project
           ├── columns: b.x:6(int!null) z:7(int!null) b.s:8(string) rowid:9(int!null)
           ├── stats: [rows=2.000001, distinct(6,7,9)=2, null(6,7,9)=0]
           ├── key: (9)
           ├── fd: ()-->(6), (9)-->(7,8)
           └── select
                ├── columns: b.x:6(int!null) z:7(int!null) b.s:8(string) rowid:9(int!null) b.crdb_internal_mvcc_timestamp:10(decimal) b.tableoid:11(oid)
                ├── stats: [rows=2.000001, distinct(6)=1, null(6)=0, distinct(6,7,9)=2, null(6,7,9)=0]
                ├── key: (9)
                ├── fd: ()-->(6), (9)-->(7,8,10,11)
                ├── scan b
                │    ├── columns: b.x:6(int) z:7(int!null) b.s:8(string) rowid:9(int!null) b.crdb_internal_mvcc_timestamp:10(decimal) b.tableoid:11(oid)
                │    ├── stats: [rows=10000, distinct(6)=5000, null(6)=0, distinct(7)=100, null(7)=0, distinct(9)=10000, null(9)=0, distinct(6,7,9)=10000, null(6,7,9)=0]
                │    ├── key: (9)
                │    └── fd: (9)-->(6-8,10,11)
                └── filters
                     └── b.x:6 = 1 [type=bool, outer=(6), constraints=(/6: [/1 - /1]; tight), fd=()-->(6)]

build
SELECT x, y, x FROM a INTERSECT ALL SELECT z, x, rowid FROM (SELECT *, rowid FROM b WHERE b.x=1) b
----
intersect-all
 ├── columns: x:12(int!null) y:13(int) x:14(int!null)
 ├── left columns: a.x:1(int) a.y:2(int) a.x:1(int)
 ├── right columns: z:7(int) b.x:6(int) rowid:9(int)
 ├── stats: [rows=2.000001]
 ├── key: (14)
 ├── fd: ()-->(13), (12)==(14), (14)==(12)
 ├── project
 │    ├── columns: a.x:1(int!null) a.y:2(int)
 │    ├── stats: [rows=5000]
 │    ├── key: (1)
 │    ├── fd: (1)-->(2)
 │    └── scan a
 │         ├── columns: a.x:1(int!null) a.y:2(int) a.s:3(string) a.crdb_internal_mvcc_timestamp:4(decimal) a.tableoid:5(oid)
 │         ├── stats: [rows=5000]
 │         ├── key: (1)
 │         └── fd: (1)-->(2-5)
 └── project
      ├── columns: b.x:6(int!null) z:7(int!null) rowid:9(int!null)
      ├── stats: [rows=2.000001]
      ├── key: (9)
      ├── fd: ()-->(6), (9)-->(7)
      └── project
           ├── columns: b.x:6(int!null) z:7(int!null) b.s:8(string) rowid:9(int!null)
           ├── stats: [rows=2.000001]
           ├── key: (9)
           ├── fd: ()-->(6), (9)-->(7,8)
           └── select
                ├── columns: b.x:6(int!null) z:7(int!null) b.s:8(string) rowid:9(int!null) b.crdb_internal_mvcc_timestamp:10(decimal) b.tableoid:11(oid)
                ├── stats: [rows=2.000001, distinct(6)=1, null(6)=0]
                ├── key: (9)
                ├── fd: ()-->(6), (9)-->(7,8,10,11)
                ├── scan b
                │    ├── columns: b.x:6(int) z:7(int!null) b.s:8(string) rowid:9(int!null) b.crdb_internal_mvcc_timestamp:10(decimal) b.tableoid:11(oid)
                │    ├── stats: [rows=10000, distinct(6)=5000, null(6)=0, distinct(7)=100, null(7)=0, distinct(9)=10000, null(9)=0]
                │    ├── key: (9)
                │    └── fd: (9)-->(6-8,10,11)
                └── filters
                     └── b.x:6 = 1 [type=bool, outer=(6), constraints=(/6: [/1 - /1]; tight), fd=()-->(6)]

build
SELECT y, s FROM a INTERSECT SELECT z, s FROM c
----
intersect
 ├── columns: y:2(int) s:3(string)
 ├── left columns: y:2(int) a.s:3(string)
 ├── right columns: z:7(int) c.s:8(string)
 ├── stats: [rows=200, distinct(2,3)=200, null(2,3)=0]
 ├── key: (2,3)
 ├── project
 │    ├── columns: y:2(int) a.s:3(string)
 │    ├── stats: [rows=5000, distinct(2,3)=1000, null(2,3)=0]
 │    └── scan a
 │         ├── columns: a.x:1(int!null) y:2(int) a.s:3(string) a.crdb_internal_mvcc_timestamp:4(decimal) a.tableoid:5(oid)
 │         ├── stats: [rows=5000, distinct(2,3)=1000, null(2,3)=0]
 │         ├── key: (1)
 │         └── fd: (1)-->(2-5)
 └── project
      ├── columns: z:7(int!null) c.s:8(string)
      ├── stats: [rows=10000, distinct(7,8)=200, null(7,8)=0]
      └── scan c
           ├── columns: c.x:6(int) z:7(int!null) c.s:8(string) rowid:9(int!null) c.crdb_internal_mvcc_timestamp:10(decimal) c.tableoid:11(oid)
           ├── stats: [rows=10000, distinct(7,8)=200, null(7,8)=0]
           ├── key: (9)
           └── fd: (9)-->(6-8,10,11)

build
SELECT y, s FROM a INTERSECT SELECT z, s FROM b
----
intersect
 ├── columns: y:2(int) s:3(string)
 ├── left columns: y:2(int) a.s:3(string)
 ├── right columns: z:7(int) b.s:8(string)
 ├── stats: [rows=200, distinct(2,3)=200, null(2,3)=0]
 ├── key: (2,3)
 ├── project
 │    ├── columns: y:2(int) a.s:3(string)
 │    ├── stats: [rows=5000, distinct(2,3)=1000, null(2,3)=0]
 │    └── scan a
 │         ├── columns: a.x:1(int!null) y:2(int) a.s:3(string) a.crdb_internal_mvcc_timestamp:4(decimal) a.tableoid:5(oid)
 │         ├── stats: [rows=5000, distinct(2,3)=1000, null(2,3)=0]
 │         ├── key: (1)
 │         └── fd: (1)-->(2-5)
 └── project
      ├── columns: z:7(int!null) b.s:8(string)
      ├── stats: [rows=10000, distinct(7,8)=200, null(7,8)=0]
      └── scan b
           ├── columns: b.x:6(int) z:7(int!null) b.s:8(string) rowid:9(int!null) b.crdb_internal_mvcc_timestamp:10(decimal) b.tableoid:11(oid)
           ├── stats: [rows=10000, distinct(7,8)=200, null(7,8)=0]
           ├── key: (9)
           └── fd: (9)-->(6-8,10,11)

build
SELECT y, s FROM a INTERSECT ALL SELECT z, s FROM b
----
intersect-all
 ├── columns: y:2(int) s:3(string)
 ├── left columns: y:2(int) a.s:3(string)
 ├── right columns: z:7(int) b.s:8(string)
 ├── stats: [rows=5000]
 ├── project
 │    ├── columns: y:2(int) a.s:3(string)
 │    ├── stats: [rows=5000]
 │    └── scan a
 │         ├── columns: a.x:1(int!null) y:2(int) a.s:3(string) a.crdb_internal_mvcc_timestamp:4(decimal) a.tableoid:5(oid)
 │         ├── stats: [rows=5000]
 │         ├── key: (1)
 │         └── fd: (1)-->(2-5)
 └── project
      ├── columns: z:7(int!null) b.s:8(string)
      ├── stats: [rows=10000]
      └── scan b
           ├── columns: b.x:6(int) z:7(int!null) b.s:8(string) rowid:9(int!null) b.crdb_internal_mvcc_timestamp:10(decimal) b.tableoid:11(oid)
           ├── stats: [rows=10000]
           ├── key: (9)
           └── fd: (9)-->(6-8,10,11)

build
SELECT x, x, y FROM a EXCEPT SELECT x, z, z FROM (SELECT * FROM b WHERE b.x=1) b
----
except
 ├── columns: x:12(int!null) x:13(int!null) y:14(int)
 ├── left columns: a.x:1(int) a.x:1(int) a.y:2(int)
 ├── right columns: b.x:6(int) z:7(int) z:7(int)
 ├── stats: [rows=5000, distinct(12-14)=5000, null(12-14)=0]
 ├── key: (13)
 ├── fd: (13)-->(12,14), (12)==(13), (13)==(12)
 ├── project
 │    ├── columns: a.x:1(int!null) a.y:2(int)
 │    ├── stats: [rows=5000, distinct(1,2)=5000, null(1,2)=0]
 │    ├── key: (1)
 │    ├── fd: (1)-->(2)
 │    └── scan a
 │         ├── columns: a.x:1(int!null) a.y:2(int) a.s:3(string) a.crdb_internal_mvcc_timestamp:4(decimal) a.tableoid:5(oid)
 │         ├── stats: [rows=5000, distinct(1,2)=5000, null(1,2)=0]
 │         ├── key: (1)
 │         └── fd: (1)-->(2-5)
 └── project
      ├── columns: b.x:6(int!null) z:7(int!null)
      ├── stats: [rows=2.000001, distinct(6,7)=2, null(6,7)=0]
      ├── fd: ()-->(6)
      └── project
           ├── columns: b.x:6(int!null) z:7(int!null) b.s:8(string)
           ├── stats: [rows=2.000001, distinct(6,7)=2, null(6,7)=0]
           ├── fd: ()-->(6)
           └── select
                ├── columns: b.x:6(int!null) z:7(int!null) b.s:8(string) rowid:9(int!null) b.crdb_internal_mvcc_timestamp:10(decimal) b.tableoid:11(oid)
                ├── stats: [rows=2.000001, distinct(6)=1, null(6)=0, distinct(6,7)=2, null(6,7)=0]
                ├── key: (9)
                ├── fd: ()-->(6), (9)-->(7,8,10,11)
                ├── scan b
                │    ├── columns: b.x:6(int) z:7(int!null) b.s:8(string) rowid:9(int!null) b.crdb_internal_mvcc_timestamp:10(decimal) b.tableoid:11(oid)
                │    ├── stats: [rows=10000, distinct(6)=5000, null(6)=0, distinct(7)=100, null(7)=0, distinct(9)=10000, null(9)=0, distinct(6,7)=10000, null(6,7)=0]
                │    ├── key: (9)
                │    └── fd: (9)-->(6-8,10,11)
                └── filters
                     └── b.x:6 = 1 [type=bool, outer=(6), constraints=(/6: [/1 - /1]; tight), fd=()-->(6)]

build
SELECT x, x, y FROM a EXCEPT ALL SELECT x, z, z FROM (SELECT * FROM b WHERE b.x=1) b
----
except-all
 ├── columns: x:12(int!null) x:13(int!null) y:14(int)
 ├── left columns: a.x:1(int) a.x:1(int) a.y:2(int)
 ├── right columns: b.x:6(int) z:7(int) z:7(int)
 ├── stats: [rows=5000]
 ├── key: (13)
 ├── fd: (12,13)-->(14), (12)==(13), (13)==(12)
 ├── project
 │    ├── columns: a.x:1(int!null) a.y:2(int)
 │    ├── stats: [rows=5000]
 │    ├── key: (1)
 │    ├── fd: (1)-->(2)
 │    └── scan a
 │         ├── columns: a.x:1(int!null) a.y:2(int) a.s:3(string) a.crdb_internal_mvcc_timestamp:4(decimal) a.tableoid:5(oid)
 │         ├── stats: [rows=5000]
 │         ├── key: (1)
 │         └── fd: (1)-->(2-5)
 └── project
      ├── columns: b.x:6(int!null) z:7(int!null)
      ├── stats: [rows=2.000001]
      ├── fd: ()-->(6)
      └── project
           ├── columns: b.x:6(int!null) z:7(int!null) b.s:8(string)
           ├── stats: [rows=2.000001]
           ├── fd: ()-->(6)
           └── select
                ├── columns: b.x:6(int!null) z:7(int!null) b.s:8(string) rowid:9(int!null) b.crdb_internal_mvcc_timestamp:10(decimal) b.tableoid:11(oid)
                ├── stats: [rows=2.000001, distinct(6)=1, null(6)=0]
                ├── key: (9)
                ├── fd: ()-->(6), (9)-->(7,8,10,11)
                ├── scan b
                │    ├── columns: b.x:6(int) z:7(int!null) b.s:8(string) rowid:9(int!null) b.crdb_internal_mvcc_timestamp:10(decimal) b.tableoid:11(oid)
                │    ├── stats: [rows=10000, distinct(6)=5000, null(6)=0, distinct(7)=100, null(7)=0, distinct(9)=10000, null(9)=0]
                │    ├── key: (9)
                │    └── fd: (9)-->(6-8,10,11)
                └── filters
                     └── b.x:6 = 1 [type=bool, outer=(6), constraints=(/6: [/1 - /1]; tight), fd=()-->(6)]

build
SELECT y, s FROM a EXCEPT SELECT z, s FROM c
----
except
 ├── columns: y:2(int) s:3(string)
 ├── left columns: y:2(int) a.s:3(string)
 ├── right columns: z:7(int) c.s:8(string)
 ├── stats: [rows=1000, distinct(2,3)=1000, null(2,3)=0]
 ├── key: (2,3)
 ├── project
 │    ├── columns: y:2(int) a.s:3(string)
 │    ├── stats: [rows=5000, distinct(2,3)=1000, null(2,3)=0]
 │    └── scan a
 │         ├── columns: a.x:1(int!null) y:2(int) a.s:3(string) a.crdb_internal_mvcc_timestamp:4(decimal) a.tableoid:5(oid)
 │         ├── stats: [rows=5000, distinct(2,3)=1000, null(2,3)=0]
 │         ├── key: (1)
 │         └── fd: (1)-->(2-5)
 └── project
      ├── columns: z:7(int!null) c.s:8(string)
      ├── stats: [rows=10000, distinct(7,8)=200, null(7,8)=0]
      └── scan c
           ├── columns: c.x:6(int) z:7(int!null) c.s:8(string) rowid:9(int!null) c.crdb_internal_mvcc_timestamp:10(decimal) c.tableoid:11(oid)
           ├── stats: [rows=10000, distinct(7,8)=200, null(7,8)=0]
           ├── key: (9)
           └── fd: (9)-->(6-8,10,11)

build
SELECT y, s FROM a EXCEPT SELECT z, s FROM b
----
except
 ├── columns: y:2(int) s:3(string)
 ├── left columns: y:2(int) a.s:3(string)
 ├── right columns: z:7(int) b.s:8(string)
 ├── stats: [rows=1000, distinct(2,3)=1000, null(2,3)=0]
 ├── key: (2,3)
 ├── project
 │    ├── columns: y:2(int) a.s:3(string)
 │    ├── stats: [rows=5000, distinct(2,3)=1000, null(2,3)=0]
 │    └── scan a
 │         ├── columns: a.x:1(int!null) y:2(int) a.s:3(string) a.crdb_internal_mvcc_timestamp:4(decimal) a.tableoid:5(oid)
 │         ├── stats: [rows=5000, distinct(2,3)=1000, null(2,3)=0]
 │         ├── key: (1)
 │         └── fd: (1)-->(2-5)
 └── project
      ├── columns: z:7(int!null) b.s:8(string)
      ├── stats: [rows=10000, distinct(7,8)=200, null(7,8)=0]
      └── scan b
           ├── columns: b.x:6(int) z:7(int!null) b.s:8(string) rowid:9(int!null) b.crdb_internal_mvcc_timestamp:10(decimal) b.tableoid:11(oid)
           ├── stats: [rows=10000, distinct(7,8)=200, null(7,8)=0]
           ├── key: (9)
           └── fd: (9)-->(6-8,10,11)

build
SELECT y, s FROM a EXCEPT ALL SELECT z, s FROM b
----
except-all
 ├── columns: y:2(int) s:3(string)
 ├── left columns: y:2(int) a.s:3(string)
 ├── right columns: z:7(int) b.s:8(string)
 ├── stats: [rows=5000]
 ├── project
 │    ├── columns: y:2(int) a.s:3(string)
 │    ├── stats: [rows=5000]
 │    └── scan a
 │         ├── columns: a.x:1(int!null) y:2(int) a.s:3(string) a.crdb_internal_mvcc_timestamp:4(decimal) a.tableoid:5(oid)
 │         ├── stats: [rows=5000]
 │         ├── key: (1)
 │         └── fd: (1)-->(2-5)
 └── project
      ├── columns: z:7(int!null) b.s:8(string)
      ├── stats: [rows=10000]
      └── scan b
           ├── columns: b.x:6(int) z:7(int!null) b.s:8(string) rowid:9(int!null) b.crdb_internal_mvcc_timestamp:10(decimal) b.tableoid:11(oid)
           ├── stats: [rows=10000]
           ├── key: (9)
           └── fd: (9)-->(6-8,10,11)

build
SELECT * FROM (SELECT y, s FROM a EXCEPT ALL SELECT z, s FROM b) WHERE y = 5
----
select
 ├── columns: y:2(int!null) s:3(string)
 ├── stats: [rows=12.5, distinct(2)=1, null(2)=0]
 ├── fd: ()-->(2)
 ├── except-all
 │    ├── columns: y:2(int) a.s:3(string)
 │    ├── left columns: y:2(int) a.s:3(string)
 │    ├── right columns: z:7(int) b.s:8(string)
 │    ├── stats: [rows=5000, distinct(2)=400, null(2)=0]
 │    ├── project
 │    │    ├── columns: y:2(int) a.s:3(string)
 │    │    ├── stats: [rows=5000, distinct(2)=400, null(2)=0]
 │    │    └── scan a
 │    │         ├── columns: a.x:1(int!null) y:2(int) a.s:3(string) a.crdb_internal_mvcc_timestamp:4(decimal) a.tableoid:5(oid)
 │    │         ├── stats: [rows=5000, distinct(2)=400, null(2)=0]
 │    │         ├── key: (1)
 │    │         └── fd: (1)-->(2-5)
 │    └── project
 │         ├── columns: z:7(int!null) b.s:8(string)
 │         ├── stats: [rows=10000, distinct(7)=100, null(7)=0]
 │         └── scan b
 │              ├── columns: b.x:6(int) z:7(int!null) b.s:8(string) rowid:9(int!null) b.crdb_internal_mvcc_timestamp:10(decimal) b.tableoid:11(oid)
 │              ├── stats: [rows=10000, distinct(7)=100, null(7)=0]
 │              ├── key: (9)
 │              └── fd: (9)-->(6-8,10,11)
 └── filters
      └── y:2 = 5 [type=bool, outer=(2), constraints=(/2: [/5 - /5]; tight), fd=()-->(2)]

# Bump up null counts.
exec-ddl
ALTER TABLE b INJECT STATISTICS '[
  {
    "columns": ["x"],
    "created_at": "2018-01-01 1:00:00.00000+00:00",
    "row_count": 10000,
    "distinct_count": 5000,
    "null_count": 2500,
    "avg_size": 4
  },
  {
    "columns": ["z"],
    "created_at": "2018-01-01 1:30:00.00000+00:00",
    "row_count": 10000,
    "distinct_count": 100,
    "avg_size": 2
  },
  {
    "columns": ["s"],
    "created_at": "2018-01-01 1:30:00.00000+00:00",
    "row_count": 10000,
    "distinct_count": 10,
    "null_count": 5000,
    "avg_size": 20
  },
  {
    "columns": ["rowid"],
    "created_at": "2018-01-01 1:30:00.00000+00:00",
    "row_count": 10000,
    "distinct_count": 10000
  }
]'
----

exec-ddl
ALTER TABLE c INJECT STATISTICS '[
  {
    "columns": ["x"],
    "created_at": "2018-01-01 1:00:00.00000+00:00",
    "row_count": 10000,
    "distinct_count": 5000,
    "null_count": 1000,
    "avg_size": 3
  },
  {
    "columns": ["z"],
    "created_at": "2018-01-01 1:30:00.00000+00:00",
    "row_count": 10000,
    "distinct_count": 100,
    "avg_size": 1
  },
  {
    "columns": ["s"],
    "created_at": "2018-01-01 1:30:00.00000+00:00",
    "row_count": 10000,
    "distinct_count": 10,
    "null_count": 7500,
    "avg_size": 30
  }
]'
----

build colstat=13 colstat=14 colstat=(13,14)
SELECT x,s FROM b UNION SELECT x,s FROM c
----
union
 ├── columns: x:13(int) s:14(string)
 ├── left columns: b.x:1(int) b.s:3(string)
 ├── right columns: c.x:7(int) c.s:9(string)
 ├── stats: [rows=20000, distinct(13)=10000, null(13)=1, distinct(14)=20, null(14)=1, distinct(13,14)=20000, null(13,14)=1]
 ├── key: (13,14)
 ├── project
 │    ├── columns: b.x:1(int) b.s:3(string)
 │    ├── stats: [rows=10000, distinct(1)=5000, null(1)=2500, distinct(3)=10, null(3)=5000, distinct(1,3)=10000, null(1,3)=1250]
 │    └── scan b
 │         ├── columns: b.x:1(int) b.z:2(int!null) b.s:3(string) b.rowid:4(int!null) b.crdb_internal_mvcc_timestamp:5(decimal) b.tableoid:6(oid)
 │         ├── stats: [rows=10000, distinct(1)=5000, null(1)=2500, distinct(3)=10, null(3)=5000, distinct(1,3)=10000, null(1,3)=1250]
 │         ├── key: (4)
 │         └── fd: (4)-->(1-3,5,6)
 └── project
      ├── columns: c.x:7(int) c.s:9(string)
      ├── stats: [rows=10000, distinct(7)=5000, null(7)=1000, distinct(9)=10, null(9)=7500, distinct(7,9)=10000, null(7,9)=750]
      └── scan c
           ├── columns: c.x:7(int) c.z:8(int!null) c.s:9(string) c.rowid:10(int!null) c.crdb_internal_mvcc_timestamp:11(decimal) c.tableoid:12(oid)
           ├── stats: [rows=10000, distinct(7)=5000, null(7)=1000, distinct(9)=10, null(9)=7500, distinct(7,9)=10000, null(7,9)=750]
           ├── key: (10)
           └── fd: (10)-->(7-9,11,12)

build colstat=1 colstat=3 colstat=(1,3)
SELECT x,s FROM b INTERSECT SELECT x,s FROM c
----
intersect
 ├── columns: x:1(int) s:3(string)
 ├── left columns: b.x:1(int) b.s:3(string)
 ├── right columns: c.x:7(int) c.s:9(string)
 ├── stats: [rows=10000, distinct(1)=5000, null(1)=1, distinct(3)=10, null(3)=1, distinct(1,3)=10000, null(1,3)=1]
 ├── key: (1,3)
 ├── project
 │    ├── columns: b.x:1(int) b.s:3(string)
 │    ├── stats: [rows=10000, distinct(1)=5000, null(1)=2500, distinct(3)=10, null(3)=5000, distinct(1,3)=10000, null(1,3)=1250]
 │    └── scan b
 │         ├── columns: b.x:1(int) b.z:2(int!null) b.s:3(string) b.rowid:4(int!null) b.crdb_internal_mvcc_timestamp:5(decimal) b.tableoid:6(oid)
 │         ├── stats: [rows=10000, distinct(1)=5000, null(1)=2500, distinct(3)=10, null(3)=5000, distinct(1,3)=10000, null(1,3)=1250]
 │         ├── key: (4)
 │         └── fd: (4)-->(1-3,5,6)
 └── project
      ├── columns: c.x:7(int) c.s:9(string)
      ├── stats: [rows=10000, distinct(7)=5000, null(7)=1000, distinct(9)=10, null(9)=7500, distinct(7,9)=10000, null(7,9)=750]
      └── scan c
           ├── columns: c.x:7(int) c.z:8(int!null) c.s:9(string) c.rowid:10(int!null) c.crdb_internal_mvcc_timestamp:11(decimal) c.tableoid:12(oid)
           ├── stats: [rows=10000, distinct(7)=5000, null(7)=1000, distinct(9)=10, null(9)=7500, distinct(7,9)=10000, null(7,9)=750]
           ├── key: (10)
           └── fd: (10)-->(7-9,11,12)

build colstat=1 colstat=3 colstat=(1,3)
SELECT x,s FROM b EXCEPT SELECT x,s FROM c
----
except
 ├── columns: x:1(int) s:3(string)
 ├── left columns: b.x:1(int) b.s:3(string)
 ├── right columns: c.x:7(int) c.s:9(string)
 ├── stats: [rows=10000, distinct(1)=5000, null(1)=0, distinct(3)=10, null(3)=0, distinct(1,3)=10000, null(1,3)=0]
 ├── key: (1,3)
 ├── project
 │    ├── columns: b.x:1(int) b.s:3(string)
 │    ├── stats: [rows=10000, distinct(1)=5000, null(1)=2500, distinct(3)=10, null(3)=5000, distinct(1,3)=10000, null(1,3)=1250]
 │    └── scan b
 │         ├── columns: b.x:1(int) b.z:2(int!null) b.s:3(string) b.rowid:4(int!null) b.crdb_internal_mvcc_timestamp:5(decimal) b.tableoid:6(oid)
 │         ├── stats: [rows=10000, distinct(1)=5000, null(1)=2500, distinct(3)=10, null(3)=5000, distinct(1,3)=10000, null(1,3)=1250]
 │         ├── key: (4)
 │         └── fd: (4)-->(1-3,5,6)
 └── project
      ├── columns: c.x:7(int) c.s:9(string)
      ├── stats: [rows=10000, distinct(7)=5000, null(7)=1000, distinct(9)=10, null(9)=7500, distinct(7,9)=10000, null(7,9)=750]
      └── scan c
           ├── columns: c.x:7(int) c.z:8(int!null) c.s:9(string) c.rowid:10(int!null) c.crdb_internal_mvcc_timestamp:11(decimal) c.tableoid:12(oid)
           ├── stats: [rows=10000, distinct(7)=5000, null(7)=1000, distinct(9)=10, null(9)=7500, distinct(7,9)=10000, null(7,9)=750]
           ├── key: (10)
           └── fd: (10)-->(7-9,11,12)

build
SELECT x FROM b UNION SELECT x FROM c
----
union
 ├── columns: x:13(int)
 ├── left columns: b.x:1(int)
 ├── right columns: c.x:7(int)
 ├── stats: [rows=10000, distinct(13)=10000, null(13)=1]
 ├── key: (13)
 ├── project
 │    ├── columns: b.x:1(int)
 │    ├── stats: [rows=10000, distinct(1)=5000, null(1)=2500]
 │    └── scan b
 │         ├── columns: b.x:1(int) b.z:2(int!null) b.s:3(string) b.rowid:4(int!null) b.crdb_internal_mvcc_timestamp:5(decimal) b.tableoid:6(oid)
 │         ├── stats: [rows=10000, distinct(1)=5000, null(1)=2500]
 │         ├── key: (4)
 │         └── fd: (4)-->(1-3,5,6)
 └── project
      ├── columns: c.x:7(int)
      ├── stats: [rows=10000, distinct(7)=5000, null(7)=1000]
      └── scan c
           ├── columns: c.x:7(int) c.z:8(int!null) c.s:9(string) c.rowid:10(int!null) c.crdb_internal_mvcc_timestamp:11(decimal) c.tableoid:12(oid)
           ├── stats: [rows=10000, distinct(7)=5000, null(7)=1000]
           ├── key: (10)
           └── fd: (10)-->(7-9,11,12)

build
SELECT x FROM b INTERSECT SELECT x FROM c
----
intersect
 ├── columns: x:1(int)
 ├── left columns: b.x:1(int)
 ├── right columns: c.x:7(int)
 ├── stats: [rows=5000, distinct(1)=5000, null(1)=1]
 ├── key: (1)
 ├── project
 │    ├── columns: b.x:1(int)
 │    ├── stats: [rows=10000, distinct(1)=5000, null(1)=2500]
 │    └── scan b
 │         ├── columns: b.x:1(int) b.z:2(int!null) b.s:3(string) b.rowid:4(int!null) b.crdb_internal_mvcc_timestamp:5(decimal) b.tableoid:6(oid)
 │         ├── stats: [rows=10000, distinct(1)=5000, null(1)=2500]
 │         ├── key: (4)
 │         └── fd: (4)-->(1-3,5,6)
 └── project
      ├── columns: c.x:7(int)
      ├── stats: [rows=10000, distinct(7)=5000, null(7)=1000]
      └── scan c
           ├── columns: c.x:7(int) c.z:8(int!null) c.s:9(string) c.rowid:10(int!null) c.crdb_internal_mvcc_timestamp:11(decimal) c.tableoid:12(oid)
           ├── stats: [rows=10000, distinct(7)=5000, null(7)=1000]
           ├── key: (10)
           └── fd: (10)-->(7-9,11,12)

build
SELECT x FROM b EXCEPT SELECT x FROM c
----
except
 ├── columns: x:1(int)
 ├── left columns: b.x:1(int)
 ├── right columns: c.x:7(int)
 ├── stats: [rows=5000, distinct(1)=5000, null(1)=0]
 ├── key: (1)
 ├── project
 │    ├── columns: b.x:1(int)
 │    ├── stats: [rows=10000, distinct(1)=5000, null(1)=2500]
 │    └── scan b
 │         ├── columns: b.x:1(int) b.z:2(int!null) b.s:3(string) b.rowid:4(int!null) b.crdb_internal_mvcc_timestamp:5(decimal) b.tableoid:6(oid)
 │         ├── stats: [rows=10000, distinct(1)=5000, null(1)=2500]
 │         ├── key: (4)
 │         └── fd: (4)-->(1-3,5,6)
 └── project
      ├── columns: c.x:7(int)
      ├── stats: [rows=10000, distinct(7)=5000, null(7)=1000]
      └── scan c
           ├── columns: c.x:7(int) c.z:8(int!null) c.s:9(string) c.rowid:10(int!null) c.crdb_internal_mvcc_timestamp:11(decimal) c.tableoid:12(oid)
           ├── stats: [rows=10000, distinct(7)=5000, null(7)=1000]
           ├── key: (10)
           └── fd: (10)-->(7-9,11,12)

build colstat=13 colstat=14 colstat=(13,14)
SELECT x,s FROM b UNION ALL SELECT x,s FROM c
----
union-all
 ├── columns: x:13(int) s:14(string)
 ├── left columns: b.x:1(int) b.s:3(string)
 ├── right columns: c.x:7(int) c.s:9(string)
 ├── stats: [rows=20000, distinct(13)=10000, null(13)=3500, distinct(14)=20, null(14)=12500, distinct(13,14)=20000, null(13,14)=2000]
 ├── project
 │    ├── columns: b.x:1(int) b.s:3(string)
 │    ├── stats: [rows=10000, distinct(1)=5000, null(1)=2500, distinct(3)=10, null(3)=5000, distinct(1,3)=10000, null(1,3)=1250]
 │    └── scan b
 │         ├── columns: b.x:1(int) b.z:2(int!null) b.s:3(string) b.rowid:4(int!null) b.crdb_internal_mvcc_timestamp:5(decimal) b.tableoid:6(oid)
 │         ├── stats: [rows=10000, distinct(1)=5000, null(1)=2500, distinct(3)=10, null(3)=5000, distinct(1,3)=10000, null(1,3)=1250]
 │         ├── key: (4)
 │         └── fd: (4)-->(1-3,5,6)
 └── project
      ├── columns: c.x:7(int) c.s:9(string)
      ├── stats: [rows=10000, distinct(7)=5000, null(7)=1000, distinct(9)=10, null(9)=7500, distinct(7,9)=10000, null(7,9)=750]
      └── scan c
           ├── columns: c.x:7(int) c.z:8(int!null) c.s:9(string) c.rowid:10(int!null) c.crdb_internal_mvcc_timestamp:11(decimal) c.tableoid:12(oid)
           ├── stats: [rows=10000, distinct(7)=5000, null(7)=1000, distinct(9)=10, null(9)=7500, distinct(7,9)=10000, null(7,9)=750]
           ├── key: (10)
           └── fd: (10)-->(7-9,11,12)

build colstat=1 colstat=3 colstat=(1,3)
SELECT x,s FROM b INTERSECT ALL SELECT x,s FROM c
----
intersect-all
 ├── columns: x:1(int) s:3(string)
 ├── left columns: b.x:1(int) b.s:3(string)
 ├── right columns: c.x:7(int) c.s:9(string)
 ├── stats: [rows=10000, distinct(1)=5000, null(1)=1000, distinct(3)=10, null(3)=5000, distinct(1,3)=10000, null(1,3)=750]
 ├── project
 │    ├── columns: b.x:1(int) b.s:3(string)
 │    ├── stats: [rows=10000, distinct(1)=5000, null(1)=2500, distinct(3)=10, null(3)=5000, distinct(1,3)=10000, null(1,3)=1250]
 │    └── scan b
 │         ├── columns: b.x:1(int) b.z:2(int!null) b.s:3(string) b.rowid:4(int!null) b.crdb_internal_mvcc_timestamp:5(decimal) b.tableoid:6(oid)
 │         ├── stats: [rows=10000, distinct(1)=5000, null(1)=2500, distinct(3)=10, null(3)=5000, distinct(1,3)=10000, null(1,3)=1250]
 │         ├── key: (4)
 │         └── fd: (4)-->(1-3,5,6)
 └── project
      ├── columns: c.x:7(int) c.s:9(string)
      ├── stats: [rows=10000, distinct(7)=5000, null(7)=1000, distinct(9)=10, null(9)=7500, distinct(7,9)=10000, null(7,9)=750]
      └── scan c
           ├── columns: c.x:7(int) c.z:8(int!null) c.s:9(string) c.rowid:10(int!null) c.crdb_internal_mvcc_timestamp:11(decimal) c.tableoid:12(oid)
           ├── stats: [rows=10000, distinct(7)=5000, null(7)=1000, distinct(9)=10, null(9)=7500, distinct(7,9)=10000, null(7,9)=750]
           ├── key: (10)
           └── fd: (10)-->(7-9,11,12)

build colstat=1 colstat=3 colstat=(1,3)
SELECT x,s FROM b EXCEPT ALL SELECT x,s FROM c
----
except-all
 ├── columns: x:1(int) s:3(string)
 ├── left columns: b.x:1(int) b.s:3(string)
 ├── right columns: c.x:7(int) c.s:9(string)
 ├── stats: [rows=10000, distinct(1)=5000, null(1)=1500, distinct(3)=10, null(3)=0, distinct(1,3)=10000, null(1,3)=500]
 ├── project
 │    ├── columns: b.x:1(int) b.s:3(string)
 │    ├── stats: [rows=10000, distinct(1)=5000, null(1)=2500, distinct(3)=10, null(3)=5000, distinct(1,3)=10000, null(1,3)=1250]
 │    └── scan b
 │         ├── columns: b.x:1(int) b.z:2(int!null) b.s:3(string) b.rowid:4(int!null) b.crdb_internal_mvcc_timestamp:5(decimal) b.tableoid:6(oid)
 │         ├── stats: [rows=10000, distinct(1)=5000, null(1)=2500, distinct(3)=10, null(3)=5000, distinct(1,3)=10000, null(1,3)=1250]
 │         ├── key: (4)
 │         └── fd: (4)-->(1-3,5,6)
 └── project
      ├── columns: c.x:7(int) c.s:9(string)
      ├── stats: [rows=10000, distinct(7)=5000, null(7)=1000, distinct(9)=10, null(9)=7500, distinct(7,9)=10000, null(7,9)=750]
      └── scan c
           ├── columns: c.x:7(int) c.z:8(int!null) c.s:9(string) c.rowid:10(int!null) c.crdb_internal_mvcc_timestamp:11(decimal) c.tableoid:12(oid)
           ├── stats: [rows=10000, distinct(7)=5000, null(7)=1000, distinct(9)=10, null(9)=7500, distinct(7,9)=10000, null(7,9)=750]
           ├── key: (10)
           └── fd: (10)-->(7-9,11,12)

# Regression test for #35715.
opt colstat=(1,2)
SELECT * FROM
(((VALUES (NULL, true), (2, true)) EXCEPT (VALUES (1, NULL), (1, NULL)))) AS t(a, b)
WHERE a IS NULL and b
----
limit
 ├── columns: a:1(int) b:2(bool!null)
 ├── cardinality: [0 - 1]
 ├── stats: [rows=1, distinct(1,2)=1, null(1,2)=0]
 ├── key: ()
 ├── fd: ()-->(1,2)
 ├── select
 │    ├── columns: column1:1(int) column2:2(bool!null)
 │    ├── cardinality: [0 - 2]
 │    ├── stats: [rows=1, distinct(1)=1, null(1)=1, distinct(2)=1, null(2)=0, distinct(1,2)=1, null(1,2)=0]
 │    ├── fd: ()-->(1,2)
 │    ├── limit hint: 1.00
 │    ├── values
 │    │    ├── columns: column1:1(int) column2:2(bool!null)
 │    │    ├── cardinality: [2 - 2]
 │    │    ├── stats: [rows=2, distinct(1)=2, null(1)=1, distinct(2)=1, null(2)=0, distinct(1,2)=2, null(1,2)=0]
 │    │    ├── limit hint: 2.00
 │    │    ├── (NULL, true) [type=tuple{int, bool}]
 │    │    └── (2, true) [type=tuple{int, bool}]
 │    └── filters
 │         ├── column1:1 IS NULL [type=bool, outer=(1), constraints=(/1: [/NULL - /NULL]; tight), fd=()-->(1)]
 │         └── column2:2 [type=bool, outer=(2), constraints=(/2: [/true - /true]; tight), fd=()-->(2)]
 └── 1 [type=int]

# Regression test for #36147 and #36157.
opt
SELECT * FROM
((VALUES (NULL, NULL), (NULL, 1), (2, NULL)) EXCEPT (VALUES (1, 2), (2, 3), (3, 4)))
WHERE column1 IS NULL
----
distinct-on
 ├── columns: column1:1(int) column2:2(int)
 ├── grouping columns: column2:2(int)
 ├── cardinality: [0 - 3]
 ├── stats: [rows=1.6151, distinct(2)=1.6151, null(2)=1]
 ├── key: (2)
 ├── fd: ()-->(1)
 ├── select
 │    ├── columns: column1:1(int) column2:2(int)
 │    ├── cardinality: [0 - 3]
 │    ├── stats: [rows=2, distinct(1)=1, null(1)=2, distinct(2)=1.6151, null(2)=1.33333]
 │    ├── fd: ()-->(1)
 │    ├── values
 │    │    ├── columns: column1:1(int) column2:2(int)
 │    │    ├── cardinality: [3 - 3]
 │    │    ├── stats: [rows=3, distinct(1)=2, null(1)=2, distinct(2)=2, null(2)=2, distinct(1,2)=3, null(1,2)=1]
 │    │    ├── (NULL, NULL) [type=tuple{int, int}]
 │    │    ├── (NULL, 1) [type=tuple{int, int}]
 │    │    └── (2, NULL) [type=tuple{int, int}]
 │    └── filters
 │         └── column1:1 IS NULL [type=bool, outer=(1), constraints=(/1: [/NULL - /NULL]; tight), fd=()-->(1)]
 └── aggregations
      └── const-agg [as=column1:1, type=int, outer=(1)]
           └── column1:1 [type=int]

# Make sure that we estimate at least 1 row for the intersect.
opt disable=SimplifyIntersectRight
VALUES (1), (2) INTERSECT VALUES (NULL) ORDER BY 1
----
intersect
 ├── columns: column1:1(int)
 ├── left columns: column1:1(int)
 ├── right columns: column1:2(int)
 ├── cardinality: [0 - 1]
 ├── stats: [rows=1, distinct(1)=1, null(1)=0]
 ├── key: ()
 ├── fd: ()-->(1)
 ├── values
 │    ├── columns: column1:1(int!null)
 │    ├── cardinality: [2 - 2]
 │    ├── stats: [rows=2, distinct(1)=2, null(1)=0]
 │    ├── (1,) [type=tuple{int}]
 │    └── (2,) [type=tuple{int}]
 └── values
      ├── columns: column1:2(int)
      ├── cardinality: [1 - 1]
      ├── stats: [rows=1, distinct(2)=1, null(2)=1]
      ├── key: ()
      ├── fd: ()-->(2)
      └── (NULL,) [type=tuple{int}]
