Skip to content

Commit

Permalink
Merge #80275 #95826
Browse files Browse the repository at this point in the history
80275: sql: add a benchmark for large DROP DATABASE statements r=ajwerner a=ajwerner

Release note: None

95826: testlogic: deflake new_schema_changer test case r=postamar a=postamar

The expected output of a system.eventlog query was rewritten in e333a39 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

Co-authored-by: Andrew Werner <awerner32@gmail.com>
Co-authored-by: Marius Posta <marius@cockroachlabs.com>
  • Loading branch information
3 people committed Jan 25, 2023
3 parents b84f0eb + e2a1c6b + 7c0ea95 commit 1f0aeb4
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
40 changes: 39 additions & 1 deletion pkg/sql/drop_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,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
Expand All @@ -1392,6 +1392,10 @@ func dropLargeDatabaseGeneric(
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,
Expand All @@ -1412,6 +1416,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)
Expand Down
3 changes: 2 additions & 1 deletion pkg/sql/logictest/testdata/logic_test/new_schema_changer
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit 1f0aeb4

Please sign in to comment.