Fijar / forzar un plan 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;
/SQL Plan Management fija el plan; es la protección más sólida frente a regresiones. También se pueden usar hints /*+ ... */.
PostgreSQL
-- There is no built-in plan pinning; the pg_hint_plan extension:
/*+ IndexScan(customer customer_city_idx) */ SELECT ... ;Alternativa: orientar a nivel de sesión con parámetros como enable_seqscan; para una fijación persistente, use pg_hint_plan.
MySQL
SELECT /*+ INDEX(customer customer_city_idx) */ * FROM customer WHERE city='Ankara';Los optimizer hints se incrustan en la consulta. Para una reescritura persistente, use el plugin query rewrite.
SQL Server
-- Force the good plan in Query Store:
EXEC sp_query_store_force_plan @query_id = 42, @plan_id = 17;Query Store debe estar habilitado. Como alternativa, OPTION (USE PLAN N'...') o una plan guide.
MongoDB
// Force an index for the query:
db.customer.find({ city: "Ankara" }).hint({ city: 1 })
// Persistent: db.customer.getPlanCache() / index filterhint fuerza un índice concreto; elimine un plan obsoleto con planCacheClear.
Redis
# Not applicable: there is no query planner.El rendimiento depende de la estructura de datos y de la complejidad de los comandos.
Elasticsearch
# There is no plan pinning; optimize the query/index and routing.
GET <index>/_search { "profile": true, "query": {...} }Use profile para ver qué consulta es costosa; oriéntela con shards/routing.