Skip to content

Commit

Permalink
does not allow unknown tables to be passed in flush statements
Browse files Browse the repository at this point in the history
Signed-off-by: GuptaManan100 <[email protected]>
  • Loading branch information
GuptaManan100 committed Jan 7, 2021
1 parent a3a3a60 commit e51e3d5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 16 deletions.
22 changes: 6 additions & 16 deletions go/vt/vtgate/planbuilder/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,24 +256,14 @@ func buildFlushTables(stmt *sqlparser.Flush, vschema ContextVSchema) (engine.Pri
table, _, _, _, destinationTab, err = vschema.FindTableOrVindex(tab)

if err != nil {
_, isNotFound := err.(vindexes.NotFoundError)
if !isNotFound {
return nil, err
}
return nil, err
}
if table == nil {
destinationTab, keyspaceTab, _, err = vschema.TargetDestination(tab.Qualifier.String())
if err != nil {
return nil, err
}
stmt.TableNames[i] = sqlparser.TableName{
Name: tab.Name,
}
} else {
keyspaceTab = table.Keyspace
stmt.TableNames[i] = sqlparser.TableName{
Name: table.Name,
}
return nil, vindexes.NotFoundError{TableName: tab.Name.String()}
}
keyspaceTab = table.Keyspace
stmt.TableNames[i] = sqlparser.TableName{
Name: table.Name,
}
if destinationTab == nil {
destinationTab = key.DestinationAllShards{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,25 @@
]
}
}

# Incorrect tables in flush
"flush tables user.a with read lock"
"table a not found"

# Unknown tables in unsharded keyspaces are allowed
"flush tables main.a with read lock"
{
"QueryType": "FLUSH",
"Original": "flush tables main.a with read lock",
"Instructions": {
"OperatorType": "Send",
"Keyspace": {
"Name": "main",
"Sharded": false
},
"TargetDestination": "AllShards()",
"IsDML": false,
"Query": "flush tables a with read lock",
"SingleShardOnly": false
}
}

0 comments on commit e51e3d5

Please sign in to comment.