Skip to content

Commit

Permalink
Merge pull request #49238 from rohany/backport20.1-47728-49234
Browse files Browse the repository at this point in the history
Backport20.1 47728 49234
  • Loading branch information
rohany authored May 19, 2020
2 parents c80790d + 8eafc91 commit 6123c0c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 deletions.
19 changes: 19 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/orms
Original file line number Diff line number Diff line change
Expand Up @@ -247,3 +247,22 @@ WHERE
AND attname = 'a';
----
a 57 true false false

# Regression test for windower not using EncDatum.Fingerprint.
statement ok
SELECT
array_agg(t_pk.table_name ORDER BY t_pk.table_name)
FROM
information_schema.statistics AS i
LEFT JOIN (
SELECT
array_agg(c.column_name) AS table_primary_key_columns,
c.table_name
FROM
information_schema.columns AS c
GROUP BY
c.table_name
)
AS t_pk ON i.table_name = t_pk.table_name
GROUP BY
t_pk.table_primary_key_columns
3 changes: 1 addition & 2 deletions pkg/sql/rowexec/windower.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (

"github.com/cockroachdb/cockroach/pkg/sql/execinfra"
"github.com/cockroachdb/cockroach/pkg/sql/execinfrapb"
"github.com/cockroachdb/cockroach/pkg/sql/flowinfra"
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode"
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgerror"
"github.com/cockroachdb/cockroach/pkg/sql/rowcontainer"
Expand Down Expand Up @@ -677,7 +676,7 @@ func (w *windower) computeWindowFunctions(ctx context.Context, evalCtx *tree.Eva
"hash column %d, row with only %d columns", errors.Safe(col), errors.Safe(len(row)))
}
var err error
w.scratch, err = row[int(col)].Encode(&w.inputTypes[int(col)], &w.datumAlloc, flowinfra.PreferredEncoding, w.scratch)
w.scratch, err = row[int(col)].Fingerprint(&w.inputTypes[int(col)], &w.datumAlloc, w.scratch)
if err != nil {
return err
}
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 6123c0c

Please sign in to comment.