@@ -3119,6 +3119,38 @@ left-join (lookup lookup_expr [as=t])
31193119 │ └── column1:1 = w:7 [outer=(1,7), constraints=(/1: (/NULL - ]; /7: (/NULL - ]), fd=(1)==(7), (7)==(1)]
31203120 └── filters (true)
31213121
3122+ # The filters in the lookup expression should contains all columns of the
3123+ # idx_vrw index. Column r, though not in the ON exprs, should still be
3124+ # in the filters, because for the column w that comes behind it in
3125+ # idx_vrw, there is a necessary filter `w IN (10, 20)`.
3126+ opt expect=GenerateLookupJoinsWithFilter
3127+ SELECT * FROM (VALUES (1), (2), (3)) AS q(v) LEFT LOOKUP JOIN lookup_expr t
3128+ ON q.v = t.v WHERE w IN (10, 20)
3129+ ----
3130+ inner-join (lookup lookup_expr [as=t])
3131+ ├── columns: v:1!null r:2!null k:3!null u:4 v:5!null w:6!null x:7 y:8!null z:9!null
3132+ ├── key columns: [2 3] = [2 3]
3133+ ├── lookup columns are key
3134+ ├── fd: ()-->(9), (2,3)-->(4-8), (1)==(5), (5)==(1)
3135+ ├── inner-join (lookup lookup_expr@idx_vrw [as=t])
3136+ │ ├── columns: column1:1!null r:2!null k:3!null v:5!null w:6!null
3137+ │ ├── flags: force lookup join (into right side)
3138+ │ ├── lookup expression
3139+ │ │ └── filters
3140+ │ │ ├── r:2 IN ('east', 'west') [outer=(2), constraints=(/2: [/'east' - /'east'] [/'west' - /'west']; tight)]
3141+ │ │ ├── w:6 IN (10, 20) [outer=(6), constraints=(/6: [/10 - /10] [/20 - /20]; tight)]
3142+ │ │ └── column1:1 = v:5 [outer=(1,5), constraints=(/1: (/NULL - ]; /5: (/NULL - ]), fd=(1)==(5), (5)==(1)]
3143+ │ ├── fd: (2,3)-->(5,6), (1)==(5), (5)==(1)
3144+ │ ├── values
3145+ │ │ ├── columns: column1:1!null
3146+ │ │ ├── cardinality: [3 - 3]
3147+ │ │ ├── (1,)
3148+ │ │ ├── (2,)
3149+ │ │ └── (3,)
3150+ │ └── filters (true)
3151+ └── filters (true)
3152+
3153+
31223154# Ensure that we constrain all columns in idx_vrw, not just v.
31233155opt expect=GenerateLookupJoins
31243156SELECT * FROM (VALUES (1, 10), (2, 20), (3, NULL)) AS q(v, w) LEFT JOIN lookup_expr t
0 commit comments