DBAtlas · Database operations atlas

Update statistics (for the optimizer)

Oracle

EXEC DBMS_STATS.GATHER_TABLE_STATS('HR', 'EMPLOYEE');
-- Whole schema: EXEC DBMS_STATS.GATHER_SCHEMA_STATS('HR');

The AUTO task usually gathers them at night; gather them manually when a problem occurs. ESTIMATE_PERCENT=>AUTO_SAMPLE_SIZE is recommended.

PostgreSQL

ANALYZE customer;
-- Both cleanup and analyze: VACUUM ANALYZE customer;

Autovacuum does this automatically; a manual ANALYZE after a sudden data load gives accurate plans.

MySQL

ANALYZE TABLE customer;

Takes a brief read lock on InnoDB; on large tables run it during low activity.

SQL Server

UPDATE STATISTICS dbo.customer WITH FULLSCAN;
-- Whole database: EXEC sp_updatestats;

FULLSCAN is the most accurate but the most expensive; on large tables sampling (SAMPLE) may be preferred.

MongoDB

// There are no manual statistics; the planner measures at runtime.
// To clear a stale plan cache:
db.customer.getPlanCache().clear()

Instead of cost estimation, MongoDB runs actual trials (plan racing); manual statistics are not needed.

Redis

# Not applicable: Redis has no query optimizer / statistics.

Command complexity is fixed; performance depends on the choice of data structure.

Open in DBAtlas →