近似值(MySQL)
近似值(MySQL)
SELECT table_name, table_rows
FROM information_schema.tables
WHERE table_schema = 'app'
AND table_name = 'orders';近似值(PostgreSQL)
近似值(PostgreSQL)
SELECT reltuples::bigint AS approx_rows
FROM pg_class
WHERE relname = 'orders';| MySQL | information_schema.tables.table_rows 为估算值,误差可达较大比例 |
|---|---|
| PostgreSQL | pg_class.reltuples 由 ANALYZE/VACUUM 更新,同为估算 |
| 精确方案 | 维护计数表或用近似统计(如 HyperLogLog) |
近似值与真实行数可能有明显偏差,不要用于对账与计费场景。