From 7ff698da2f9e6b2f9fe2cb1e2bbe29c1833caf32 Mon Sep 17 00:00:00 2001 From: Xiang Gu Date: Thu, 29 Jun 2023 16:08:52 -0400 Subject: [PATCH] sctest: Run backup/restore tests if exactly one database has schema changed We skip backup/restore tests in declarative schema changer if more than one databases have had schema changes, because we are doing database level backup. This should not change any existing test case but rather skip new ones (to be added in the next commit) like ``` create index idx on t (i); create database db; ``` Release note: None --- pkg/sql/schemachanger/sctest/framework.go | 66 ++++++++++++----------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/pkg/sql/schemachanger/sctest/framework.go b/pkg/sql/schemachanger/sctest/framework.go index a66f6ea4467f..cd8e5713bd88 100644 --- a/pkg/sql/schemachanger/sctest/framework.go +++ b/pkg/sql/schemachanger/sctest/framework.go @@ -753,40 +753,42 @@ func maybeGetDatabaseForIDs( t *testing.T, tdb *sqlutils.SQLRunner, ids catalog.DescriptorIDSet, ) (dbName string, exists bool) { const q = ` -SELECT - name -FROM - system.namespace -WHERE - id - IN ( - SELECT - DISTINCT - COALESCE( - d->'database'->>'id', - d->'schema'->>'parentId', - d->'type'->>'parentId', - d->'function'->>'parentId', - d->'table'->>'parentId' - )::INT8 - FROM - ( - SELECT - crdb_internal.pb_to_json('desc', descriptor) AS d - FROM - system.descriptor - WHERE - id IN (SELECT * FROM ROWS FROM (unnest($1::INT8[]))) - ) - ) -` - err := tdb.DB.QueryRowContext(context.Background(), q, pq.Array(ids.Ordered())).Scan(&dbName) - if errors.Is(err, gosql.ErrNoRows) { + SELECT + name + FROM + system.namespace + WHERE + id + IN ( + SELECT + DISTINCT + COALESCE( + d->'database'->>'id', + d->'schema'->>'parentId', + d->'type'->>'parentId', + d->'function'->>'parentId', + d->'table'->>'parentId' + )::INT8 + FROM + ( + SELECT + crdb_internal.pb_to_json('desc', descriptor) AS d + FROM + system.descriptor + WHERE + id IN (SELECT * FROM ROWS FROM (unnest($1::INT8[]))) + ) + ) + ` + results := tdb.QueryStr(t, q, pq.Array(ids.Ordered())) + if len(results) > 1 { + skip.IgnoreLintf(t, "requires all schema changes to happen within one database;"+ + " get %v: %v", len(results), results) + } + if len(results) == 0 { return "", false } - - require.NoError(t, err) - return dbName, true + return results[0][0], true } // withPostCommitPlanAfterSchemaChange