Skip to content

Commit

Permalink
Merge #78548 #78563
Browse files Browse the repository at this point in the history
78548: sql: populate semantic type of DOid correctly in some cases r=yuzefovich a=yuzefovich

This commit is a small step towards preserving the information of
a `DOid` during serialization / deserialization. Namely, we now preserve
the semantic type in some cases. There might be more cases where we want
to set a custom semantic type. Futhermore, `name` field is not preserved
at the moment.

Touches: #78547.

Release note: None

78563: sql/rowexec: make bulk row writer (materialized view/ctas) write-at-now r=dt a=dt

Release note: none.

Co-authored-by: Yahor Yuzefovich <[email protected]>
Co-authored-by: David Taylor <[email protected]>
  • Loading branch information
3 people committed Mar 27, 2022
3 parents d72bd93 + 5364692 + abeaf01 commit b9a6752
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 7 deletions.
2 changes: 1 addition & 1 deletion pkg/sql/colfetcher/cfetcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -1304,7 +1304,7 @@ func (cf *cFetcher) finalizeBatch() {
// Note that we don't need to update the memory accounting because
// oids are fixed length values and have already been accounted for
// when finalizing each row.
cf.machine.tableoidCol.Set(i, cf.table.da.NewDOid(tree.MakeDOid(tree.DInt(id))))
cf.machine.tableoidCol.Set(i, cf.table.da.NewDOid(tree.MakeDOid(tree.DInt(id), types.Oid)))
}
}
cf.machine.batch.SetLength(cf.machine.rowIdx)
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/rowenc/keyside/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func Decode(
} else {
rkey, i, err = encoding.DecodeVarintDescending(key)
}
return a.NewDOid(tree.MakeDOid(tree.DInt(i))), rkey, err
return a.NewDOid(tree.MakeDOid(tree.DInt(i), valType)), rkey, err
case types.EnumFamily:
var r []byte
if dir == encoding.Ascending {
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/rowenc/valueside/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ func DecodeUntaggedDatum(
return a.NewDJSON(tree.DJSON{JSON: j}), b, nil
case types.OidFamily:
b, data, err := encoding.DecodeUntaggedIntValue(buf)
return a.NewDOid(tree.MakeDOid(tree.DInt(data))), b, err
return a.NewDOid(tree.MakeDOid(tree.DInt(data), t)), b, err
case types.ArrayFamily:
// Skip the encoded data length.
b, _, _, err := encoding.DecodeNonsortingUvarint(buf)
Expand Down
2 changes: 1 addition & 1 deletion pkg/sql/rowenc/valueside/legacy.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ func UnmarshalLegacy(a *tree.DatumAlloc, typ *types.T, value roachpb.Value) (tre
if err != nil {
return nil, err
}
return a.NewDOid(tree.MakeDOid(tree.DInt(v))), nil
return a.NewDOid(tree.MakeDOid(tree.DInt(v), typ)), nil
case types.ArrayFamily:
v, err := value.GetBytes()
if err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/sql/rowexec/bulk_row_writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ func (sp *bulkRowWriter) ingestLoop(ctx context.Context, kvCh chan row.KVBatch)
// conflicting unique index entry would still be rejected as its value
// would point to a different owning row.
DisallowShadowingBelow: writeTS,
WriteAtBatchTimestamp: true,
},
)
if err != nil {
Expand Down
8 changes: 5 additions & 3 deletions pkg/sql/sem/tree/datum.go
Original file line number Diff line number Diff line change
Expand Up @@ -4845,13 +4845,15 @@ type DOid struct {
}

// MakeDOid is a helper routine to create a DOid initialized from a DInt.
func MakeDOid(d DInt) DOid {
return DOid{DInt: d, semanticType: types.Oid, name: ""}
func MakeDOid(d DInt, semanticType *types.T) DOid {
return DOid{DInt: d, semanticType: semanticType, name: ""}
}

// NewDOid is a helper routine to create a *DOid initialized from a DInt.
func NewDOid(d DInt) *DOid {
oid := MakeDOid(d)
// TODO(yuzefovich): audit the callers of NewDOid to see whether any want to
// create a DOid with a semantic type different from types.Oid.
oid := MakeDOid(d, types.Oid)
return &oid
}

Expand Down

0 comments on commit b9a6752

Please sign in to comment.