更多指數 - 指數......
你可以為每個臨時表定義多個索引。如果你需要它們 - 定義它們。基本上,與你的查詢和/或排序順序匹配的索引將有助於提高效能!
DEFINE TEMP-TABLE ttWithIndex NO-UNDO
FIELD field1 AS INTEGER
FIELD field2 AS CHARACTER
FIELD field3 AS LOGICAL
INDEX field1 field1.
DEFINE TEMP-TABLE ttWithoutIndex NO-UNDO
FIELD field1 AS INTEGER
FIELD field2 AS CHARACTER
FIELD field3 AS LOGICAL.
DEFINE VARIABLE i AS INTEGER NO-UNDO.
DEFINE VARIABLE iWithCreate AS INTEGER NO-UNDO.
DEFINE VARIABLE iWithFind AS INTEGER NO-UNDO.
DEFINE VARIABLE iWithoutCreate AS INTEGER NO-UNDO.
DEFINE VARIABLE iWithoutFind AS INTEGER NO-UNDO.
ETIME(TRUE).
DO i = 1 TO 1000:
CREATE ttWithIndex.
ttWithIndex.field1 = i.
END.
iWithCreate = ETIME.
ETIME(TRUE).
DO i = 1 TO 1000:
CREATE ttWithoutIndex.
ttWithoutIndex.field1 = i.
END.
iWithoutCreate = ETIME.
RELEASE ttWithIndex.
RELEASE ttWithoutIndex.
ETIME(TRUE).
DO i = 1 TO 1000:
FIND FIRST ttWithIndex WHERE ttWithIndex.field1 = i NO-ERROR.
END.
iWithFind = ETIME.
ETIME(TRUE).
DO i = 1 TO 1000:
FIND FIRST ttWithoutIndex WHERE ttWithoutIndex.field1 = i NO-ERROR.
END.
iWithoutFind = ETIME.
MESSAGE
"With index took" iWithFind "ms to find and" iWithCreate "ms to create" SKIP
"Without index took" iWithoutFind "ms to find and" iWithoutCreate "ms to create"
VIEW-AS ALERT-BOX.
與沒有索引相比,使用索引搜尋大約快 70 倍! 這只是一次執行,所以不是科學證明,但你的索引設定會產生影響。