Skip to content

Commit 8c39073

Browse files
author
ffffwh
committed
env config: count table use info_schema
1 parent 4292240 commit 8c39073

File tree

2 files changed

+19
-8
lines changed

2 files changed

+19
-8
lines changed

internal/client/driver/mysql/extractor.go

+12-3
Original file line numberDiff line numberDiff line change
@@ -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

internal/g/g.go

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// global values
12
package g
23

34
var (
@@ -11,9 +12,10 @@ const (
1112
GtidExecutedTableV2 string = "gtid_executed_v2"
1213
GtidExecutedTableV3 string = "gtid_executed_v3"
1314

14-
ENV_PRINT_TPS = "UDUP_PRINT_TPS"
15-
ENV_DUMP_CHECKSUM = "DTLE_DUMP_CHECKSUM"
16-
ENV_DUMP_OLDWAY = "DTLE_DUMP_OLDWAY"
17-
ENV_TESTSTUB1_DELAY = "UDUP_TESTSTUB1_DELAY"
18-
ENV_FULL_APPLY_DELAY = "DTLE_FULL_APPLY_DELAY"
15+
ENV_PRINT_TPS = "UDUP_PRINT_TPS"
16+
ENV_DUMP_CHECKSUM = "DTLE_DUMP_CHECKSUM"
17+
ENV_DUMP_OLDWAY = "DTLE_DUMP_OLDWAY"
18+
ENV_TESTSTUB1_DELAY = "UDUP_TESTSTUB1_DELAY"
19+
ENV_FULL_APPLY_DELAY = "DTLE_FULL_APPLY_DELAY"
20+
ENV_COUNT_INFO_SCHEMA = "DTLE_COUNT_INFO_SCHEMA"
1921
)

0 commit comments

Comments
 (0)