Skip to content

Commit

Permalink
In dolt diff, short-circuit computing a unified schema unless the s…
Browse files Browse the repository at this point in the history
…chema has changed, avoid comparing two `sql.Type`s directly, since some implementations are not comparable.
  • Loading branch information
nicktobey committed Nov 4, 2024
1 parent 6a2ee9f commit 43196c0
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions go/cmd/dolt/commands/diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -1401,7 +1401,12 @@ func diffRows(
toSch = pkSch.Schema
}

unionSch := unionSchemas(fromSch, toSch)
var unionSch sql.Schema
if fromSch.Equals(toSch) {
unionSch = fromSch
} else {
unionSch = unionSchemas(fromSch, toSch)
}

// We always instantiate a RowWriter in case the diffWriter needs it to close off any work from schema output
rowWriter, err := dw.RowWriter(fromTableInfo, toTableInfo, tableSummary, unionSch)
Expand Down Expand Up @@ -1561,13 +1566,13 @@ func unionSchemas(s1 sql.Schema, s2 sql.Schema) sql.Schema {
//
// Note this is only for printing the diff. This is not robust for other purposes.
func chooseMostFlexibleType(origA, origB sql.Type) sql.Type {
if origA == origB {
return origA
}

at := origA.Type()
bt := origB.Type()

if at == bt {
return origA
}

// If both are numbers, we'll take the float.
if sqltypes.IsIntegral(at) && sqltypes.IsFloat(bt) {
return origB
Expand Down

0 comments on commit 43196c0

Please sign in to comment.