Skip to content

Commit d806e45

Browse files
committed
backupccl: add WITH SKIP SIZE option to SHOW BACKUP
Computing the sizes requires reading more metadata, which can be skipped if the sizes are not required. Release note: none. Epic: none.
1 parent 1e40fd2 commit d806e45

File tree

6 files changed

+38
-8
lines changed

6 files changed

+38
-8
lines changed

docs/generated/sql/bnf/stmt_block.bnf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3238,6 +3238,7 @@ var_list ::=
32383238
show_backup_options ::=
32393239
'AS_JSON'
32403240
| 'CHECK_FILES'
3241+
| 'SKIP' 'SIZE'
32413242
| 'DEBUG_IDS'
32423243
| 'INCREMENTAL_LOCATION' '=' string_or_placeholder_opt_list
32433244
| 'KMS' '=' string_or_placeholder_opt_list

pkg/ccl/backupccl/show.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import (
4444
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgnotice"
4545
"github.com/cockroachdb/cockroach/pkg/sql/protoreflect"
4646
"github.com/cockroachdb/cockroach/pkg/sql/sem/catconstants"
47+
"github.com/cockroachdb/cockroach/pkg/sql/sem/catid"
4748
"github.com/cockroachdb/cockroach/pkg/sql/sem/tree"
4849
"github.com/cockroachdb/cockroach/pkg/sql/types"
4950
"github.com/cockroachdb/cockroach/pkg/util/hlc"
@@ -830,10 +831,14 @@ func backupShowerDefault(
830831
fileSizes = info.fileSizes[layer]
831832
}
832833

833-
tableSizes, err := getTableSizes(ctx, info.layerToIterFactory[layer], fileSizes)
834-
if err != nil {
835-
return nil, err
834+
var tableSizes map[catid.DescID]descriptorSize
835+
if !opts.SkipSize {
836+
tableSizes, err = getTableSizes(ctx, info.layerToIterFactory[layer], fileSizes)
837+
if err != nil {
838+
return nil, err
839+
}
836840
}
841+
837842
backupType := tree.NewDString("full")
838843
if manifest.IsIncremental() {
839844
backupType = tree.NewDString("incremental")

pkg/ccl/backupccl/testdata/backup-restore/show_backup

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,16 @@ true
1616
link-backup cluster=s1 src-path=show_backup_validate,valid-22.2 dest-path=valid-22.2
1717
----
1818

19+
query-sql
20+
SELECT sum(size_bytes) FROM [SHOW BACKUP 'valid-22.2' IN 'nodelocal://1/'];
21+
----
22+
1120
23+
24+
query-sql
25+
SELECT sum(size_bytes) FROM [SHOW BACKUP 'valid-22.2' IN 'nodelocal://1/' WITH skip size];
26+
----
27+
0
28+
1929
# This backup is completely valid, but has no jobs.
2030
query-sql regex=No\sproblems\sfound!
2131
SELECT * FROM [SHOW BACKUP VALIDATE FROM 'valid-22.2' IN 'nodelocal://1/'];

pkg/sql/parser/sql.y

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7635,6 +7635,10 @@ show_backup_options:
76357635
{
76367636
$$.val = &tree.ShowBackupOptions{CheckFiles: true}
76377637
}
7638+
| SKIP SIZE
7639+
{
7640+
$$.val = &tree.ShowBackupOptions{SkipSize: true}
7641+
}
76387642
| DEBUG_IDS
76397643
{
76407644
$$.val = &tree.ShowBackupOptions{DebugIDs: true}

pkg/sql/parser/testdata/backup_restore

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,12 +112,12 @@ SHOW BACKUP 'bar' WITH check_files, encryption_passphrase = '*****' -- identifie
112112
SHOW BACKUP 'bar' WITH check_files, encryption_passphrase = 'secret' -- passwords exposed
113113

114114
parse
115-
SHOW BACKUP FROM LATEST IN 'bar' WITH incremental_location = 'baz'
115+
SHOW BACKUP FROM LATEST IN 'bar' WITH incremental_location = 'baz', skip size
116116
----
117-
SHOW BACKUP FROM 'latest' IN 'bar' WITH incremental_location = 'baz' -- normalized!
118-
SHOW BACKUP FROM ('latest') IN ('bar') WITH incremental_location = ('baz') -- fully parenthesized
119-
SHOW BACKUP FROM '_' IN '_' WITH incremental_location = '_' -- literals removed
120-
SHOW BACKUP FROM 'latest' IN 'bar' WITH incremental_location = 'baz' -- identifiers removed
117+
SHOW BACKUP FROM 'latest' IN 'bar' WITH incremental_location = 'baz', skip size -- normalized!
118+
SHOW BACKUP FROM ('latest') IN ('bar') WITH incremental_location = ('baz'), skip size -- fully parenthesized
119+
SHOW BACKUP FROM '_' IN '_' WITH incremental_location = '_', skip size -- literals removed
120+
SHOW BACKUP FROM 'latest' IN 'bar' WITH incremental_location = 'baz', skip size -- identifiers removed
121121

122122
parse
123123
SHOW BACKUP FROM LATEST IN ('bar','bar1') WITH KMS = ('foo', 'bar'), incremental_location=('hi','hello')

pkg/sql/sem/tree/show.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ type ShowBackupOptions struct {
152152
DecryptionKMSURI StringOrPlaceholderOptList
153153
EncryptionPassphrase Expr
154154
Privileges bool
155+
SkipSize bool
155156

156157
// EncryptionInfoDir is a hidden option used when the user wants to run the deprecated
157158
//
@@ -221,6 +222,10 @@ func (o *ShowBackupOptions) Format(ctx *FmtCtx) {
221222
ctx.WriteString("kms = ")
222223
ctx.FormatNode(&o.DecryptionKMSURI)
223224
}
225+
if o.SkipSize {
226+
maybeAddSep()
227+
ctx.WriteString("skip size")
228+
}
224229
if o.DebugMetadataSST {
225230
maybeAddSep()
226231
ctx.WriteString("debug_dump_metadata_sst")
@@ -253,6 +258,7 @@ func (o ShowBackupOptions) IsDefault() bool {
253258
cmp.Equal(o.DecryptionKMSURI, options.DecryptionKMSURI) &&
254259
o.EncryptionPassphrase == options.EncryptionPassphrase &&
255260
o.Privileges == options.Privileges &&
261+
o.SkipSize == options.SkipSize &&
256262
o.DebugMetadataSST == options.DebugMetadataSST &&
257263
o.EncryptionInfoDir == options.EncryptionInfoDir &&
258264
o.CheckConnectionTransferSize == options.CheckConnectionTransferSize &&
@@ -322,6 +328,10 @@ func (o *ShowBackupOptions) CombineWith(other *ShowBackupOptions) error {
322328
if err != nil {
323329
return err
324330
}
331+
o.SkipSize, err = combineBools(o.SkipSize, other.SkipSize, "skip size")
332+
if err != nil {
333+
return err
334+
}
325335
o.DebugMetadataSST, err = combineBools(o.DebugMetadataSST, other.DebugMetadataSST,
326336
"debug_dump_metadata_sst")
327337
if err != nil {

0 commit comments

Comments
 (0)