我收到了以下sql请求,我想知道是否可以让它更快地运行。我可以在这里改变什么加速它?它目前执行0.24秒。
SELECT RECNO
FROM ( SELECT T.ID, T.RECNO, T.STATE, T.TYPEID
FROM SOME_TABLE T
ORDER BY T.ID )
WHERE ROWNUM = 1 AND TYPEID = 123123 AND STATE = 123;
答案 0 :(得分:0)
如果您使用的是Oracle 12c +
,则可以使用OFFSET-FETCH
SELECT * FROM SOME_TABLE T
Where TYPEID = 123123 AND STATE = 123;
ORDER BY T.ID
FETCH NEXT 1 ROWS ONLY --OFFSET 0 ROWS FETCH NEXT 1 ROWS ONLY
虽然对表现不太确定
答案 1 :(得分:0)
试试这个:
SELECT RECNO
FROM ( SELECT T.ID, T.RECNO, T.STATE, T.TYPEID
FROM SOME_TABLE T
where TYPEID = 123123 AND STATE = 123
ORDER BY T.ID ) a
WHERE ROWNUM = 1