LBiddiscombe
New Member
Hi,
There may be a blindingly obvious explanation for the following behaviour but, so far, I've missed it!
BTW, In practice I am use similar logic to break an output file into sizeable 5000 line chunks, so it has more of a purpose than this demonstration shows!...
Run the code as is, and as expected both result set counts are the same.
Now remove the "USE-INDEX main" line and run it again. The counts are different!?
Can anyone explain why??
DEFINE TEMP-TABLE t_item NO-UNDO
FIELD item-id AS INTEGER
FIELD item-desc AS CHARACTER
FIELD active AS LOGICAL
INDEX main AS PRIMARY UNIQUE item-id
INDEX active active.
DEFINE VARIABLE i AS INTEGER NO-UNDO.
DEFINE VARIABLE j AS INTEGER NO-UNDO.
DEFINE VARIABLE i-simple AS INTEGER NO-UNDO.
DEFINE VARIABLE i-split AS INTEGER NO-UNDO.
DEFINE VARIABLE i-last-item AS INTEGER NO-UNDO.
/* Build the dummy demo table */
DO i = 1 TO 10000:
CREATE t_item.
ASSIGN
t_item.item-id = i
t_item.item-desc = SUBSTITUTE("Item_&1", STRING(t_item.item-id))
t_item.active = (i MOD 2 = 0).
END.
/* count the active items */
FOR EACH t_item NO-LOCK WHERE t_item.active:
ASSIGN i-simple = i-simple + 1.
END.
/* count the actve items, in batches of 1000 */
split:
REPEAT:
FOR EACH t_item NO-LOCK WHERE
t_item.active AND
t_item.item-id >= i-last-item
USE-INDEX main
j = 1 TO 1000:
ASSIGN i-last-item = t_item.item-id i-split = i-split + 1.
END.
IF NOT AVAILABLE t_item THEN LEAVE split.
ELSE i-last-item = t_item.item-id.
END.
MESSAGE i-simple SKIP i-split
VIEW-AS ALERT-BOX INFO BUTTONS OK.
There may be a blindingly obvious explanation for the following behaviour but, so far, I've missed it!
BTW, In practice I am use similar logic to break an output file into sizeable 5000 line chunks, so it has more of a purpose than this demonstration shows!...
Run the code as is, and as expected both result set counts are the same.
Now remove the "USE-INDEX main" line and run it again. The counts are different!?
Can anyone explain why??
DEFINE TEMP-TABLE t_item NO-UNDO
FIELD item-id AS INTEGER
FIELD item-desc AS CHARACTER
FIELD active AS LOGICAL
INDEX main AS PRIMARY UNIQUE item-id
INDEX active active.
DEFINE VARIABLE i AS INTEGER NO-UNDO.
DEFINE VARIABLE j AS INTEGER NO-UNDO.
DEFINE VARIABLE i-simple AS INTEGER NO-UNDO.
DEFINE VARIABLE i-split AS INTEGER NO-UNDO.
DEFINE VARIABLE i-last-item AS INTEGER NO-UNDO.
/* Build the dummy demo table */
DO i = 1 TO 10000:
CREATE t_item.
ASSIGN
t_item.item-id = i
t_item.item-desc = SUBSTITUTE("Item_&1", STRING(t_item.item-id))
t_item.active = (i MOD 2 = 0).
END.
/* count the active items */
FOR EACH t_item NO-LOCK WHERE t_item.active:
ASSIGN i-simple = i-simple + 1.
END.
/* count the actve items, in batches of 1000 */
split:
REPEAT:
FOR EACH t_item NO-LOCK WHERE
t_item.active AND
t_item.item-id >= i-last-item
USE-INDEX main
j = 1 TO 1000:
ASSIGN i-last-item = t_item.item-id i-split = i-split + 1.
END.
IF NOT AVAILABLE t_item THEN LEAVE split.
ELSE i-last-item = t_item.item-id.
END.
MESSAGE i-simple SKIP i-split
VIEW-AS ALERT-BOX INFO BUTTONS OK.