exec-ddl
CREATE TABLE a (x INT PRIMARY KEY, y INT, s STRING, d DECIMAL NOT NULL, UNIQUE (s DESC, d))
----

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

build
SELECT * FROM a
----
scan a
 ├── columns: x:1(int!null) y:2(int) s:3(string) d:4(decimal!null)
 ├── key: (1)
 ├── fd: (1)-->(2-4), (3,4)~~>(1,2)
 ├── prune: (1-4)
 └── interesting orderings: (+1) (-3,+4,+1)

build
SELECT * FROM b
----
project
 ├── columns: x:1(int) z:2(int!null)
 ├── prune: (1,2)
 └── scan b
      ├── columns: x:1(int) z:2(int!null) rowid:3(int!null)
      ├── key: (3)
      ├── fd: (3)-->(1,2)
      ├── prune: (1-3)
      └── interesting orderings: (+3)

# Select subset of columns.
opt
SELECT s, x FROM a
----
scan a@secondary
 ├── columns: s:3(string) x:1(int!null)
 ├── key: (1)
 ├── fd: (1)-->(3)
 ├── prune: (1,3)
 └── interesting orderings: (+1) (-3)

# Test constrained scan.
opt
SELECT s, x FROM a WHERE x=1
----
scan a
 ├── columns: s:3(string) x:1(int!null)
 ├── constraint: /1: [/1 - /1]
 ├── cardinality: [0 - 1]
 ├── key: ()
 ├── fd: ()-->(1,3)
 ├── prune: (3)
 └── interesting orderings: (+1) (-3)

# Test limited scan.
opt
SELECT s, x FROM a WHERE x > 1 LIMIT 2
----
scan a
 ├── columns: s:3(string) x:1(int!null)
 ├── constraint: /1: [/2 - ]
 ├── limit: 2
 ├── key: (1)
 ├── fd: (1)-->(3)
 ├── prune: (3)
 └── interesting orderings: (+1) (-3)

# Test limited scan with 1 row.
opt
SELECT s, x FROM a WHERE x > 1 LIMIT 1
----
scan a
 ├── columns: s:3(string) x:1(int!null)
 ├── constraint: /1: [/2 - ]
 ├── limit: 1
 ├── key: ()
 ├── fd: ()-->(1,3)
 ├── prune: (3)
 └── interesting orderings: (+1) (-3)

# Test case where there are no weak keys available.
opt
SELECT d FROM a
----
scan a@secondary
 ├── columns: d:4(decimal!null)
 └── prune: (4)

exec-ddl
CREATE TABLE t (
  a INT,
  b CHAR,
  c INT,
  d CHAR,
  PRIMARY KEY (a, b),
  INDEX bc (b, c),
  INDEX dc (d, c),
  INDEX a_desc (a DESC),
  FAMILY (a, b),
  FAMILY (c),
  FAMILY (d)
)
----

opt
SELECT 1 FROM t WHERE a > 1 AND a < 2
----
values
 ├── columns: "?column?":5(int!null)
 ├── cardinality: [0 - 0]
 ├── key: ()
 ├── fd: ()-->(5)
 └── prune: (5)

opt
SELECT * FROM t WHERE b IN ('a', 'b') AND c IN (1, 2) AND a IN (2, 3)
----
index-join t
 ├── columns: a:1(int!null) b:2(char!null) c:3(int!null) d:4(char)
 ├── key: (1,2)
 ├── fd: (1,2)-->(3,4)
 ├── prune: (4)
 ├── interesting orderings: (+1,+2) (+2,+3,+1) (-1,+2)
 └── scan t@bc
      ├── columns: a:1(int!null) b:2(char!null) c:3(int!null)
      ├── constraint: /2/3/1: [/'a'/1/2 - /'a'/1/3] [/'a'/2/2 - /'a'/2/3] [/'b'/1/2 - /'b'/1/3] [/'b'/2/2 - /'b'/2/3]
      ├── cardinality: [0 - 8]
      ├── key: (1,2)
      ├── fd: (1,2)-->(3)
      ├── prune: (1-3)
      └── interesting orderings: (+1,+2) (+2,+3,+1) (-1,+2)

opt
SELECT * FROM a WHERE x IN (1, 2, 4, 6, 7, 9)
----
scan a
 ├── columns: x:1(int!null) y:2(int) s:3(string) d:4(decimal!null)
 ├── constraint: /1: [/1 - /2] [/4 - /4] [/6 - /7] [/9 - /9]
 ├── cardinality: [0 - 6]
 ├── key: (1)
 ├── fd: (1)-->(2-4), (3,4)~~>(1,2)
 ├── prune: (2-4)
 └── interesting orderings: (+1) (-3,+4,+1)

exec-ddl
CREATE TABLE date_pk (d DATE PRIMARY KEY, i INT)
----

opt
SELECT * FROM date_pk WHERE d IN ('2019-08-08', '2019-08-07') OR (d >= '2017-01-01' AND d < '2017-01-05')
----
select
 ├── columns: d:1(date!null) i:2(int)
 ├── cardinality: [0 - 6]
 ├── key: (1)
 ├── fd: (1)-->(2)
 ├── prune: (2)
 ├── interesting orderings: (+1)
 ├── scan date_pk
 │    ├── columns: d:1(date!null) i:2(int)
 │    ├── constraint: /1: [/'2017-01-01' - /'2017-01-04'] [/'2019-08-07' - /'2019-08-08']
 │    ├── cardinality: [0 - 6]
 │    ├── key: (1)
 │    ├── fd: (1)-->(2)
 │    ├── prune: (1,2)
 │    └── interesting orderings: (+1)
 └── filters
      └── or [type=bool, outer=(1), constraints=(/1: (/NULL - /'2017-01-04'] [/'2019-08-07' - /'2019-08-07'] [/'2019-08-08' - /'2019-08-08'])]
           ├── in [type=bool]
           │    ├── variable: d [type=date]
           │    └── tuple [type=tuple{date, date}]
           │         ├── const: '2019-08-07' [type=date]
           │         └── const: '2019-08-08' [type=date]
           └── lt [type=bool]
                ├── variable: d [type=date]
                └── const: '2017-01-05' [type=date]
