Skip to content

Commit

Permalink
Merge pull request #5023 from bumbing/upstream
Browse files Browse the repository at this point in the history
 Keep the lowest cost vindex for each column if there are multiple ones
  • Loading branch information
sougou authored Jul 27, 2019
2 parents 7ff352b + e6f2064 commit 9a6e7da
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
4 changes: 3 additions & 1 deletion go/vt/vtgate/planbuilder/symtab.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ func (st *symtab) AddVSchemaTable(alias sqlparser.TableName, vschemaTables []*vi
if vindexMap == nil {
vindexMap = make(map[*column]vindexes.Vindex)
}
vindexMap[col] = cv.Vindex
if vindexMap[col] == nil || vindexMap[col].Cost() > cv.Vindex.Cost() {
vindexMap[col] = cv.Vindex
}
}
}
}
Expand Down
26 changes: 26 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/schema_test.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@
"hash_dup": {
"type": "hash_test",
"owner": "user"
},
"vindex1": {
"type": "hash_test",
"owner": "samecolvin"
},
"vindex2": {
"type": "lookup_test",
"owner": "samecolvin"
}
},
"tables": {
Expand Down Expand Up @@ -170,6 +178,24 @@
],
"column_list_authoritative": true
},
"samecolvin": {
"column_vindexes": [
{
"column": "col",
"name": "vindex1"
},
{
"column": "col",
"name": "vindex2"
}
],
"columns": [
{
"name": "col"
}
],
"column_list_authoritative": true
},
"multicolvin": {
"column_vindexes": [
{
Expand Down
19 changes: 19 additions & 0 deletions go/vt/vtgate/planbuilder/testdata/vindex_func_cases.txt
Original file line number Diff line number Diff line change
Expand Up @@ -336,3 +336,22 @@

"select none from user_index where id = :id"
"symbol none not found in table or subquery"

"select * from samecolvin where col = :col"
{
"Original": "select * from samecolvin where col = :col",
"Instructions": {
"Opcode": "SelectEqualUnique",
"Keyspace": {
"Name": "user",
"Sharded": true
},
"Query": "select col from samecolvin where col = :col",
"FieldQuery": "select col from samecolvin where 1 != 1",
"Vindex": "vindex1",
"Values": [
":col"
],
"Table": "samecolvin"
}
}

0 comments on commit 9a6e7da

Please sign in to comment.