@@ -261,86 +261,6 @@ func addIndexEntryForDatums(
261261 return kvDB .Put (context .Background (), entry .Key , & entry .Value )
262262}
263263
264- // TestScrubIndexDanglingIndexReference tests that
265- // `SCRUB TABLE ... INDEX“ will find dangling index references, which
266- // are index entries that have no corresponding primary k/v. To test
267- // this an index entry is generated and inserted. This creates a
268- // dangling index error as the corresponding primary k/v is not equal.
269- func TestScrubIndexDanglingIndexReference (t * testing.T ) {
270- defer leaktest .AfterTest (t )()
271- defer log .Scope (t ).Close (t )
272- s , db , kvDB := serverutils .StartServer (t , base.TestServerArgs {})
273- defer s .Stopper ().Stop (context .Background ())
274-
275- // Create the table and the row entry.
276- if _ , err := db .Exec (`
277- CREATE DATABASE t;
278- CREATE TABLE t.test (k INT PRIMARY KEY, v INT);
279- CREATE INDEX secondary ON t.test (v);
280- ` ); err != nil {
281- t .Fatalf ("unexpected error: %s" , err )
282- }
283-
284- tableDesc := desctestutils .TestingGetPublicTableDescriptor (kvDB , keys .SystemSQLCodec , "t" , "test" )
285- secondaryIndex := tableDesc .PublicNonPrimaryIndexes ()[0 ]
286- // Construct datums and secondary k/v for our row values (k, v).
287- values := []tree.Datum {tree .NewDInt (10 ), tree .NewDInt (314 )}
288-
289- // Put the new secondary k/v into the database.
290- if err := addIndexEntryForDatums (values , kvDB , tableDesc , secondaryIndex ); err != nil {
291- t .Fatalf ("unexpected error: %s" , err )
292- }
293-
294- // Run SCRUB and find the index errors we created.
295- rows , err := db .Query (`EXPERIMENTAL SCRUB TABLE t.test WITH OPTIONS INDEX ALL` )
296- if err != nil {
297- t .Fatalf ("unexpected error: %s" , err )
298- }
299- defer rows .Close ()
300-
301- results , err := sqlutils .GetInspectResultRows (rows )
302- if err != nil {
303- t .Fatalf ("unexpected error: %s" , err )
304- }
305-
306- if len (results ) != 1 {
307- t .Fatalf ("expected 1 result, got %d. got %#v" , len (results ), results )
308- }
309- if result := results [0 ]; result .ErrorType != scrub .DanglingIndexReferenceError {
310- t .Fatalf ("expected %q error, instead got: %s" ,
311- scrub .DanglingIndexReferenceError , result .ErrorType )
312- } else if result .Database != "t" {
313- t .Fatalf ("expected database %q, got %q" , "t" , result .Database )
314- } else if result .Table != "test" {
315- t .Fatalf ("expected table %q, got %q" , "test" , result .Table )
316- } else if result .PrimaryKey != "(10)" {
317- t .Fatalf ("expected primaryKey %q, got %q" , "(10)" , result .PrimaryKey )
318- } else if result .Repaired {
319- t .Fatalf ("expected repaired %v, got %v" , false , result .Repaired )
320- } else if ! strings .Contains (result .Details , `"v": "314"` ) {
321- t .Fatalf ("expected error details to contain `%s`, got %s" , `"v": "314"` , result .Details )
322- }
323-
324- // Run SCRUB DATABASE to make sure it also catches the problem.
325- rows , err = db .Query (`EXPERIMENTAL SCRUB DATABASE t` )
326- if err != nil {
327- t .Fatalf ("unexpected error: %+v" , err )
328- }
329- defer rows .Close ()
330- scrubDatabaseResults , err := sqlutils .GetInspectResultRows (rows )
331- if err != nil {
332- t .Fatalf ("unexpected error: %s" , err )
333- } else if len (scrubDatabaseResults ) != 1 {
334- t .Fatalf ("expected 1 result, got %d. got %#v" , len (scrubDatabaseResults ), scrubDatabaseResults )
335- } else if ! (scrubDatabaseResults [0 ].ErrorType == results [0 ].ErrorType &&
336- scrubDatabaseResults [0 ].Database == results [0 ].Database &&
337- scrubDatabaseResults [0 ].Table == results [0 ].Table &&
338- scrubDatabaseResults [0 ].Details == results [0 ].Details ) {
339- t .Fatalf ("expected results to be equal, SCRUB TABLE got %v. SCRUB DATABASE got %v" ,
340- results , scrubDatabaseResults )
341- }
342- }
343-
344264// TestScrubIndexCatchesStoringMismatch tests that
345265// `SCRUB TABLE ... INDEX ALL` will fail if an index entry only differs
346266// by its STORING values. To test this, a row's underlying secondary
0 commit comments