@@ -312,58 +312,11 @@ const schemaChangerBackfillTxnDebugName = "schemaChangerBackfill"
312
312
// validateBackfillQueryIntoTable validates that source query matches the contents of
313
313
// a backfilled table, when executing the query at queryTS.
314
314
func (sc * SchemaChanger ) validateBackfillQueryIntoTable (
315
- ctx context.Context ,
316
- table catalog.TableDescriptor ,
317
- entryCountWrittenToPrimaryIdx int64 ,
318
- queryTS hlc.Timestamp ,
319
- query string ,
320
- skipAOSTValidation bool ,
315
+ ctx context.Context , table catalog.TableDescriptor , entryCountWrittenToPrimaryIdx int64 ,
321
316
) error {
322
- var aostEntryCount int64
323
317
sd := NewInternalSessionData (ctx , sc .execCfg .Settings , "validateBackfillQueryIntoTable" )
324
318
sd .SessionData = * sc .sessionData
325
- // First get the expected row count for the source query at the target timestamp.
326
- if err := sc .execCfg .InternalDB .Txn (ctx , func (ctx context.Context , txn isql.Txn ) error {
327
- if skipAOSTValidation {
328
- return nil
329
- }
330
- parsedQuery , err := parser .ParseOne (query )
331
- if err != nil {
332
- return err
333
- }
334
- // If the query has an AOST clause, then we will remove it here.
335
- selectTop , ok := parsedQuery .AST .(* tree.Select )
336
- if ok {
337
- selectStmt := selectTop .Select
338
- var parenSel * tree.ParenSelect
339
- var ok bool
340
- for parenSel , ok = selectStmt .(* tree.ParenSelect ); ok ; parenSel , ok = selectStmt .(* tree.ParenSelect ) {
341
- selectStmt = parenSel .Select .Select
342
- }
343
- sc , ok := selectStmt .(* tree.SelectClause )
344
- if ok && sc .From .AsOf .Expr != nil {
345
- sc .From .AsOf .Expr = nil
346
- query = parsedQuery .AST .String ()
347
- }
348
- }
349
- // Inject the query and the time we should scan at.
350
- err = txn .KV ().SetFixedTimestamp (ctx , queryTS )
351
- if err != nil {
352
- return err
353
- }
354
- countQuery := fmt .Sprintf ("SELECT count(*) FROM (%s)" , query )
355
- row , err := txn .QueryRow (ctx , "backfill-query-src-count" , txn .KV (), countQuery )
356
- if err != nil {
357
- return err
358
- }
359
- aostEntryCount = int64 (tree .MustBeDInt (row [0 ]))
360
- return nil
361
- }, isql .WithSessionData (sd ),
362
- isql .WithPriority (admissionpb .BulkNormalPri ),
363
- ); err != nil {
364
- return err
365
- }
366
- // Next run validation on table that was populated using count queries.
319
+ // Run validation on table that was populated using count queries.
367
320
// Get rid of the table ID prefix.
368
321
index := table .GetPrimaryIndex ()
369
322
now := sc .db .KV ().Clock ().Now ()
@@ -390,7 +343,7 @@ func (sc *SchemaChanger) validateBackfillQueryIntoTable(
390
343
// Testing knob that allows us to manipulate counts to fail
391
344
// the validation.
392
345
if sc .testingKnobs .RunDuringQueryBackfillValidation != nil {
393
- newTblEntryCount , err = sc .testingKnobs .RunDuringQueryBackfillValidation (aostEntryCount , newTblEntryCount )
346
+ newTblEntryCount , err = sc .testingKnobs .RunDuringQueryBackfillValidation (entryCountWrittenToPrimaryIdx , newTblEntryCount )
394
347
if err != nil {
395
348
return err
396
349
}
@@ -403,9 +356,6 @@ func (sc *SchemaChanger) validateBackfillQueryIntoTable(
403
356
)
404
357
}
405
358
}
406
- if ! skipAOSTValidation && newTblEntryCount != aostEntryCount {
407
- return errors .AssertionFailedf ("backfill query did not populate index %q with expected number of rows (expected: %d, got: %d)" , index .GetName (), aostEntryCount , newTblEntryCount )
408
- }
409
359
return nil
410
360
}
411
361
@@ -435,8 +385,6 @@ func (sc *SchemaChanger) backfillQueryIntoTable(
435
385
}
436
386
}
437
387
}()
438
- validationTime := ts
439
- var skipAOSTValidation bool
440
388
bulkSummary := kvpb.BulkOpSummary {}
441
389
442
390
err = sc .db .Txn (ctx , func (ctx context.Context , txn isql.Txn ) error {
@@ -596,23 +544,7 @@ func (sc *SchemaChanger) backfillQueryIntoTable(
596
544
return
597
545
}
598
546
})
599
-
600
- if planAndRunErr != nil {
601
- return planAndRunErr
602
- }
603
- // Otherwise, the select statement had no fixed timestamp. For
604
- // validating counts we will start with the read timestamp.
605
- if ts .IsEmpty () {
606
- validationTime = txn .KV ().ReadTimestamp ()
607
- }
608
- // If a virtual table was used then we can't conduct any kind of validation,
609
- // since our AOST query might be reading data not in KV.
610
- for _ , tbl := range localPlanner .curPlan .mem .Metadata ().AllTables () {
611
- if tbl .Table .IsVirtualTable () {
612
- skipAOSTValidation = true
613
- }
614
- }
615
- return nil
547
+ return planAndRunErr
616
548
})
617
549
618
550
// BatchTimestampBeforeGCError is retryable for the schema changer, but we
@@ -638,15 +570,14 @@ func (sc *SchemaChanger) backfillQueryIntoTable(
638
570
639
571
// Validation will be skipped if the query is not AOST safe.
640
572
// (i.e. reading non-KV data via CRDB internal)
641
- if err := sc .validateBackfillQueryIntoTable (ctx , table , entriesWrittenToPrimaryIdx , validationTime , query , skipAOSTValidation ); err != nil {
573
+ if err := sc .validateBackfillQueryIntoTable (ctx , table , entriesWrittenToPrimaryIdx ); err != nil {
642
574
return err
643
575
}
644
576
return nil
645
577
}
646
578
647
579
// maybe backfill a created table by executing the AS query. Return nil if
648
580
// successfully backfilled.
649
- //
650
581
// Note that this does not connect to the tracing settings of the
651
582
// surrounding SQL transaction. This should be OK as (at the time of
652
583
// this writing) this code path is only used for standalone CREATE
0 commit comments