Fixar / forçar um plano de consulta (plan baseline / hint)
Oracle
-- Load the good plan from the cursor cache as a baseline:
DECLARE n NUMBER; BEGIN
n := DBMS_SPM.LOAD_PLANS_FROM_CURSOR_CACHE(sql_id => '&sql_id');
END;
/O SQL Plan Management fixa o plano; é a proteção mais forte contra regressões. Hints /*+ ... */ também podem ser usados.
PostgreSQL
-- There is no built-in plan pinning; the pg_hint_plan extension:
/*+ IndexScan(customer customer_city_idx) */ SELECT ... ;Alternativa: direcionar em nível de sessão com configurações como enable_seqscan; para fixação persistente, use o pg_hint_plan.
MySQL
SELECT /*+ INDEX(customer customer_city_idx) */ * FROM customer WHERE city='Ankara';Os optimizer hints são embutidos na consulta. Para reescrita persistente, use o plugin query rewrite.
SQL Server
-- Force the good plan in Query Store:
EXEC sp_query_store_force_plan @query_id = 42, @plan_id = 17;O Query Store deve estar habilitado. Como alternativa, OPTION (USE PLAN N'...') ou um plan guide.
MongoDB
// Force an index for the query:
db.customer.find({ city: "Ankara" }).hint({ city: 1 })
// Persistent: db.customer.getPlanCache() / index filterhint força um índice específico; limpe um plano obsoleto com planCacheClear.
Redis
# Not applicable: there is no query planner.O desempenho depende da estrutura de dados e da complexidade dos comandos.
Elasticsearch
# There is no plan pinning; optimize the query/index and routing.
GET <index>/_search { "profile": true, "query": {...} }Use profile para ver qual consulta é cara; direcione com shards/routing.