exec-ddl
CREATE TABLE abc (
    a INT NOT NULL,
    b TEXT DEFAULT ('foo'),
    c FLOAT AS (a::float) STORED
)
----
TABLE abc
 ├── a int not null
 ├── b string
 ├── c float
 ├── rowid int not null (hidden)
 └── INDEX primary
      └── rowid int not null (hidden)

exec-ddl
ALTER TABLE abc INJECT STATISTICS '[
  {
    "columns": ["a"],
    "created_at": "2018-01-01 1:00:00.00000+00:00",
    "row_count": 2000,
    "distinct_count": 2000
  },
  {
    "columns": ["b"],
    "created_at": "2018-01-01 1:30:00.00000+00:00",
    "row_count": 2000,
    "distinct_count": 10
  }
]'
----

exec-ddl
CREATE TABLE xyz (
    x TEXT PRIMARY KEY,
    y INT8 NOT NULL,
    z FLOAT8
)
----
TABLE xyz
 ├── x string not null
 ├── y int not null
 ├── z float
 └── INDEX primary
      └── x string not null

# Statistics should be derived from INSERT input columns and transferred to
# RETURNING columns.
build
SELECT *
FROM [INSERT INTO xyz (x, y, z) SELECT b, a, c FROM abc WHERE b='foo' RETURNING *]
WHERE z > 1.0
----
select
 ├── columns: x:1(string!null) y:2(int!null) z:3(float!null)
 ├── side-effects, mutations
 ├── stats: [rows=66, distinct(1)=1, null(1)=0, distinct(2)=66, null(2)=0, distinct(3)=60.3661899, null(3)=0]
 ├── fd: ()-->(1)
 ├── insert xyz
 │    ├── columns: x:1(string!null) y:2(int!null) z:3(float)
 │    ├── insert-mapping:
 │    │    ├──  b:5 => x:1
 │    │    ├──  a:4 => y:2
 │    │    └──  c:6 => z:3
 │    ├── side-effects, mutations
 │    ├── stats: [rows=200, distinct(1)=1, null(1)=0, distinct(2)=200, null(2)=0, distinct(3)=130.264312, null(3)=2]
 │    ├── fd: ()-->(1)
 │    └── project
 │         ├── columns: a:4(int!null) b:5(string!null) c:6(float)
 │         ├── stats: [rows=200, distinct(4)=200, null(4)=0, distinct(5)=1, null(5)=0, distinct(6)=130.264312, null(6)=2]
 │         ├── fd: ()-->(5)
 │         └── select
 │              ├── columns: a:4(int!null) b:5(string!null) c:6(float) rowid:7(int!null)
 │              ├── stats: [rows=200, distinct(4)=200, null(4)=0, distinct(5)=1, null(5)=0, distinct(6)=130.264312, null(6)=2, distinct(7)=200, null(7)=0]
 │              ├── key: (7)
 │              ├── fd: ()-->(5), (7)-->(4,6)
 │              ├── scan abc
 │              │    ├── columns: a:4(int!null) b:5(string) c:6(float) rowid:7(int!null)
 │              │    ├── stats: [rows=2000, distinct(4)=2000, null(4)=0, distinct(5)=10, null(5)=0, distinct(6)=200, null(6)=20, distinct(7)=2000, null(7)=0]
 │              │    ├── key: (7)
 │              │    └── fd: (7)-->(4-6)
 │              └── filters
 │                   └── b = 'foo' [type=bool, outer=(5), constraints=(/5: [/'foo' - /'foo']; tight), fd=()-->(5)]
 └── filters
      └── z > 1.0 [type=bool, outer=(3), constraints=(/3: [/1.0000000000000002 - ]; tight)]

# Cardinality is zero.
build
INSERT INTO xyz (x, y, z) SELECT b, a, c FROM abc WHERE False RETURNING *
----
insert xyz
 ├── columns: x:1(string!null) y:2(int!null) z:3(float)
 ├── insert-mapping:
 │    ├──  b:5 => x:1
 │    ├──  a:4 => y:2
 │    └──  c:6 => z:3
 ├── cardinality: [0 - 0]
 ├── side-effects, mutations
 ├── stats: [rows=0]
 └── project
      ├── columns: a:4(int!null) b:5(string) c:6(float)
      ├── cardinality: [0 - 0]
      ├── stats: [rows=0]
      └── select
           ├── columns: a:4(int!null) b:5(string) c:6(float) rowid:7(int!null)
           ├── cardinality: [0 - 0]
           ├── stats: [rows=0]
           ├── key: (7)
           ├── fd: (7)-->(4-6)
           ├── scan abc
           │    ├── columns: a:4(int!null) b:5(string) c:6(float) rowid:7(int!null)
           │    ├── stats: [rows=2000]
           │    ├── key: (7)
           │    └── fd: (7)-->(4-6)
           └── filters
                └── false [type=bool]
