查询数据按日期字段作筛选,导致索引失效的情况

查询数据按日期字段作筛选,导致索引失效的情况

1.使用sqoop查询前10天的数据增量,发现耗时很长,大概用了3分钟才查询出来
test_query "
 select count(1) as cnt
 from test.mandpay
 where to_char(updatetime,'YYYY-MM-DD')>to_char(sysdate-10,'yyyy-mm-dd')
"
 2024-12-31 17:51:34,743 WARN tool.BaseSqoopTool: Setting your password on the command-line is insecure. Consider using -P instead.

------------------------
| CNT                  |
------------------------
| 377075               |
------------------------

date
Tue Dec 31 17:54:48 CST 2024

2.使用sqoop查询前10天的数据增量,几秒钟就查询出来了
test_query "
 select count(1) as cnt
 from test.mandpay
 where updatetime>=TRUNC(SYSDATE-10) 
"
2024-12-31 17:55:44,366 WARN tool.BaseSqoopTool: Setting your password on the command-line is insecure. Consider using -P instead.
------------------------
| CNT                  |
------------------------
| 406545               |
------------------------

date
Tue Dec 31 17:55:50 CST 2024

3.问题原因
updatetime 该字段在业务系统是索引字段,第一种方式对索引字段做了to_char操作,导致索引失效
改成用第二种方式就用上了索引,明显地提升了查询效率


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值