exec-ddl
CREATE TABLE xyzs (x INT PRIMARY KEY, y INT, z FLOAT NOT NULL, s STRING, UNIQUE (s DESC, z))
----
TABLE xyzs
 ├── x int not null
 ├── y int
 ├── z float not null
 ├── s string
 ├── INDEX primary
 │    └── x int not null
 └── INDEX secondary
      ├── s string desc
      ├── z float not null
      └── x int not null (storing)

exec-ddl
CREATE TABLE kuv (k INT PRIMARY KEY, u FLOAT, v STRING)
----
TABLE kuv
 ├── k int not null
 ├── u float
 ├── v string
 └── INDEX primary
      └── k int not null

build
SELECT * FROM xyzs LIMIT 1
----
limit
 ├── columns: x:1(int!null) y:2(int) z:3(float!null) s:4(string)
 ├── cardinality: [0 - 1]
 ├── key: ()
 ├── fd: ()-->(1-4)
 ├── prune: (1-4)
 ├── interesting orderings: (+1) (-4,+3,+1)
 ├── scan xyzs
 │    ├── columns: x:1(int!null) y:2(int) z:3(float!null) s:4(string)
 │    ├── key: (1)
 │    ├── fd: (1)-->(2-4), (3,4)~~>(1,2)
 │    ├── prune: (1-4)
 │    └── interesting orderings: (+1) (-4,+3,+1)
 └── const: 1 [type=int]

build
SELECT count(*) FROM xyzs LIMIT 10
----
limit
 ├── columns: count:5(int)
 ├── cardinality: [1 - 1]
 ├── key: ()
 ├── fd: ()-->(5)
 ├── prune: (5)
 ├── scalar-group-by
 │    ├── columns: count_rows:5(int)
 │    ├── cardinality: [1 - 1]
 │    ├── key: ()
 │    ├── fd: ()-->(5)
 │    ├── prune: (5)
 │    ├── project
 │    │    └── scan xyzs
 │    │         ├── columns: x:1(int!null) y:2(int) z:3(float!null) s:4(string)
 │    │         ├── key: (1)
 │    │         ├── fd: (1)-->(2-4), (3,4)~~>(1,2)
 │    │         ├── prune: (1-4)
 │    │         └── interesting orderings: (+1) (-4,+3,+1)
 │    └── aggregations
 │         └── count-rows [type=int]
 └── const: 10 [type=int]

build
SELECT * FROM xyzs LIMIT (SELECT 1)
----
limit
 ├── columns: x:1(int!null) y:2(int) z:3(float!null) s:4(string)
 ├── side-effects
 ├── key: (1)
 ├── fd: (1)-->(2-4), (3,4)~~>(1,2)
 ├── prune: (1-4)
 ├── interesting orderings: (+1) (-4,+3,+1)
 ├── scan xyzs
 │    ├── columns: x:1(int!null) y:2(int) z:3(float!null) s:4(string)
 │    ├── key: (1)
 │    ├── fd: (1)-->(2-4), (3,4)~~>(1,2)
 │    ├── prune: (1-4)
 │    └── interesting orderings: (+1) (-4,+3,+1)
 └── subquery [type=int]
      └── max1-row
           ├── columns: "?column?":5(int!null)
           ├── cardinality: [1 - 1]
           ├── key: ()
           ├── fd: ()-->(5)
           └── project
                ├── columns: "?column?":5(int!null)
                ├── cardinality: [1 - 1]
                ├── key: ()
                ├── fd: ()-->(5)
                ├── prune: (5)
                ├── values
                │    ├── cardinality: [1 - 1]
                │    ├── key: ()
                │    └── tuple [type=tuple]
                └── projections
                     └── const: 1 [type=int]

build
SELECT * FROM xyzs LIMIT 0
----
limit
 ├── columns: x:1(int!null) y:2(int) z:3(float!null) s:4(string)
 ├── cardinality: [0 - 0]
 ├── key: ()
 ├── fd: ()-->(1-4)
 ├── prune: (1-4)
 ├── interesting orderings: (+1) (-4,+3,+1)
 ├── scan xyzs
 │    ├── columns: x:1(int!null) y:2(int) z:3(float!null) s:4(string)
 │    ├── key: (1)
 │    ├── fd: (1)-->(2-4), (3,4)~~>(1,2)
 │    ├── prune: (1-4)
 │    └── interesting orderings: (+1) (-4,+3,+1)
 └── const: 0 [type=int]

# Propagate outer columns.
build
SELECT (SELECT x FROM kuv LIMIT y) FROM xyzs
----
project
 ├── columns: x:9(int)
 ├── side-effects
 ├── prune: (9)
 ├── scan xyzs
 │    ├── columns: xyzs.x:1(int!null) y:2(int) z:3(float!null) s:4(string)
 │    ├── key: (1)
 │    ├── fd: (1)-->(2-4), (3,4)~~>(1,2)
 │    ├── prune: (1-4)
 │    └── interesting orderings: (+1) (-4,+3,+1)
 └── projections [outer=(1,2), side-effects]
      └── subquery [type=int, outer=(1,2), side-effects]
           └── max1-row
                ├── columns: x:8(int)
                ├── outer: (1,2)
                ├── cardinality: [0 - 1]
                ├── side-effects
                ├── key: ()
                ├── fd: ()-->(8)
                └── limit
                     ├── columns: x:8(int)
                     ├── outer: (1,2)
                     ├── side-effects
                     ├── fd: ()-->(8)
                     ├── prune: (8)
                     ├── project
                     │    ├── columns: x:8(int)
                     │    ├── outer: (1)
                     │    ├── fd: ()-->(8)
                     │    ├── prune: (8)
                     │    ├── scan kuv
                     │    │    ├── columns: k:5(int!null) u:6(float) v:7(string)
                     │    │    ├── key: (5)
                     │    │    ├── fd: (5)-->(6,7)
                     │    │    ├── prune: (5-7)
                     │    │    └── interesting orderings: (+5)
                     │    └── projections [outer=(1)]
                     │         └── variable: xyzs.x [type=int, outer=(1)]
                     └── variable: y [type=int, outer=(2)]

# Test very high limit (> max uint32).
opt
SELECT s, x FROM xyzs WHERE s='foo' LIMIT 4294967296
----
scan xyzs@secondary
 ├── columns: s:4(string!null) x:1(int!null)
 ├── constraint: /-4/3: [/'foo' - /'foo']
 ├── limit: 4294967296
 ├── key: (1)
 ├── fd: ()-->(4)
 ├── prune: (1)
 └── interesting orderings: (+1) (-4)
