CountTableRows counts exact number of rows on the original table
(db sql.QueryAble, table *common.Table)
| 857 | |
| 858 | // CountTableRows counts exact number of rows on the original table |
| 859 | func (e *Extractor) CountTableRows(db sql.QueryAble, table *common.Table) (int64, error) { |
| 860 | //e.logger.Debug("As instructed, I'm issuing a SELECT COUNT(*) on the table. This may take a while") |
| 861 | |
| 862 | var query string |
| 863 | // It only requires select privilege on target table to select its information_schema item. |
| 864 | query = fmt.Sprintf(`select table_rows from information_schema.tables where table_schema = ? and table_name = ?`) |
| 865 | var rowsEstimate int64 |
| 866 | err := db.QueryRowContext(e.ctx, query, table.TableSchema, table.TableName).Scan(&rowsEstimate) |
| 867 | if err != nil { |
| 868 | e.logger.Error("error when getting estimated row number (using information_schema)", "err", err, |
| 869 | "schema", table.TableSchema, "table", table.TableName) |
| 870 | rowsEstimate = 0 |
| 871 | } |
| 872 | atomic.AddInt64(&e.mysqlContext.RowsEstimate, rowsEstimate) |
| 873 | |
| 874 | e.mysqlContext.Stage = common.StageSearchingRowsForUpdate |
| 875 | e.logger.Debug("Estimated number of rows", "schema", table.TableSchema, "table", table.TableName, "n", rowsEstimate) |
| 876 | return rowsEstimate, nil |
| 877 | } |
| 878 | |
| 879 | // Read the MySQL charset-related system variables. |
| 880 | func (e *Extractor) readMySqlCharsetSystemVariables() error { |
no test coverage detected