satellite/metabase: sort stats by creation time not number of entries

By accident query to get latest table stats was ordered by 'row_count'
column instead 'create'. We need latest stats so we need ordering by
creation time.

Change-Id: I9d0a0edda8bab59c3d96b7a15cd6502ed51633fc
This commit is contained in:
Michal Niewrzal 2023-03-30 14:29:40 +02:00
parent 00420b5904
commit dc9cbe36ae

View File

@ -31,7 +31,7 @@ func (db *DB) GetTableStats(ctx context.Context, opts GetTableStats) (result Tab
// if it's cockroach and statistics are up to date we will use them to get segments count
if db.impl == dbutil.Cockroach {
var created time.Time
err := db.db.QueryRowContext(ctx, `WITH stats AS (SHOW STATISTICS FOR TABLE segments) SELECT row_count, created FROM stats ORDER BY row_count DESC LIMIT 1`).
err := db.db.QueryRowContext(ctx, `WITH stats AS (SHOW STATISTICS FOR TABLE segments) SELECT row_count, created FROM stats ORDER BY created DESC LIMIT 1`).
Scan(&result.SegmentCount, &created)
if err != nil && !errors.Is(err, sql.ErrNoRows) {
return TableStats{}, err