1

什么是强制执行计划仅在一次情况下使用提示 USE_NL 对所有表执行嵌套循环连接的最佳方法,
而在其他情况下只对所有表使用 USE_HASH 提示执行哈希连接我想同时运行查询并查看哪个有执行计划和使用成本低,请建议

我的疑问是我应该按照下面的 USE_NL(bl1_gain_adj,customers,bl1_gain,bl1_reply_code) 将所有 4 个表放在 HINT 中的哪个顺序

SELECT bl1_gain_adj.adj_seq_no,
bl1_gain_adj.amount_currency ,
bl1_gain_adj.gain_seq_no, 
customers.loan_key,
customers.customer_key,
FROM
bl1_gain_adj,
customers,
bl1_gain,
bl1_reply_code
WHERE
bl1_gain.loan_key = customers.loan_key
AND bl1_gain.customer_key = customers.customer_key
AND bl1_gain.receiver_customer = customers.customer_no
AND bl1_gain.cycle_seq_no = customers.cycle_seq_no
AND bl1_reply_code.gain_code = bl1_gain.gain_code
AND bl1_reply_code.revenue_code = 'RC'
AND bl1_gain_adj.gain_seq_no = bl1_gain.gain_seq_no
AND bl1_gain_adj.customer_key = bl1_gain.customer_key;

Records in tables
---------------
 bl1_gain_adj = 100 records    
 customers = 10 Million records   
 bl1_gain = 1 Million records   
 bl1_reply_code = 100 million records
4

1 回答 1

2

除了为您的查询选择最合适的提示(如果有的话)之外,您在USE_NL提示中写入表名/别名的顺序并不重要。

根据Oracle 文档

请注意,USE_NL(table1 table2)它不被视为多表提示,因为USE_NL(table1)USE_NL(table2)

关于 USE_NL,Oracle 说

USE_NL提示指示优化器将每个指定的表连接到具有嵌套循环连接的另一个行源,使用指定的表作为内表。

也就是说,如果你写USE_NL(table1 table2 table3 table4)这意味着“将所有这些表用作嵌套循环连接中的内表”;如果您的查询只有这 4 个表,则至少一个表的提示将被忽略:要使用一个表作为内部表,我们需要另一个表作为外部表,因此不可能将所有表都用作内部表。

LEADING关于扫描表的顺序,做了一些不同的事情:

LEADING 提示指示优化器使用指定的表集作为执行计划中的前缀。

于 2017-01-04T09:33:57.690 回答