Skip to content

Commit

Permalink
Include schema name when fetching estimate
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanslade committed Jan 3, 2025
1 parent 150e1c9 commit 30b57d1
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pkg/migrations/backfill.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,15 @@ func Backfill(ctx context.Context, conn db.DB, table *schema.Table, batchSize in
func getRowCount(ctx context.Context, conn db.DB, tableName string) (int64, error) {
var total int64
// Try and get estimated row count
row := conn.QueryRowContext(ctx, `
var currentSchema string
row := conn.QueryRowContext(ctx, "select current_schema()")
if err := row.Scan(&currentSchema); err != nil {
return 0, fmt.Errorf("getting current schema: %w", err)
}
row = conn.QueryRowContext(ctx, `
SELECT n_live_tup AS estimate
FROM pg_stat_user_tables
WHERE relname = $1`, tableName)
WHERE schemaname = $1 AND relname = $2`, currentSchema, tableName)
if err := row.Scan(&total); err != nil {
return 0, fmt.Errorf("scanning row count estimate for %q: %w", tableName, err)
}
Expand Down

0 comments on commit 30b57d1

Please sign in to comment.