Pin / force a query plan (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 locks in the plan; the strongest protection against regressions. /*+ ... */ hints can also be used.
PostgreSQL
-- There is no built-in plan pinning; the pg_hint_plan extension:
/*+ IndexScan(customer customer_city_idx) */ SELECT ... ;Alternative: steer at session level with settings such as enable_seqscan; for persistent pinning, use pg_hint_plan.
MySQL
SELECT /*+ INDEX(customer customer_city_idx) */ * FROM customer WHERE city='Ankara';Optimizer hints are embedded in the query. For persistent rewriting, use the query rewrite plugin.
SQL Server
-- Force the good plan in Query Store:
EXEC sp_query_store_force_plan @query_id = 42, @plan_id = 17;Query Store must be enabled. Alternatively OPTION (USE PLAN N'...') or a plan guide.
MongoDB
// Force an index for the query:
db.customer.find({ city: "Ankara" }).hint({ city: 1 })
// Persistent: db.customer.getPlanCache() / index filterhint forces a specific index; clear a stale plan with planCacheClear.
Redis
# Not applicable: there is no query planner.Performance comes from the data structure and command complexity.
Elasticsearch
# There is no plan pinning; optimize the query/index and routing.
GET <index>/_search { "profile": true, "query": {...} }Use profile to see which query is expensive; steer with shards/routing.