exec-ddl
CREATE TABLE a (k INT PRIMARY KEY, i INT, s STRING, d DECIMAL NOT NULL)
----
TABLE a
 ├── k int not null
 ├── i int
 ├── s string
 ├── d decimal not null
 └── INDEX primary
      └── k int not null

exec-ddl
CREATE TABLE b (x INT, z INT NOT NULL)
----
TABLE b
 ├── x int
 ├── z int not null
 ├── rowid int not null (hidden)
 └── INDEX primary
      └── rowid int not null (hidden)

opt
SELECT k, x FROM a INNER JOIN b ON k=x WHERE d=1.0
----
project
 ├── columns: k:1(int!null) x:5(int!null)
 ├── stats: [rows=100]
 ├── cost: 2124.675
 ├── fd: (1)==(5), (5)==(1)
 └── inner-join
      ├── columns: k:1(int!null) d:4(decimal!null) x:5(int!null)
      ├── stats: [rows=100, distinct(1)=10, distinct(5)=10]
      ├── cost: 2123.675
      ├── fd: ()-->(4), (1)==(5), (5)==(1)
      ├── scan b
      │    ├── columns: x:5(int)
      │    ├── stats: [rows=1000, distinct(5)=100]
      │    └── cost: 1040
      ├── select
      │    ├── columns: k:1(int!null) d:4(decimal!null)
      │    ├── stats: [rows=10, distinct(1)=10, distinct(4)=1]
      │    ├── cost: 1070
      │    ├── key: (1)
      │    ├── fd: ()-->(4)
      │    ├── scan a
      │    │    ├── columns: k:1(int!null) d:4(decimal!null)
      │    │    ├── stats: [rows=1000, distinct(1)=1000, distinct(4)=100]
      │    │    ├── cost: 1060
      │    │    ├── key: (1)
      │    │    └── fd: (1)-->(4)
      │    └── filters [type=bool, outer=(4), constraints=(/4: [/1.0 - /1.0]; tight), fd=()-->(4)]
      │         └── d = 1.0 [type=bool, outer=(4), constraints=(/4: [/1.0 - /1.0]; tight)]
      └── filters [type=bool, outer=(1,5), constraints=(/1: (/NULL - ]; /5: (/NULL - ]), fd=(1)==(5), (5)==(1)]
           └── k = x [type=bool, outer=(1,5), constraints=(/1: (/NULL - ]; /5: (/NULL - ])]

exec-ddl
CREATE TABLE abc (a INT PRIMARY KEY, b INT, c INT, INDEX c_idx (c))
----
TABLE abc
 ├── a int not null
 ├── b int
 ├── c int
 ├── INDEX primary
 │    └── a int not null
 └── INDEX c_idx
      ├── c int
      └── a int not null

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

# Check that we choose the lookup join when it makes sense.
opt
SELECT * FROM abc WHERE c = 1
----
index-join abc
 ├── columns: a:1(int!null) b:2(int) c:3(int!null)
 ├── stats: [rows=10, distinct(3)=1]
 ├── cost: 51.1
 ├── key: (1)
 ├── fd: ()-->(3), (1)-->(2)
 └── scan abc@c_idx
      ├── columns: a:1(int!null) c:3(int!null)
      ├── constraint: /3/1: [/1 - /1]
      ├── stats: [rows=10, distinct(3)=1]
      ├── cost: 10.4
      ├── key: (1)
      └── fd: ()-->(3)
