Skip to content

Commit 811f49f

Browse files
committed
sql: remove redundant DOidWrapper checks
We had many `tree.AsD*` functions which checked whether the given datum was a DOidWrapper around another datum. Given that we now only support oid-wrapping on top of `DString` and `DCollatedString`, most of these functions are redundant and were only introduced due to blind copy-paste. This commit removes most of them, replacing with an explicit type cast. Release note: None
1 parent 3a92631 commit 811f49f

File tree

17 files changed

+93
-423
lines changed

17 files changed

+93
-423
lines changed

pkg/ccl/changefeedccl/event_processing.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -825,7 +825,7 @@ func readOneJSONValue(row cdcevent.Row, colName string) (*tree.DJSON, error) {
825825
if d == tree.DNull {
826826
return nil
827827
}
828-
if valJSON, ok = tree.AsDJSON(d); !ok {
828+
if valJSON, ok = d.(*tree.DJSON); !ok {
829829
return errors.Newf("expected a JSON object, got %s", d.ResolvedType())
830830
}
831831
return nil

pkg/crosscluster/logical/sql_row_reader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func (r *sqlRowReader) ReadRows(
128128
isLocal = true
129129
}
130130

131-
decimal, ok := tree.AsDDecimal(timestamp)
131+
decimal, ok := timestamp.(*tree.DDecimal)
132132
if !ok {
133133
return nil, errors.AssertionFailedf("expected column 1 or 2 to be origin timestamp")
134134
}

pkg/multitenant/mtinfo/info.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,11 @@ func GetTenantInfoFromSQLRow(
5353
if len(row) < 2 || row[1] == tree.DNull {
5454
return tid, nil, errors.AssertionFailedf("%v: missing data in info column", tid)
5555
}
56-
ival, ok := tree.AsDBytes(row[1])
56+
ival, ok := row[1].(*tree.DBytes)
5757
if !ok {
5858
return tid, nil, errors.AssertionFailedf("%v: info: expected bytes, got %T", tid, row[1])
5959
}
60-
infoBytes := []byte(ival)
60+
infoBytes := []byte(*ival)
6161
if err := protoutil.Unmarshal(infoBytes, &info.ProtoInfo); err != nil {
6262
return tid, nil, errors.NewAssertionErrorWithWrappedErrf(err, "%v: decoding info column", tid)
6363
}

pkg/sql/backfill/backfill.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -522,7 +522,7 @@ func (vih *VectorIndexHelper) ReEncodeVector(
522522
}
523523
key.PartitionKey = cspann.PartitionKey(tree.MustBeDInt(searcher.PartitionKey()))
524524
key.Level = cspann.LeafLevel
525-
quantizedVector, ok := tree.AsDBytes(searcher.EncodedVector())
525+
quantizedVector, ok := searcher.EncodedVector().(*tree.DBytes)
526526
if !ok {
527527
return &rowenc.IndexEntry{}, errors.AssertionFailedf("expected encoded vector to be of type DBytes")
528528
}

pkg/sql/colexec/colbuilder/execplan.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2229,7 +2229,7 @@ func planSelectionOperators(
22292229
}
22302230
case treecmp.In, treecmp.NotIn:
22312231
negate := cmpOp.Symbol == treecmp.NotIn
2232-
datumTuple, ok := tree.AsDTuple(constArg)
2232+
datumTuple, ok := constArg.(*tree.DTuple)
22332233
if !ok || useDefaultCmpOpForIn(datumTuple) {
22342234
break
22352235
}
@@ -2882,7 +2882,7 @@ func planProjectionExpr(
28822882
}
28832883
case treecmp.In, treecmp.NotIn:
28842884
negate := cmpProjOp.Symbol == treecmp.NotIn
2885-
datumTuple, ok := tree.AsDTuple(rConstArg)
2885+
datumTuple, ok := rConstArg.(*tree.DTuple)
28862886
if !ok || useDefaultCmpOpForIn(datumTuple) {
28872887
break
28882888
}

pkg/sql/crdb_internal.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7961,8 +7961,8 @@ CREATE TABLE crdb_internal.cluster_locks (
79617961
},
79627962
{
79637963
populate: genPopulateClusterLocksWithIndex("contended" /* idxColumnName */, func(filters *clusterLocksFilters, idxConstraint tree.Datum) {
7964-
if contended, ok := tree.AsDBool(idxConstraint); ok {
7965-
filters.contended = (*bool)(&contended)
7964+
if contended, ok := idxConstraint.(*tree.DBool); ok {
7965+
filters.contended = (*bool)(contended)
79667966
}
79677967
}),
79687968
},

pkg/sql/opt/norm/fold_constants_funcs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,7 @@ func (c *CustomFuncs) foldOIDFamilyCast(
338338
if err != nil {
339339
return nil, false, err
340340
}
341-
oid, ok := tree.AsDOid(cDatum)
341+
oid, ok := cDatum.(*tree.DOid)
342342
if !ok {
343343
return nil, false, nil
344344
}

pkg/sql/paramparse/paramparse.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,15 @@ func DatumAsBool(
138138
if err != nil {
139139
return false, err
140140
}
141-
b, ok := tree.AsDBool(val)
141+
b, ok := val.(*tree.DBool)
142142
if !ok {
143143
err = pgerror.Newf(pgcode.InvalidParameterValue,
144144
"parameter %q requires a Boolean value", name)
145145
err = errors.WithDetailf(err,
146146
"%s is a %s", value, errors.Safe(val.ResolvedType()))
147147
return false, err
148148
}
149-
return bool(b), nil
149+
return bool(*b), nil
150150
}
151151

152152
// GetSingleBool returns the boolean if the input Datum is a DBool,

pkg/sql/routine.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func (d *callNode) startExec(params runParams) error {
6262
if res == tree.DNull {
6363
return pgerror.New(pgcode.Internal, "procedure returned null record")
6464
}
65-
tuple, ok := tree.AsDTuple(res)
65+
tuple, ok := res.(*tree.DTuple)
6666
if !ok {
6767
return errors.AssertionFailedf("expected a tuple, got %T", res)
6868
}

pkg/sql/rowenc/index_encoding.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1651,7 +1651,7 @@ func encodeSecondaryIndexNoFamilies(
16511651
// Vector index values begin with the quantized and encoded vector. It is
16521652
// possible that it is not supplied here (e.g. for an index delete).
16531653
if encVector := vh.QuantizedVecs[index.GetID()]; encVector != nil {
1654-
encVectorBytes, ok := tree.AsDBytes(encVector)
1654+
encVectorBytes, ok := encVector.(*tree.DBytes)
16551655
if !ok {
16561656
return IndexEntry{}, errors.AssertionFailedf(
16571657
"unexpected type for vector index value: %T", encVector)

0 commit comments

Comments
 (0)