Skip to content

Commit

Permalink
Fix devconsole counts when database statistics are not available. (he…
Browse files Browse the repository at this point in the history
  • Loading branch information
ftkg authored Mar 24, 2022
1 parent 6afd376 commit d5d1299
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions server/console_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,7 +376,8 @@ func countDatabase(ctx context.Context, logger *zap.Logger, db *sql.DB, tableNam
return 0
}
}
if count.Valid && count.Int64 != 0 {
// It may return -1 if there are no statistics collected (PG14)
if count.Valid && count.Int64 > 0 {
// Use this count result.
return int32(count.Int64)
}
Expand All @@ -389,12 +390,12 @@ func countDatabase(ctx context.Context, logger *zap.Logger, db *sql.DB, tableNam
return 0
}
}
if count.Valid && count.Int64 != 0 {
if count.Valid && count.Int64 > 0 {
// Use this count result.
return int32(count.Int64)
}

// If both fast counts failed, returned NULL, or returned 0 try a full count.
// If both fast counts failed, returned NULL, returned 0 or -1 try a full count.
// NOTE: PostgreSQL parses the expression count(*) as a special case taking no
// arguments, while count(1) takes an argument and PostgreSQL has to check that
// 1 is indeed still not NULL for every row.
Expand Down

0 comments on commit d5d1299

Please sign in to comment.