Skip to content

Commit e300eaf

Browse files
committed
tree: include gist into enum comparison assertion
In theory, the plan gist should already be included in all assertion failures, but it doesn't happen in practice. Let's include it explicitly (if it is present in the context) into the enum mismatched version comparison error to help with tracking it down. Release note: None
1 parent 59dedfe commit e300eaf

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

pkg/sql/conn_executor.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4854,4 +4854,5 @@ func init() {
48544854
logcrash.RegisterTagFn("gist", func(ctx context.Context) string {
48554855
return planGistFromCtx(ctx)
48564856
})
4857+
tree.PlanGistFromCtx = planGistFromCtx
48574858
}

pkg/sql/sem/tree/datum.go

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5474,6 +5474,10 @@ func (d *DEnum) ResolvedType() *types.T {
54745474
return d.EnumTyp
54755475
}
54765476

5477+
// PlanCistFromCtx returns the plan gist if it is stored in the context. It is
5478+
// injected from the sql package to avoid import cycle.
5479+
var PlanGistFromCtx func(context.Context) string
5480+
54775481
// Compare implements the Datum interface.
54785482
func (d *DEnum) Compare(ctx context.Context, cmpCtx CompareContext, other Datum) (int, error) {
54795483
if other == DNull {
@@ -5491,10 +5495,16 @@ func (d *DEnum) Compare(ctx context.Context, cmpCtx CompareContext, other Datum)
54915495

54925496
// We should never be comparing two different versions of the same enum.
54935497
if v.EnumTyp.TypeMeta.Version != d.EnumTyp.TypeMeta.Version {
5498+
var gist redact.SafeString
5499+
if PlanGistFromCtx != nil {
5500+
// Plan gist, by construction, doesn't contain any PII, so it's a
5501+
// safe string.
5502+
gist = redact.SafeString(PlanGistFromCtx(ctx))
5503+
}
54945504
panic(errors.AssertionFailedf(
5495-
"comparison of two different versions of enum %s oid %d: versions %d and %d",
5505+
"comparison of two different versions of enum %s oid %d: versions %d and %d, gist %q",
54965506
d.EnumTyp.SQLStringForError(), errors.Safe(d.EnumTyp.Oid()), d.EnumTyp.TypeMeta.Version,
5497-
v.EnumTyp.TypeMeta.Version,
5507+
v.EnumTyp.TypeMeta.Version, gist,
54985508
))
54995509
}
55005510

0 commit comments

Comments
 (0)