Skip to content

Commit

Permalink
Mark non-unique lookup vindex as backfill to ignore vindex selection (#…
Browse files Browse the repository at this point in the history
…14227)

Signed-off-by: Armand Parajon <[email protected]>
  • Loading branch information
aparajon authored Jan 24, 2024
1 parent dc4435e commit 58bb702
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 4 deletions.
17 changes: 14 additions & 3 deletions go/vt/vtgate/planbuilder/plan_test_vindex.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ func newLookupIndex(name string, _ map[string]string) (vindexes.Vindex, error) {
var _ vindexes.Lookup = (*lookupIndex)(nil)

// nameLkpIndex satisfies Lookup, NonUnique.
type nameLkpIndex struct{ name string }
type nameLkpIndex struct {
name string
inBackfill bool
}

func (v *nameLkpIndex) String() string { return v.name }
func (*nameLkpIndex) Cost() int { return 3 }
Expand Down Expand Up @@ -102,13 +105,21 @@ func (*nameLkpIndex) Query() (string, []string) {
func (*nameLkpIndex) MapResult([]sqltypes.Value, []*sqltypes.Result) ([]key.Destination, error) {
return nil, nil
}
func newNameLkpIndex(name string, _ map[string]string) (vindexes.Vindex, error) {
return &nameLkpIndex{name: name}, nil

func (v *nameLkpIndex) IsBackfilling() bool { return v.inBackfill }

func newNameLkpIndex(name string, m map[string]string) (vindexes.Vindex, error) {
vdx := &nameLkpIndex{name: name}
if val, ok := m["write_only"]; ok {
vdx.inBackfill = val == "true"
}
return vdx, nil
}

var _ vindexes.Vindex = (*nameLkpIndex)(nil)
var _ vindexes.Lookup = (*nameLkpIndex)(nil)
var _ vindexes.LookupPlanable = (*nameLkpIndex)(nil)
var _ vindexes.LookupBackfill = (*nameLkpIndex)(nil)

// costlyIndex satisfies Lookup, NonUnique.
type costlyIndex struct{ name string }
Expand Down
22 changes: 22 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/select_cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -4598,6 +4598,28 @@
]
}
},
{
"comment": "name is in backfill vindex - not selected for vindex lookup",
"query": "select * from customer where name = 'x'",
"plan": {
"QueryType": "SELECT",
"Original": "select * from customer where name = 'x'",
"Instructions": {
"OperatorType": "Route",
"Variant": "Scatter",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"FieldQuery": "select * from customer where 1 != 1",
"Query": "select * from customer where `name` = 'x'",
"Table": "customer"
},
"TablesUsed": [
"user.customer"
]
}
},
{
"comment": "email vindex is costly than phone vindex - but phone vindex is backfiling hence ignored",
"query": "select * from customer where email = '[email protected]' and phone = 123456",
Expand Down
14 changes: 14 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/vschemas/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,16 @@
"to": "keyspace_id",
"cost": "300"
}
},
"lkp_bf_vdx": {
"type": "name_lkp_test",
"owner": "customer",
"params": {
"table": "lkp_shard_vdx",
"from": " ",
"to": "keyspace_id",
"write_only": "true"
}
}
},
"tables": {
Expand Down Expand Up @@ -476,6 +486,10 @@
{
"column": "phone",
"name": "unq_lkp_bf_vdx"
},
{
"column": "name",
"name": "lkp_bf_vdx"
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vtgate/vindexes/consistent_lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -489,7 +489,7 @@ func (lu *clCommon) GetCommitOrder() vtgatepb.CommitOrder {
}

// IsBackfilling implements the LookupBackfill interface
func (lu *ConsistentLookupUnique) IsBackfilling() bool {
func (lu *clCommon) IsBackfilling() bool {
return lu.writeOnly
}

Expand Down
5 changes: 5 additions & 0 deletions go/vt/vtgate/vindexes/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,11 @@ func (ln *LookupNonUnique) MarshalJSON() ([]byte, error) {
return json.Marshal(ln.lkp)
}

// IsBackfilling implements the LookupBackfill interface
func (ln *LookupNonUnique) IsBackfilling() bool {
return ln.writeOnly
}

// Query implements the LookupPlanable interface
func (ln *LookupNonUnique) Query() (selQuery string, arguments []string) {
return ln.lkp.query()
Expand Down

0 comments on commit 58bb702

Please sign in to comment.