Oracle 常用hint

表的连接方式

USE_NL Hint 

Description of use_nl_hint.gif follows

 For example:

SELECT /*+ USE_NL(l h) */ h.customer_id, l.unit_price * l.quantity
  FROM orders h, order_items l
  WHERE l.order_id = h.order_id;

USE_HASH Hint

Description of use_hash_hint.gif follows

For example:

SELECT /*+ USE_HASH(l h) */ *
  FROM orders h, order_items l
  WHERE l.order_id = h.order_id
    AND l.order_id > 2400;


USE_MERGE Hint

Description of use_merge_hint.gif follows

 

 For example:

SELECT /*+ USE_MERGE(employees departments) */ * 
  FROM employees, departments 
  WHERE employees.department_id = departments.department_id;

表的访问路径

FULL Hint 

Description of full_hint.gif follows

 For example:

SELECT /*+ FULL(e) */ employee_id, last_name
  FROM hr.employees e 
  WHERE last_name LIKE :b1;

INDEX Hint

Description of index_hint.gif follows

For example:

SELECT /*+ INDEX (employees emp_department_ix)*/ employee_id, department_id
  FROM employees 
  WHERE department_id > 50;

INDEX_FFS Hint

Description of index_ffs_hint.gif follows

 For example:

SELECT /*+ INDEX_FFS(e emp_name_ix) */ first_name
  FROM employees e;

驱动表的选择

LEADING Hint

Description of leading_hint.gif follows

SELECT /*+ LEADING(e j) */ *
    FROM employees e, departments d, job_history j
    WHERE e.department_id = d.department_id
      AND e.hire_date = j.start_date;

QB_NAME Hint

当遇到子查询时,需要用qb_name命名子查询的查询语句块命名

 

Description of qb_name_hint.gif follows

For example:

SELECT /*+ leading(a@f) */ first_name
  FROM employees e where deptno in(select/*+ qb_name(a)*/ deptno from dept f)


SWAP_JOIN_INPUTS Hint

两表是外连接,要该表hash连接的驱动表必须使用该hint

For example:

SELECT /*+ use_hash(e,a@f) swap_join_inputs(a@f) */ first_name
  FROM employees e where not exists (select/*+ qb_name(a)*/ 1 from dept f
where e.dept_no=f.dept_no)



 

posted @   阿西吧li  阅读(486)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
点击右上角即可分享
微信分享提示