Coletar estatísticas com opções avançadas (histogramas etc.)
Oracle
EXEC DBMS_STATS.GATHER_TABLE_STATS(
ownname=>'HR', tabname=>'EMPLOYEE',
estimate_percent=>DBMS_STATS.AUTO_SAMPLE_SIZE,
method_opt=>'FOR ALL COLUMNS SIZE AUTO', degree=>4);method_opt controla os histogramas e degree controla o paralelismo. Use LOCK_TABLE_STATS para bloquear as estatísticas.
PostgreSQL
ALTER TABLE customer ALTER COLUMN city SET STATISTICS 500;
ANALYZE customer;Alvo de amostragem por coluna; default_statistics_target define o padrão global.
MySQL
ANALYZE TABLE customer UPDATE HISTOGRAM ON city WITH 32 BUCKETS;Suporte a histogramas no MySQL 8.0; útil em colunas que são filtradas, mas não são seletivas.
SQL Server
UPDATE STATISTICS dbo.customer WITH FULLSCAN;
-- Filtered statistics: CREATE STATISTICS ... WHERE ...FULLSCAN é o mais preciso; use SAMPLE em tabelas grandes. AUTO_UPDATE_STATISTICS para atualizações automáticas.
MongoDB
// There are no manual statistics; the planner measures at runtime.
db.customer.getPlanCache().clear()Além de limpar um plan cache obsoleto, não são necessárias estatísticas manuais.
Redis
# Not applicable.Não há estatísticas/otimizador.
Elasticsearch
# There is no statistics gathering; refresh searchability:
POST <index>/_refreshField data e doc values são usados no momento da consulta; o force merge reduz os segmentos.