Skip to content

Commit

Permalink
Correct PK handling
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <mattalord@gmail.com>
  • Loading branch information
mattlord committed May 13, 2024
1 parent 194b84c commit efd373f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions go/vt/vttablet/tabletserver/schema/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -702,15 +702,16 @@ func (se *Engine) GetTableForPos(ctx context.Context, tableName sqlparser.Identi
return nil, err
}
defer conn.Recycle()
cst := *st // Make a copy
cst := *st // Make a copy
cst.Fields = nil // We're going to refresh the columns/fields
if err := fetchColumns(&cst, conn, se.cp.DBName(), tableNameStr); err != nil {
return nil, err
}
// Update the PK columns for the table as well as that may have changed.
// Update the PK columns for the table as well as they may have changed.
cst.PKColumns = nil // We're going to repopulate the PK columns
if err := se.populatePrimaryKeys(ctx, conn.Conn, map[string]*Table{tableNameStr: &cst}); err != nil {
return nil, err
}
log.Errorf("DEBUG: updating cache entry for table %v, pk column(s): %v", tableNameStr, cst.PKColumns)
se.tables[tableNameStr] = &cst
return newMinimalTable(&cst), nil
}
Expand Down
4 changes: 2 additions & 2 deletions go/vt/vttablet/tabletserver/schema/engine_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1422,8 +1422,8 @@ func TestGetTableForPos(t *testing.T) {
name: "GetTableForPos with cache initialized, table found",
initialCacheState: map[string]*Table{table.String(): {Name: table}},
expectedQueriesFunc: func(db *fakesqldb.DB) {
// We only reload the columns for the table in our cache. A new column called
// col2 has been added to the table schema and it is the new PK.
// We only reload the column and PK info for the table in our cache. A new column
// called col2 has been added to the table schema and it is the new PK.
newTableSchema := "create table t1 (id int, col2 varchar, primary key(col2))"
db.AddQuery(mysql.BaseShowPrimary, &sqltypes.Result{
Fields: mysql.ShowPrimaryFields,
Expand Down

0 comments on commit efd373f

Please sign in to comment.