Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

release-21.1: sql: add CACHE clause to SHOW CREATE SEQUENCE when relevant #65805

Merged
merged 1 commit into from
May 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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