From f3cd9b6abf050b8e2519e8356f78cc18ce90f960 Mon Sep 17 00:00:00 2001 From: Andrew Werner Date: Tue, 13 Apr 2021 09:25:18 -0400 Subject: [PATCH] sql: add `CACHE` clause to `SHOW CREATE SEQUENCE` when relevant 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. --- pkg/sql/logictest/testdata/logic_test/sequences | 5 +++++ pkg/sql/show_create_clauses.go | 3 +++ pkg/sql/show_test.go | 8 ++++++++ 3 files changed, 16 insertions(+) diff --git a/pkg/sql/logictest/testdata/logic_test/sequences b/pkg/sql/logictest/testdata/logic_test/sequences index 0eb708968bcd..e027bd0fbdb6 100644 --- a/pkg/sql/logictest/testdata/logic_test/sequences +++ b/pkg/sql/logictest/testdata/logic_test/sequences @@ -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. diff --git a/pkg/sql/show_create_clauses.go b/pkg/sql/show_create_clauses.go index 4ccb7c3af45c..49b43f6e5373 100644 --- a/pkg/sql/show_create_clauses.go +++ b/pkg/sql/show_create_clauses.go @@ -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 } diff --git a/pkg/sql/show_test.go b/pkg/sql/show_test.go index 12e073df4cdf..a646e4a12fce 100644 --- a/pkg/sql/show_test.go +++ b/pkg/sql/show_test.go @@ -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) {