通过 DB2 TPC-C 基准实现探索 SQL
2008-09-17 16:31:49 来源:WEB开发网对于那些对内联 SQL PL 的内部原理真正感兴趣的读者,可以在本文 参考资料 一节中给出的参考资料中发现更详细的信息。
NEW_ORDER 事务中的第三条语句,也即最后一条语句是:
清单 7. 第三条 SQL 语句
1
SELECT W_TAX, C_DISCOUNT, C_LAST, C_CREDIT
2
INTO :ware_tax, :c_discount, :c_last, :c_credit
3
FROM TABLE ( NEW_WH ( :next_o_id
4 , :w_id
5 , :d_id
6 , :c_id
7 , :o_entry_d
8 , :inputItemCount
9 , :allLocal
10 )
11 )
AS NEW_WH_TABLE
清单 8. NEW_WH 函数
1
CREATE FUNCTION NEW_WH ( O_ID INTEGER
2 , W_ID INTEGER
3 , D_ID SMALLINT
4 , C_ID INTEGER
5 , O_ENTRY_D BIGINT
6 , O_OL_CNT SMALLINT
7 , O_ALL_LOCAL SMALLINT
8 )
9
RETURNS TABLE ( W_TAX INTEGER
10 , C_DISCOUNT INTEGER
11 , C_LAST VARCHAR(16)
12 , C_CREDIT CHAR(2)
13 )
14
SPECIFIC NEW_WH
15
MODIFIES SQL DATA DETERMINISTIC NO EXTERNAL ACTION LANGUAGE SQL
16 VAR:
BEGIN ATOMIC
17
DECLARE C_DISCOUNT INTEGER ;
18
DECLARE C_LAST VARCHAR(16) ;
19
DECLARE C_CREDIT CHAR(2) ;
20
DECLARE W_TAX INTEGER ;
21
22
INSERT
23
INTO NEW_ORDER ( NO_O_ID, NO_D_ID, NO_W_ID )
24
VALUES ( O_ID
25 , D_ID
26 , W_ID
27 )
28 ;
29
INSERT
30
INTO ORDERS ( O_C_ID , O_ENTRY_D , O_CARRIER_ID , O_OL_CNT
31 , O_ALL_LOCAL , O_ID , O_W_ID , O_D_ID )
32
VALUES ( C_ID , O_ENTRY_D , 0 , O_OL_CNT
33 , O_ALL_LOCAL , O_ID , W_ID , D_ID )
34 ;
35
SET ( C_DISCOUNT, C_LAST, C_CREDIT )
36 = (
SELECT C_DISCOUNT, C_LAST, C_CREDIT
37
FROM CUSTOMER
38
WHERE C_ID = NEW_WH.C_ID
39
AND C_W_ID = W_ID
40
AND C_D_ID = D_ID
41 )
42 ;
43
SET W_TAX
44 = (
SELECT W_TAX
45
FROM WAREHOUSE
46
WHERE W_ID = NEW_WH.W_ID
47 )
48 ;
49
RETURN VALUES ( W_TAX , C_DISCOUNT , C_LAST , C_CREDIT ) ;
50
END
更多精彩
赞助商链接