Skip to content

Commit

Permalink
distsql: don't use VALUE encodings in HashJoiner
Browse files Browse the repository at this point in the history
It looks like the VALUE encodings are not unique (they contain a column ID) so
they shouldn't be used for equality testing in hash joins.
  • Loading branch information
RaduBerinde committed Dec 7, 2016
1 parent 266c027 commit d45ad26
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion pkg/sql/distsql/hashjoiner.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,12 @@ func (h *hashJoiner) encode(
if row[colIdx].IsNull() {
return nil, true, nil
}
appendTo, err = row[colIdx].Encode(&h.datumAlloc, sqlbase.DatumEncoding_VALUE, appendTo)
// Note: we cannot compare VALUE encodings because they contain column IDs
// which can vary.
// TODO(radu): we should figure out what encoding is readily available and
// use that (though it needs to be consistent across all rows). We could add
// functionality to compare VALUE encodings ignoring the column ID.
appendTo, err = row[colIdx].Encode(&h.datumAlloc, sqlbase.DatumEncoding_ASCENDING_KEY, appendTo)
if err != nil {
return appendTo, false, err
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/sql/sqlbase/encoded_datum.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,8 @@ func (ed *EncDatum) Encoding() (DatumEncoding, bool) {

// Encode appends the encoded datum to the given slice using the requested
// encoding.
// Note: DatumEncoding_VALUE encodings are not unique because they can contain
// a column ID so they should not be used to test for equality.
func (ed *EncDatum) Encode(a *DatumAlloc, enc DatumEncoding, appendTo []byte) ([]byte, error) {
if ed.encoded != nil && enc == ed.encoding {
// We already have an encoding that matches
Expand Down

0 comments on commit d45ad26

Please sign in to comment.