Skip to content

opt: unnecessary cross-joins with when generating a lookup join with a lookup expression #79384

@mgartner

Description

@mgartner

Notice in the query plan below that the cross-join to produce the lookup_join_const_col_@7 column is unnecessary.

exec-ddl
CREATE TABLE t1234 (
  a INT,
  b INT,
  c INT,
  INDEX (a, b, c)
)
----

opt expect=GenerateLookupJoinsWithFilter
SELECT m FROM small JOIN t1234 ON b IN (1, 2, 3) AND c > 0 AND m = a
----
project
 ├── columns: m:1!null
 └── inner-join (lookup t1234@t1234_a_b_c_idx)
      ├── columns: m:1!null a:6!null b:7!null c:8!null
      ├── lookup expression
      │    └── filters
      │         ├── m:1 = a:6 [outer=(1,6), constraints=(/1: (/NULL - ]; /6: (/NULL - ]), fd=(1)==(6), (6)==(1)]
      │         ├── b:7 IN (1, 2, 3) [outer=(7), constraints=(/7: [/1 - /1] [/2 - /2] [/3 - /3]; tight)]
      │         └── c:8 > 0 [outer=(8), constraints=(/8: [/1 - ]; tight)]
      ├── fd: (1)==(6), (6)==(1)
      ├── inner-join (cross)
      │    ├── columns: m:1 "lookup_join_const_col_@7":12!null
      │    ├── multiplicity: left-rows(one-or-more), right-rows(zero-or-more)
      │    ├── scan small
      │    │    └── columns: m:1
      │    ├── values
      │    │    ├── columns: "lookup_join_const_col_@7":12!null
      │    │    ├── cardinality: [3 - 3]
      │    │    ├── (1,)
      │    │    ├── (2,)
      │    │    └── (3,)
      │    └── filters (true)
      └── filters (true)

Jira issue: CRDB-14777

Metadata

Metadata

Assignees

Labels

C-bugCode not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior.C-technical-advisoryCaused a technical advisoryT-sql-queriesSQL Queries Teambranch-release-21.1Used to mark GA and release blockers, technical advisories, and bugs for 21.1branch-release-21.2Used to mark GA and release blockers, technical advisories, and bugs for 21.2

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions