@@ -518,16 +518,25 @@ func (e *Extractor) CountTableRows(table *config.Table) (int64, error) {
518
518
defer atomic .StoreInt64 (& e .mysqlContext .CountingRowsFlag , 0 )
519
519
//e.logger.Debugf("mysql.extractor: As instructed, I'm issuing a SELECT COUNT(*) on the table. This may take a while")
520
520
521
- query := fmt .Sprintf (`select count(*) as rows from %s.%s where (%s)` ,
522
- sql .EscapeName (table .TableSchema ), sql .EscapeName (table .TableName ), table .Where )
521
+ var query string
522
+ var method string
523
+ if os .Getenv (g .ENV_COUNT_INFO_SCHEMA ) != "" {
524
+ method = "information_schema"
525
+ query = fmt .Sprintf (`select table_rows from information_schema.tables where table_schema = '%s' and table_name = '%s'` ,
526
+ table .TableSchema , table .TableName )
527
+ } else {
528
+ method = "COUNT"
529
+ query = fmt .Sprintf (`select count(*) as rows from %s.%s where (%s)` ,
530
+ sql .EscapeName (table .TableSchema ), sql .EscapeName (table .TableName ), table .Where )
531
+ }
523
532
var rowsEstimate int64
524
533
if err := e .db .QueryRow (query ).Scan (& rowsEstimate ); err != nil {
525
534
return 0 , err
526
535
}
527
536
atomic .AddInt64 (& e .mysqlContext .RowsEstimate , rowsEstimate )
528
537
529
538
e .mysqlContext .Stage = models .StageSearchingRowsForUpdate
530
- e .logger .Debugf ("mysql.extractor: Exact number of rows(%s.%s) via COUNT : %d" , table .TableSchema , table .TableName , rowsEstimate )
539
+ e .logger .Debugf ("mysql.extractor: Exact number of rows(%s.%s) via %v : %d" , table .TableSchema , table .TableName , method , rowsEstimate )
531
540
return rowsEstimate , nil
532
541
}
533
542
0 commit comments