通过 DB2 TPC-C 基准实现探索 SQL(2)
2008-09-17 16:31:45 来源:WEB开发网STOCK LEVEL 查询
最后一点,也是重要的一点, STOCK LEVEL 查询演习了一个三方(three-way)连接,以确定对于一个给定的、库存水平低于一个指定阈值的地区,在过去 20 份订单中产品的数量。关于这个查询没有很多要讲的,只有一点:该查询是惟一可以以 cursor stability 隔离级别运行的查询。DB2 能够逐个地为查询指定隔离级别,这里就使用了这一功能。
清单 20. 库存水平查询
1
SELECT COUNT( S_I_ID )
INTO :low_stock
2
FROM (
SELECT DISTINCT S_I_ID
3
FROM ORDER_LINE , STOCK , DISTRICT
4
WHERE D_W_ID = :w_id
5
AND D_ID = :d_id
6
AND OL_O_ID < d_next_o_id
7
AND OL_O_ID >= ( d_next_o_id - 20 )
8
AND OL_W_ID = D_W_ID
9
AND OL_D_ID = D_ID
10
AND S_I_ID = OL_I_ID
11
AND S_W_ID = OL_W_ID
12
AND S_QUANTITY < :threshold
13 )
AS OLS
14
WITH CS
清单 21. 库存水平查询访问计划
Rows
RETURN
( 1)
Cost
I/O
|
1
GRPBY
( 2)
13.204
1.02222
|
3.75467e-005
TBSCAN
( 3)
13.2039
1.02222
|
3.75467e-005
SORT
( 4)
13.2033
1.02222
|
3.75467e-005
NLJOIN
( 5)
13.2023
1.02222
/--------------------+--------------------
0.00782222 0.0048
NLJOIN FETCH
( 6) ( 11)
13.0011 0.201169
1.00782 0.0144
/-----------+----------- /----+---
1 0.00782222 0.0144 9
FETCH FETCH IXSCAN TABLE: SRIELAU
( 7) ( 9) ( 12) STOCK
12.872 0.129119 0.0157274
1 0.00782222 0
/----+--- /----+--- |
1 26 0.00782222 44 9
IXSCAN TABLE: SRIELAU IXSCAN TABLE: SRIELAU INDEX: SYSIBM
( 8) DISTRICT ( 10) ORDER_LINE SQL0410231029421
0.0175755 0.0282312
0 0
| |
26 44
INDEX: SYSIBM INDEX: SYSIBM
SQL0410231029415 SQL0410231030088
更多精彩
赞助商链接