-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #50714 from ajwerner/ajwerner/stop-populating-Drop…
…JobID-in-truncate sql: only set DropJobID on old table descriptor in TRUNCATE
- Loading branch information
Showing
2 changed files
with
52 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright 2020 The Cockroach Authors. | ||
// | ||
// Use of this software is governed by the Business Source License | ||
// included in the file licenses/BSL.txt. | ||
// | ||
// As of the Change Date specified in that file, in accordance with | ||
// the Business Source License, use of this software will be governed | ||
// by the Apache License, Version 2.0, included in the file | ||
// licenses/APL.txt. | ||
|
||
package sql_test | ||
|
||
import ( | ||
"context" | ||
"testing" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/base" | ||
"github.com/cockroachdb/cockroach/pkg/sql/sqlbase" | ||
"github.com/cockroachdb/cockroach/pkg/testutils/sqlutils" | ||
"github.com/cockroachdb/cockroach/pkg/testutils/testcluster" | ||
"github.com/cockroachdb/cockroach/pkg/util/leaktest" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
// TestTruncateDoesNotSetDropJobOnNewTable ensures that the new version of a | ||
// table after a TRUNCATE does not contain a DropJobID. This is a regression | ||
// test for #50587. | ||
func TestTruncateDoesNotSetDropJobOnNewTable(t *testing.T) { | ||
defer leaktest.AfterTest(t)() | ||
|
||
ctx := context.Background() | ||
tc := testcluster.StartTestCluster(t, 1, base.TestClusterArgs{}) | ||
defer tc.Stopper().Stop(ctx) | ||
|
||
tdb := sqlutils.MakeSQLRunner(tc.ServerConn(0)) | ||
|
||
getTableDescID := func(t *testing.T, tableName string) (id sqlbase.ID) { | ||
tdb.QueryRow(t, `SELECT '`+tableName+`'::regclass::int`).Scan(&id) | ||
return id | ||
} | ||
|
||
tdb.Exec(t, `CREATE TABLE foo (i INT PRIMARY KEY)`) | ||
tdb.Exec(t, `INSERT INTO foo VALUES (1)`) | ||
oldID := getTableDescID(t, "foo") | ||
tdb.Exec(t, `TRUNCATE foo`) | ||
newID := getTableDescID(t, "foo") | ||
require.NotEqual(t, oldID, newID) | ||
td, err := sqlbase.GetTableDescFromID(ctx, tc.Server(0).DB(), newID) | ||
require.NoError(t, err) | ||
require.Zero(t, td.DropJobID) | ||
} |