数据量:
SELECT COUNT(*)
FROM GPRXSJB
WHERE GPDM = '000001'
AND FSRQ < TO_DATE('2007-9-11','YYYY-MM-DD')
结果为 4054行FROM GPRXSJB
WHERE GPDM = '000001'
AND FSRQ < TO_DATE('2007-9-11','YYYY-MM-DD')
SQL1(ROWNUM方式):
SELECT *
FROM
(
SELECT SPJ
FROM GPRXSJB
WHERE GPDM = '000001'
AND FSRQ < TO_DATE('2007-9-11','YYYY-MM-DD')
ORDER BY FSRQ DESC
)
WHERE
ROWNUM = 1;
执行平均时间为:7.8 sFROM
(
SELECT SPJ
FROM GPRXSJB
WHERE GPDM = '000001'
AND FSRQ < TO_DATE('2007-9-11','YYYY-MM-DD')
ORDER BY FSRQ DESC
)
WHERE
ROWNUM = 1;
SQL2(MAX方式):
SELECT *
FROM GPRXSJB A,
(
SELECT MAX(FSRQ) AS MAXDATE
FROM GPRXSJB
WHERE GPDM = '000001'
AND FSRQ < TO_DATE('2007-9-11','YYYY-MM-DD')
) B
WHERE A.GPDM = '000001'
AND A.FSRQ = B.MAXDATE
执行平均时间为:16 sFROM GPRXSJB A,
(
SELECT MAX(FSRQ) AS MAXDATE
FROM GPRXSJB
WHERE GPDM = '000001'
AND FSRQ < TO_DATE('2007-9-11','YYYY-MM-DD')
) B
WHERE A.GPDM = '000001'
AND A.FSRQ = B.MAXDATE
效率比较明细第一种要快得多。
可能原因分析:
按第二种方式,与原表关联的笛卡尔积维度较大,所以执行缓慢。
愿牛人们帮忙分析一下,谢谢。