diff --git a/pkg/sql/executor.go b/pkg/sql/executor.go index c46552a9df6d..99cac3e7bae1 100644 --- a/pkg/sql/executor.go +++ b/pkg/sql/executor.go @@ -1479,6 +1479,8 @@ func (e *Executor) execStmtInAbortedTxn( false /* implicitTxn */, true, /* retryIntent */ curTs /* sqlTimestamp */, curIso /* isolation */, curPri /* priority */) } + session.testingVerifyMetadataFn = nil + session.tables.releaseTables(session.Ctx()) // TODO(andrei/cdo): add a counter for user-directed retries. return nil default: @@ -1752,6 +1754,8 @@ func (e *Executor) execStmtInOpenTxn( txnState.mu.txn.Proto().Restart( 0 /* userPriority */, 0 /* upgradePriority */, hlc.Timestamp{}) } + session.testingVerifyMetadataFn = nil + session.tables.releaseTables(session.Ctx()) return nil case *parser.Prepare: diff --git a/pkg/sql/logictest/testdata/logic_test/manual_retry b/pkg/sql/logictest/testdata/logic_test/manual_retry index 4383e628adce..f2237d7648c0 100644 --- a/pkg/sql/logictest/testdata/logic_test/manual_retry +++ b/pkg/sql/logictest/testdata/logic_test/manual_retry @@ -34,3 +34,40 @@ SELECT CRDB_INTERNAL.FORCE_RETRY('500ms':::INTERVAL) statement ok COMMIT + +# Test that creating a table repeatedly across restarts doesn't leave dangling +# rows behind (the rows are associated with the correct descriptor). +# See #24785. + +statement ok +BEGIN + +statement ok +SAVEPOINT cockroach_restart + +statement ok +CREATE TABLE t ( +id INT PRIMARY KEY +) + +statement ok +ROLLBACK TO SAVEPOINT cockroach_restart + +# The following CREATE shouldn't be necessary. This test would like to just run +# the next insert (or a select) and check that it fails to resolve the table +# name. However, that doesn't currently work because of #24885. +statement ok +CREATE TABLE t ( +id INT PRIMARY KEY +) + +statement ok +INSERT INTO t (id) VALUES (1); + +statement ok +COMMIT + +query I +SELECT id FROM t +---- +1