Skip to content

Commit

Permalink
Merge pull request #65805 from ajwerner/backport21.1-63548
Browse files Browse the repository at this point in the history
release-21.1: sql: add `CACHE` clause to `SHOW CREATE SEQUENCE` when relevant
  • Loading branch information
ajwerner authored May 30, 2021
2 parents 4837b15 + f3cd9b6 commit bdffce4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/sql/logictest/testdata/logic_test/sequences
Original file line number Diff line number Diff line change
Expand Up @@ -1485,6 +1485,11 @@ CREATE SEQUENCE cache_test CACHE 0
statement ok
CREATE SEQUENCE cache_test CACHE 10 INCREMENT 1

query TT
SHOW CREATE SEQUENCE cache_test
----
cache_test CREATE SEQUENCE public.cache_test MINVALUE 1 MAXVALUE 9223372036854775807 INCREMENT 1 START 1 CACHE 10

# Verify cache invalidation with schema changes.

# 10 values (1,2,...,10) are cached, and the underlying sequence is incremented to 10.
Expand Down
3 changes: 3 additions & 0 deletions pkg/sql/show_create_clauses.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ func ShowCreateSequence(
if opts.Virtual {
f.Printf(" VIRTUAL")
}
if opts.CacheSize > 1 {
f.Printf(" CACHE %d", opts.CacheSize)
}
return f.CloseAndGetString(), nil
}

Expand Down
8 changes: 8 additions & 0 deletions pkg/sql/show_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,14 @@ func TestShowCreateSequence(t *testing.T) {
`CREATE SEQUENCE %s INCREMENT 5 MAXVALUE 10000 START 10 MINVALUE 0`,
`CREATE SEQUENCE public.%s MINVALUE 0 MAXVALUE 10000 INCREMENT 5 START 10`,
},
{
`CREATE SEQUENCE %s INCREMENT 5 MAXVALUE 10000 START 10 MINVALUE 0 CACHE 1`,
`CREATE SEQUENCE public.%s MINVALUE 0 MAXVALUE 10000 INCREMENT 5 START 10`,
},
{
`CREATE SEQUENCE %s INCREMENT 5 MAXVALUE 10000 START 10 MINVALUE 0 CACHE 10`,
`CREATE SEQUENCE public.%s MINVALUE 0 MAXVALUE 10000 INCREMENT 5 START 10 CACHE 10`,
},
}
for i, test := range tests {
t.Run(fmt.Sprint(i), func(t *testing.T) {
Expand Down

0 comments on commit bdffce4

Please sign in to comment.