Skip to content

Commit

Permalink
Merge #47728
Browse files Browse the repository at this point in the history
47728: sqlbase: avoid decode/encode in Fingerprint r=jordanlewis a=jordanlewis

The Fingerprint method introduced in
b08d8f4 added an unnecessary
decode/encode cycle that didn't exist before, if the input Datum was
already in ASCENDING_KEY encoding.

This commit restores the original behavior.

We should probably backport this to release-20.1.

Release note: None

Co-authored-by: Jordan Lewis <jordanthelewis@gmail.com>
  • Loading branch information
craig[bot] and jordanlewis committed Apr 21, 2020
2 parents ede462e + e963949 commit 5ad50d8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 0 additions & 2 deletions pkg/cmd/roachtest/alterpk.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,6 @@ func registerAlterPK(r *testRegistry) {
},
})
r.Add(testSpec{
// TODO(yuzefovich): investigate #47598 and unskip this configuration.
Skip: "#47598",
Name: "alterpk-tpcc-500",
Owner: OwnerSQLSchema,
// Use a 4 node cluster -- 3 nodes will run cockroach, and the last will be the
Expand Down
12 changes: 9 additions & 3 deletions pkg/sql/sqlbase/encoded_datum.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,15 +279,21 @@ func (ed *EncDatum) Encode(
// fingerprints of a set of datums are appended together, the resulting
// fingerprint will uniquely identify the set.
func (ed *EncDatum) Fingerprint(typ *types.T, a *DatumAlloc, appendTo []byte) ([]byte, error) {
if err := ed.EnsureDecoded(typ, a); err != nil {
return nil, err
}
// Note: we don't ed.EnsureDecoded on top of this method, because the default
// case uses ed.Encode, which has a fast path if the encoded bytes are already
// the right encoding.
switch typ.Family() {
case types.JsonFamily:
if err := ed.EnsureDecoded(typ, a); err != nil {
return nil, err
}
// We must use value encodings without a column ID even if the EncDatum already
// is encoded with the value encoding so that the hashes are indeed unique.
return EncodeTableValue(appendTo, ColumnID(encoding.NoColumnID), ed.Datum, a.scratch)
case types.ArrayFamily:
if err := ed.EnsureDecoded(typ, a); err != nil {
return nil, err
}
// Arrays may contain composite data, so we cannot just value
// encode an array (that would give same-valued composite
// datums a different encoding).
Expand Down

0 comments on commit 5ad50d8

Please sign in to comment.