外连接的有效替代方案
此查询上的 RIGHT JOIN
会导致 lims.operator
上出现 TABLE ACCESS FULL
。 常规联接运行速度很快,但当然,示例“WHEREauthorized_by IS NULL
”不会显示。
在这种情况下,是否有比 RIGHT JOIN 更有效的替代方案?
SELECT full_name
FROM (SELECT operator_id AS authorised_by, full_name
FROM lims.operator)
RIGHT JOIN (SELECT sample_id, authorised_by
FROM lims.sample
WHERE sample_template_id = 200)
USING (authorised_by)
注意:显示的所有列(full_name 除外)均已编入索引,并且是某个表的主键。
The RIGHT JOIN
on this query causes a TABLE ACCESS FULL
on lims.operator
. A regular join runs quickly, but of course, the samples 'WHERE authorised_by IS NULL
' do not show up.
Is there a more efficient alternative to a RIGHT JOIN
in this case?
SELECT full_name
FROM (SELECT operator_id AS authorised_by, full_name
FROM lims.operator)
RIGHT JOIN (SELECT sample_id, authorised_by
FROM lims.sample
WHERE sample_template_id = 200)
USING (authorised_by)
NOTE: All columns shown (except full_name) are indexed and the primary key of some table.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
由于您正在执行外连接,因此很可能执行全表扫描实际上比使用索引更有效。
如果您确信应该使用索引,请使用提示强制使用:
SELECT /*+ INDEX (lims.operatoroperator_index_name)*/ ...
然后看看会发生什么...
Since you're doing an outer join, it could easily be that it actually is more efficient to do a full table scan rather than use the index.
If you are convinced the index should be used, force it with a hint:
SELECT /*+ INDEX (lims.operator operator_index_name)*/ ...
then see what happens...
无需嵌套查询。 尝试这个:
No need to nest queries. Try this:
我已经有一段时间没有为 Oracle 编写 sql 了,但是我会这样编写查询:
这仍然执行得那么糟糕吗?
I didn't write sql for oracle since a while, but i would write the query like this:
Does this still perform that bad?