select /*+ parallel(n) */orderid, sum(amount) as amount, count(detailid) as detailsfrom orderdetail_1group by orderid;
其中/*+ parallel(n) */ 用于并行测试,n为并行数。
| A | |
| 1 | =now() |
| 2 | =file("/home/ctx/orderdetail_1.ctx").open().cursor@m(orderid,detailid,amount;;1) |
| 3 | =A2.groups@o(orderid;sum(amount):amount,count(detailid):details) |
| 4 | =interval@s(A1,now()) |
groups分组时加选项@o就适用分组字段有序时,只比较相邻行的值进行有序分组。
| 并行数 | 1 | 2 | 4 | 8 | 16 |
| Oracle | 24 | 19 | 16 | 13 | 13 |
| SPL | 11 | 6 | 3 | 2 | 1 |
在8千万行数据的情况下,SPL有序分组的性能提高了一倍左右,并且并行的效果非常好,性能呈线性上升。而使用hash分组的Oracle并行提速效果并不明显。
select * from (select /*+ parallel(n) */orderid, sum(amount) sum_amount, count(detailid) as detailsfrom orderdetail_2group by orderid)where sum_amount<35;
其中/*+ parallel(n) */ 用于并行测试,n为并行数。
| A | |
| 1 | =now() |
| 2 | =file("/home/ctx/orderdetail_2.ctx").open().cursor@m(orderid,detailid,amount;;1) |
| 3 | =A2.group(orderid;sum(amount):amount,count(detailid):details).select(amount<35).fetch() |
| 4 | =interval@s(A1,now()) |
由于分组结果集很大,无法全部装载到内存,所以使用group函数进行有序分组,返回分组结果集对应的游标,再对游标过滤后取得需要的查询结果。
| 并行数 | 1 | 2 | 4 | 8 | 16 |
| Oracle | 2647 | 1345 | 1092 | 806 | 737 |
| SPL | 451 | 235 | 119 | 65 | 48 |
在不并行的情况下,SPL有序分组比Oracle性能提升了近6倍左右。因SPL有序分组方法很适合并行,随着并行数的增加,性能提升的效果就越好。