Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark non-unique lookup vindex as backfill to ignore vindex selection #14227

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -4664,6 +4664,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()
Comment on lines +184 to 191
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add this to ConsistentLookup as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 7361fe245816db696c12da9306da125539aacffa, I think using *clCommon should take care of that.

Expand Down
Loading