查询提示
查询提示(Query Hints)是随 SQL 查询一起发送的指令,帮助数据库决定更高效的执行策略。
不同的 RDBMS 系统支持不同类型的提示,例如建议使用某个索引或选择合适的 JOIN 类型。
await dataSource.query(`
SELECT /*+ MAX_EXECUTION_TIME(1000) */ *
FROM user
WHERE email = '[email protected]'
`)在上面的示例中,MAX_EXECUTION_TIME(1000) 指示 MySQL 在查询耗时超过 1 秒时中止该查询。
Query Hints are instructions sent along with SQL queries, helping the database decide on more efficient execution strategies.
Different RDBMS systems support different kinds of hints, such as suggesting index usage or choosing the appropriate JOIN type.
await dataSource.query(`
SELECT /*+ MAX_EXECUTION_TIME(1000) */ *
FROM user
WHERE email = '[email protected]'
`)In the example above, MAX_EXECUTION_TIME(1000) instructs MySQL to stop the query if it takes more than 1 second.