From e2a1c6ba75df2cec294c791f03f9ba7a24c595e5 Mon Sep 17 00:00:00 2001 From: Andrew Werner Date: Tue, 19 Apr 2022 21:34:27 -0400 Subject: [PATCH 1/2] sql: add a benchmark for large DROP DATABASE statements Release note: None --- pkg/sql/drop_test.go | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/pkg/sql/drop_test.go b/pkg/sql/drop_test.go index 6c3b6a2d938b..95429c46e56b 100644 --- a/pkg/sql/drop_test.go +++ b/pkg/sql/drop_test.go @@ -1287,7 +1287,7 @@ func TestDropPhysicalTableGC(t *testing.T) { } func dropLargeDatabaseGeneric( - t *testing.T, workloadParams sqltestutils.GenerateViewBasedGraphSchemaParams, useDeclarative bool, + t testing.TB, workloadParams sqltestutils.GenerateViewBasedGraphSchemaParams, useDeclarative bool, ) { // Creates a complex schema with a view based graph that nests within // each other, which can lead to long DROP times specially if there @@ -1312,6 +1312,10 @@ CREATE DATABASE largedb; sqlDB.Exec(t, `SET use_declarative_schema_changer=off;`) } startTime := timeutil.Now() + if b, isB := t.(*testing.B); isB { + b.StartTimer() + defer b.StopTimer() + } sqlDB.Exec(t, `DROP DATABASE largedb;`) t.Logf("Total time for drop (declarative: %t) %f", useDeclarative, @@ -1332,6 +1336,40 @@ func TestDropLargeDatabaseWithLegacySchemaChanger(t *testing.T) { false) } +// BenchmarkDropLargeDatabase adds a benchmark which runs a large database +// drop for a connected graph of views. It can be used to compare the +// legacy and declarative schema changer. +// +// TODO(ajwerner): The parameters to the generator are a little bit opaque. +// It'd be nice to have a sense of how many views and how many total columns +// we end up dropping. +func BenchmarkDropLargeDatabase(b *testing.B) { + defer leaktest.AfterTest(b)() + + for _, declarative := range []bool{false, true} { + for _, tables := range []int{3, 4} { + for _, depth := range []int{2, 3, 4, 5} { + for _, columns := range []int{2, 4} { + b.Run(fmt.Sprintf("tables=%d,columns=%d,depth=%d,declarative=%t", + tables, columns, depth, declarative), func(b *testing.B) { + for i := 0; i < b.N; i++ { + b.StopTimer() + dropLargeDatabaseGeneric(b, + sqltestutils.GenerateViewBasedGraphSchemaParams{ + SchemaName: "largedb", + NumTablesPerDepth: tables, + NumColumnsPerTable: columns, + GraphDepth: depth, + }, + declarative) + } + }) + } + } + } + } +} + func TestDropLargeDatabaseWithDeclarativeSchemaChanger(t *testing.T) { defer leaktest.AfterTest(t)() defer log.Scope(t).Close(t) From 7c0ea9596e46876bca73678ebb0abe72db1611c5 Mon Sep 17 00:00:00 2001 From: Marius Posta Date: Wed, 25 Jan 2023 09:28:31 -0500 Subject: [PATCH 2/2] testlogic: deflake new_schema_changer test case The expected output of a system.eventlog query was rewritten in e333a39c7e106f11c7f87968d6b37e9b5dee0c95 with more than one record but the query was missing an ORDER clause, leading to non-deterministic output. This commit fixes this by adding the missing ORDER clause. Fixes #95825. Release note: None --- pkg/sql/logictest/testdata/logic_test/new_schema_changer | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pkg/sql/logictest/testdata/logic_test/new_schema_changer b/pkg/sql/logictest/testdata/logic_test/new_schema_changer index 3a8b31b8454a..243f5f0b886f 100644 --- a/pkg/sql/logictest/testdata/logic_test/new_schema_changer +++ b/pkg/sql/logictest/testdata/logic_test/new_schema_changer @@ -1091,7 +1091,8 @@ DROP VIEW v1ev CASCADE; query IT SELECT "reportingID", info::JSONB - 'Timestamp' - 'DescriptorID' -FROM system.eventlog; +FROM system.eventlog +ORDER BY "timestamp", info DESC ---- 1 {"CascadeDroppedViews": ["test.public.v4ev"], "EventType": "drop_view", "Statement": "DROP VIEW test.public.v1ev CASCADE", "Tag": "DROP VIEW", "User": "root", "ViewName": "test.public.v1ev"} 1 {"EventType": "finish_schema_change", "InstanceID": 1}