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

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

# In order to actually create new logical props for the index join, we need to
# call ConstructLookupJoin, which only happens when where is a remaining filter.
opt
SELECT * FROM a WHERE s = 'foo' AND x + y = 10
----
select
 ├── columns: x:1(int!null) y:2(int) s:3(string!null) d:4(decimal!null)
 ├── key: (1)
 ├── fd: ()-->(3), (1)-->(2,4), (4)-->(1,2), (2,3)~~>(1,4)
 ├── prune: (4)
 ├── interesting orderings: (+1) (-3,+4,+1)
 ├── index-join a
 │    ├── columns: x:1(int!null) y:2(int) s:3(string) d:4(decimal!null)
 │    ├── key: (1)
 │    ├── fd: ()-->(3), (1)-->(2,4), (4)-->(1), (3,4)~~>(1,2), (2,3)~~>(1,4)
 │    ├── interesting orderings: (+1) (-3,+4,+1)
 │    └── scan a@secondary
 │         ├── columns: x:1(int!null) s:3(string!null) d:4(decimal!null)
 │         ├── constraint: /-3/4: [/'foo' - /'foo']
 │         ├── key: (1)
 │         ├── fd: ()-->(3), (1)-->(4), (4)-->(1)
 │         ├── prune: (1,3,4)
 │         └── interesting orderings: (+1) (-3,+4,+1)
 └── filters [type=bool, outer=(1,2)]
      └── eq [type=bool, outer=(1,2)]
           ├── plus [type=int, outer=(1,2)]
           │    ├── variable: x [type=int, outer=(1)]
           │    └── variable: y [type=int, outer=(2)]
           └── const: 10 [type=int]

opt
SELECT y FROM a WHERE s = 'foo' AND x + y = 10
----
project
 ├── columns: y:2(int)
 ├── lax-key: (2)
 ├── prune: (2)
 └── select
      ├── columns: x:1(int!null) y:2(int) s:3(string!null)
      ├── key: (1)
      ├── fd: ()-->(3), (1)-->(2), (2,3)~~>(1)
      ├── interesting orderings: (+1) (-3)
      ├── index-join a
      │    ├── columns: x:1(int!null) y:2(int) s:3(string)
      │    ├── key: (1)
      │    ├── fd: ()-->(3), (1)-->(2), (2,3)~~>(1)
      │    ├── interesting orderings: (+1) (-3)
      │    └── scan a@secondary
      │         ├── columns: x:1(int!null) s:3(string!null)
      │         ├── constraint: /-3/4: [/'foo' - /'foo']
      │         ├── key: (1)
      │         ├── fd: ()-->(3)
      │         ├── prune: (1,3)
      │         └── interesting orderings: (+1) (-3)
      └── filters [type=bool, outer=(1,2)]
           └── eq [type=bool, outer=(1,2)]
                ├── plus [type=int, outer=(1,2)]
                │    ├── variable: x [type=int, outer=(1)]
                │    └── variable: y [type=int, outer=(2)]
                └── const: 10 [type=int]

# Use secondary index to join to multi-valued primary index, but project only
# a subset of the primary columns.
opt
SELECT b, c, d FROM abc WHERE c=1 AND d=2
----
select
 ├── columns: b:2(int!null) c:3(int!null) d:4(int!null)
 ├── fd: ()-->(3,4)
 ├── prune: (2)
 ├── interesting orderings: (+1,+2) (+3,+1,+2)
 ├── index-join abc
 │    ├── columns: b:2(int!null) c:3(int) d:4(int)
 │    ├── fd: ()-->(3)
 │    ├── interesting orderings: (+1,+2) (+3,+1,+2)
 │    └── scan abc@secondary
 │         ├── columns: a:1(int!null) b:2(int!null) c:3(int!null)
 │         ├── constraint: /3/1/2: [/1 - /1]
 │         ├── key: (1,2)
 │         ├── fd: ()-->(3)
 │         ├── prune: (1-3)
 │         └── interesting orderings: (+1,+2) (+3,+1,+2)
 └── filters [type=bool, outer=(4), constraints=(/4: [/2 - /2]; tight), fd=()-->(4)]
      └── eq [type=bool, outer=(4), constraints=(/4: [/2 - /2]; tight)]
           ├── variable: d [type=int, outer=(4)]
           └── const: 2 [type=int]
