Unverified Commit d5d12997 authored by Fernando Takagi's avatar Fernando Takagi Committed by GitHub
Browse files

Fix devconsole counts when database statistics are not available. (#816)

parent 6afd376e
Loading
Loading
Loading
Loading
+4 −3
Original line number Diff line number Diff line
@@ -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)
	}
@@ -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.