Fixes #3957 thanks for the report and nice find! The bug was the missing ORDER clause.

Also fixing the "look ahead code" to lookahead at most the visit standard length