tpch数据集的 sql优化案例

数据集:tpch 2.18 scale factor20,数据量大约1.2亿
在这里插入图片描述
1.


select
o_orderpriority,
count(*) as order_count
from
orders
where
o_orderdate >= date '1993-03-16'
and o_orderdate < date '1993-03-16' + interval '3' month
and exists (
	select
	*
	from
	lineitem
	where
	l_orderkey = o_orderkey
	and l_commitdate < l_receiptdate
	and L_ORDERKEY < 400000
	and L_LINENUMBER < 2
)
group by
o_orderpriority order by o_orderpriority limit 5;

优化:

  1. 强制使用索引,不适用引擎优化建议
  2. 范围查询变成等值查询,即将<>换成in
  3. 建立索引create index o_orderdate_index on orders(o_orderdate)
  4. 使用索引覆盖优化子查询

优化后


SELECT o_orderpriority, COUNT(1) AS order_count
FROM orders force index (o_orderdate_index)
WHERE o_orderdate IN (
'1993-03-16', '1993-03-17', '1993-03-18', '1993-03-19', '1993-03-20', '1993-03-
21',
'1993-03-22', '1993-03-23', '1993-03-24', '1993-03-25', '1993-03-26', '1993-03-
27',
'1993-03-28', '1993-03-29', '1993-03-30', '1993-03-31', '1993-04-01', '1993-04-
02'
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值