From 3c20609515810095874d1f3bbdffa5eb1fa21dd8 Mon Sep 17 00:00:00 2001 From: adityamaru Date: Tue, 6 Dec 2022 12:48:38 -0500 Subject: [PATCH] release-22.1: backupccl: elide expensive ShowCreate call in SHOW BACKUP Backport 1/1 commits from #88293. /cc @cockroachdb/release In #88376 we see the call to ShowCreate taking ~all the time on a cluster with 2.5K empty tables. In all cases except SHOW BACKUP SCHEMAS we do not need to construct the SQL representation of the table's schema. This results in a marked improvement in the performance of SHOW BACKUP as can be seen in #88376 (comment). Fixes: #88376 Release note (performance improvement): SHOW BACKUP on a backup containing several table descriptors is now more performant Release justification: low risk performance improvement required for the use of schedules in CockroachCloud --- pkg/ccl/backupccl/show.go | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/pkg/ccl/backupccl/show.go b/pkg/ccl/backupccl/show.go index be924f88bc4d..c54bcb263233 100644 --- a/pkg/ccl/backupccl/show.go +++ b/pkg/ccl/backupccl/show.go @@ -578,18 +578,23 @@ func backupShowerDefault( dataSizeDatum = tree.NewDInt(tree.DInt(tableSize.DataSize)) rowCountDatum = tree.NewDInt(tree.DInt(tableSize.Rows)) - displayOptions := sql.ShowCreateDisplayOptions{ - FKDisplayMode: sql.OmitMissingFKClausesFromCreate, - IgnoreComments: true, + // Only resolve the table schemas if running `SHOW BACKUP SCHEMAS`. + // In all other cases we discard these results and so it is wasteful + // to construct the SQL representation of the table's schema. + if showSchemas { + displayOptions := sql.ShowCreateDisplayOptions{ + FKDisplayMode: sql.OmitMissingFKClausesFromCreate, + IgnoreComments: true, + } + createStmt, err := p.ShowCreate(ctx, dbName, manifest.Descriptors, + tabledesc.NewBuilder(desc.TableDesc()).BuildImmutableTable(), displayOptions) + if err != nil { + // We expect that we might get an error here due to X-DB + // references, which were possible on 20.2 betas and rcs. + log.Errorf(ctx, "error while generating create statement: %+v", err) + } + createStmtDatum = nullIfEmpty(createStmt) } - createStmt, err := p.ShowCreate(ctx, dbName, manifest.Descriptors, - tabledesc.NewBuilder(desc.TableDesc()).BuildImmutableTable(), displayOptions) - if err != nil { - // We expect that we might get an error here due to X-DB - // references, which were possible on 20.2 betas and rcs. - log.Errorf(ctx, "error while generating create statement: %+v", err) - } - createStmtDatum = nullIfEmpty(createStmt) default: descriptorType = "unknown" }