Skip to content

sql/types: remove VisibleType field from InternalType proto #152629

@rafiss

Description

@rafiss

In #148694, we removed the downgradeType function, which was invoked during protobuf serialization of types.T objects. This function was initially created to preserve compatibility with our pre-19.1 type formats in a mixed version setting. This removal was done during the 25.4 development cycle. There's a corresponding upgradeType function that is invoked during deserialization.

Due to the way that upgradeType and downgradeType had been implemented previously (i.e. in pre-19.1 versions), we needed to keep the VisibleType field of the protobuf, even though that is part of the legacy format. The reason is that in versions 25.3 (and earlier) upgradeType will look at the VisibleType and use that to overwrite the Oid field:

case StringFamily, CollatedStringFamily:
// Map string-related visible types to corresponding Oid values.
if t.Oid() == oidext.T_citext {
// CITEXT is already an "upgraded" type, so we can skip the
// VisibleType -> Oid mapping as it would overwrite the OID.
break
}
switch t.InternalType.VisibleType {
case visibleVARCHAR:
t.InternalType.Oid = oid.T_varchar
case visibleCHAR:
t.InternalType.Oid = oid.T_bpchar
case visibleQCHAR:
t.InternalType.Oid = oid.T_char
case visibleNONE:
t.InternalType.Oid = oid.T_text
default:
return errors.AssertionFailedf("unexpected visible type: %d", t.InternalType.VisibleType)
}

In v25.4 we've added logic to avoid overwriting the OID if it's already present. Here's the same section of the code in 25.4:

case StringFamily, CollatedStringFamily:
// If the OID is not set, map string-related visible types to corresponding
// Oid values.
if t.InternalType.Oid == 0 {
switch t.InternalType.VisibleType {
case visibleVARCHAR:
t.InternalType.Oid = oid.T_varchar
case visibleCHAR:
t.InternalType.Oid = oid.T_bpchar
case visibleQCHAR:
t.InternalType.Oid = oid.T_char
case visibleNONE:
t.InternalType.Oid = oid.T_text
default:
return errors.AssertionFailedf("unexpected visible type: %d", t.InternalType.VisibleType)
}
}

If the cluster is in a mixed version state and has both v25.4 and v25.3 nodes, then we need to make sure VisibleType is still present -- otherwise the correct OID will get clobbered during deserialization.

Once we no longer need compatibility with 25.3 or earlier, we can safely remove VisibleType entirely. We may be able to remove upgradeType as well.

update: we re-added some of downgradeType in v25.4 (#154363), but it should still be safe to remove after the v25.4 upgrade.

Jira issue: CRDB-53950

Epic CRDB-58150

Metadata

Metadata

Assignees

Labels

A-sql-datatypesSQL column types usable in table descriptors.C-cleanupTech debt, refactors, loose ends, etc. Solution not expected to significantly change behavior.C-enhancementSolution expected to add code/behavior + preserve backward-compat (pg compat issues are exception)T-sql-foundationsSQL Foundations Team (formerly SQL Schema + SQL Sessions)target-release-26.2.0v26.2.0-prerelease

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions