@@ -518,16 +518,25 @@ func (e *Extractor) CountTableRows(table *config.Table) (int64, error) {
518518 defer atomic .StoreInt64 (& e .mysqlContext .CountingRowsFlag , 0 )
519519 //e.logger.Debugf("mysql.extractor: As instructed, I'm issuing a SELECT COUNT(*) on the table. This may take a while")
520520
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+ }
523532 var rowsEstimate int64
524533 if err := e .db .QueryRow (query ).Scan (& rowsEstimate ); err != nil {
525534 return 0 , err
526535 }
527536 atomic .AddInt64 (& e .mysqlContext .RowsEstimate , rowsEstimate )
528537
529538 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 )
531540 return rowsEstimate , nil
532541}
533542
0 commit comments