Skip to content

Commit

Permalink
sql: add CACHE clause to SHOW CREATE SEQUENCE when relevant
Browse files Browse the repository at this point in the history
In 21.1 we added support for `CACHE` to sequences but we didn't add the logic
to render that clause.

Release note (bug fix): Render `CACHE` clause for sequences which use a cache.
  • Loading branch information
ajwerner committed May 27, 2021
1 parent 8d76190 commit f3cd9b6
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 f3cd9b6

Please sign in to comment.