@@ -7,6 +7,7 @@ package backupccl
7
7
8
8
import (
9
9
"context"
10
+ gosql "database/sql"
10
11
"testing"
11
12
"time"
12
13
@@ -58,3 +59,49 @@ func TestRestoreWithOpenTransaction(t *testing.T) {
58
59
59
60
userConn .Exec (t , "COMMIT" )
60
61
}
62
+
63
+ func TestRestoreDuplicateTempTables (t * testing.T ) {
64
+ defer leaktest .AfterTest (t )()
65
+ defer log .Scope (t ).Close (t )
66
+
67
+ // This is a regression test for #153722. It verifies that restoring a backup
68
+ // that contains two temporary tables with the same name does not cause the
69
+ // restore to fail with an error of the form: "restoring 17 TableDescriptors
70
+ // from 4 databases: restoring table desc and namespace entries: table
71
+ // already exists"
72
+
73
+ clusterSize := 1
74
+ tc , sqlDB , _ , cleanupFn := backuptestutils .StartBackupRestoreTestCluster (t , clusterSize )
75
+ defer cleanupFn ()
76
+
77
+ sqlDB .Exec (t , `SET experimental_enable_temp_tables=true` )
78
+ sqlDB .Exec (t , `CREATE DATABASE test_db` )
79
+ sqlDB .Exec (t , `USE test_db` )
80
+ sqlDB .Exec (t , `CREATE TABLE permanent_table (id INT PRIMARY KEY, name TEXT)` )
81
+
82
+ sessions := make ([]* gosql.DB , 2 )
83
+ for i := range sessions {
84
+ sessions [i ] = tc .Servers [0 ].SQLConn (t )
85
+ sql := sqlutils .MakeSQLRunner (sessions [i ])
86
+ sql .Exec (t , `SET experimental_enable_temp_tables=true` )
87
+ sql .Exec (t , `USE test_db` )
88
+ sql .Exec (t , `CREATE TEMP TABLE duplicate_temp (id INT PRIMARY KEY, value TEXT)` )
89
+ sql .Exec (t , `INSERT INTO duplicate_temp VALUES (1, 'value')` )
90
+ }
91
+
92
+ sqlDB .Exec (t , `BACKUP INTO 'nodelocal://1/duplicate_temp_backup'` )
93
+
94
+ for _ , session := range sessions {
95
+ require .NoError (t , session .Close ())
96
+ }
97
+
98
+ // The cluster must be empty for a full cluster restore.
99
+ sqlDB .Exec (t , `DROP DATABASE test_db CASCADE` )
100
+ sqlDB .Exec (t , `RESTORE FROM LATEST IN 'nodelocal://1/duplicate_temp_backup'` )
101
+
102
+ sqlDB .Exec (t , `DROP DATABASE test_db CASCADE` )
103
+ sqlDB .Exec (t , `RESTORE DATABASE test_db FROM LATEST IN 'nodelocal://1/duplicate_temp_backup'` )
104
+
105
+ result := sqlDB .QueryStr (t , `SELECT table_name FROM [SHOW TABLES] ORDER BY table_name` )
106
+ require .Equal (t , [][]string {{"permanent_table" }}, result )
107
+ }
0 commit comments