sql - 试图在 oracle 中完全删除表访问
问题描述
我有一个简单的查询
select round(sum(a.wt)) as a_wt
from db.abc a
where a.date is null
and a.col_no is not null
and a.pod_cd = '367'
and a.fant != a.rce
我想删除完整的表访问。在以下列组合中有 3 个索引类似于这些
col_no
col_no,date,fant,pyc
wagno,batno
解决方案
一种选择是创建一个Function Based Index
:
create index idx_date_col_pod on ABC (nvl("date",date'1900-01-01'), nvl(col_no,0), pod_cd);
并将查询转换为:
select round(sum(wt)) as a_wt
from abc
where nvl("date",date'1900-01-01') = date'1900-01-01' -- matching means "date" column is null assuming there exists no records with this ancient date.
and nvl(col_no,0) != 0 -- non-matching means "col_no" column is not null
and pod_cd = 367
and fant != rce
推荐阅读
- javascript - 如何测试从外部 API 获取数据的组件?
- ios - Swiftui List Row Cells 在 View 出现后设置填充
- mysql - 如何在 MySQLWorkbench 中执行简单的 SQL 命令
- php - Sonata 管理员根据所选值动态更改输入数据 - 自定义控制器
- php - 使用 .htaccess 的 SEO 友好 url 不加载 css 文件(路径是相对的)
- sql-update - 使用 H2 中 CTE 的结果集进行更新
- c# - 将两个相似的 for 循环合并为一个是否存在性能差异?
- reporting-services - 多个 Power BI 报表服务器指向同一个 ReportServerDB?
- mysql - SQl查询:统计分类中的产品,一次统计1个分类,不统计其他分类
- python - 使用 PIL/Image 保存 .tif 堆栈