DBAtlas · Атлас эксплуатации баз данных

Закрепить / принудительно задать план запроса (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 фиксирует план; самая сильная защита от регрессий. Можно также использовать хинты /*+ ... */.

PostgreSQL

-- There is no built-in plan pinning; the pg_hint_plan extension:
/*+ IndexScan(customer customer_city_idx) */ SELECT ... ;

Альтернатива: управлять на уровне сессии параметрами вроде enable_seqscan; для постоянного закрепления используйте pg_hint_plan.

MySQL

SELECT /*+ INDEX(customer customer_city_idx) */ * FROM customer WHERE city='Ankara';

Хинты оптимизатора встраиваются в запрос. Для постоянной перезаписи используйте плагин 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 должен быть включён. Альтернатива: OPTION (USE PLAN N'...') или plan guide.

MongoDB

// Force an index for the query:
db.customer.find({ city: "Ankara" }).hint({ city: 1 })
// Persistent: db.customer.getPlanCache() / index filter

hint принудительно задаёт конкретный индекс; устаревший план очищается через planCacheClear.

Redis

# Not applicable: there is no query planner.

Производительность определяется структурой данных и сложностью команд.

Elasticsearch

# There is no plan pinning; optimize the query/index and routing.
GET <index>/_search { "profile": true, "query": {...} }

Используйте profile, чтобы увидеть, какой запрос дорогой; управляйте через шарды/routing.

Открыть в DBAtlas →