Skip to content

Commit

Permalink
*: DATA RACE in the temptable.AttachLocalTemporaryTableInfoSchema (#3…
Browse files Browse the repository at this point in the history
  • Loading branch information
hawkingrei authored Sep 29, 2022
1 parent 14d085b commit 52099eb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
5 changes: 3 additions & 2 deletions infoschema/infoschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -623,8 +623,9 @@ func (is *SessionTables) schemaTables(schema model.CIStr) *schemaTables {
// So when a database is dropped, its temporary tables still exist and can be returned by TableByName/TableByID.
type SessionExtendedInfoSchema struct {
InfoSchema
LocalTemporaryTables *SessionTables
MdlTables *SessionTables
LocalTemporaryTablesOnce sync.Once
LocalTemporaryTables *SessionTables
MdlTables *SessionTables
}

// TableByName implements InfoSchema.TableByName
Expand Down
8 changes: 5 additions & 3 deletions table/temptable/infoschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ func AttachLocalTemporaryTableInfoSchema(sctx sessionctx.Context, is infoschema.
return is
}
if se, ok := is.(*infoschema.SessionExtendedInfoSchema); ok {
se.LocalTemporaryTables = localTemporaryTables
se.LocalTemporaryTablesOnce.Do(func() {
se.LocalTemporaryTables = localTemporaryTables
})
return is
}

Expand All @@ -39,9 +41,9 @@ func AttachLocalTemporaryTableInfoSchema(sctx sessionctx.Context, is infoschema.
// DetachLocalTemporaryTableInfoSchema detach local temporary table information schema from is
func DetachLocalTemporaryTableInfoSchema(is infoschema.InfoSchema) infoschema.InfoSchema {
if attachedInfoSchema, ok := is.(*infoschema.SessionExtendedInfoSchema); ok {
newIs := *attachedInfoSchema
newIs := attachedInfoSchema
newIs.LocalTemporaryTables = nil
return &newIs
return newIs
}

return is
Expand Down

0 comments on commit 52099eb

Please sign in to comment.