Subject Why PLAN token is not allowed after ORDER BY?
Author Alec Swan
Hello,

I am using FB 2.5 and execute SQL using Flamerobin. I am trying to
specify a plan for a query that has ORDER BY clause. I get a "invalid
token PLAN" error if I specify the plan after ORDER BY, but it works
OK if I specify the plan before ORDER BY. But the plan contains
instructions for ORDER BY as well. What's the problem?

This works:

SELECT FIRST (1000) *
FROM PHYSICAL_COPY INNER JOIN COPY ON PHYSICAL_COPY."COPY_ID" = COPY."ID"
WHERE (PHYSICAL_COPY."IS_DIRTY" = 1) AND (COPY."SOURCE_ID" =
'5d74876f-1b14-466a-aeee-f000b8b16512') AND
(PHYSICAL_COPY."COMMIT_NUMBER" >= 1000)

PLAN JOIN (PHYSICAL_COPY ORDER "IDX_214/CmDhH936xtHXcXNQKg=="
INDEX ("IDX_214/CmDhH936xtHXcXNQKg==", "IDX_4I5n6Ay0py37rBgakWZS3Q=="),
COPY INDEX ("PK_ZM6SRonqR8AHSQuCISgvnQ=="))
ORDER BY PHYSICAL_COPY."COMMIT_NUMBER" ASC

This DOES NOT WORK!!

SELECT FIRST (1000) *
FROM PHYSICAL_COPY INNER JOIN COPY ON PHYSICAL_COPY."COPY_ID" = COPY."ID"
WHERE (PHYSICAL_COPY."IS_DIRTY" = 1) AND (COPY."SOURCE_ID" =
'5d74876f-1b14-466a-aeee-f000b8b16512') AND
(PHYSICAL_COPY."COMMIT_NUMBER" >= 1000)
ORDER BY PHYSICAL_COPY."COMMIT_NUMBER" ASC

PLAN JOIN (PHYSICAL_COPY ORDER "IDX_214/CmDhH936xtHXcXNQKg=="
INDEX ("IDX_214/CmDhH936xtHXcXNQKg==", "IDX_4I5n6Ay0py37rBgakWZS3Q=="),
COPY INDEX ("PK_ZM6SRonqR8AHSQuCISgvnQ=="))

Message: isc_dsql_prepare failed
SQL Message : -104
Invalid token

Engine Code : 335544569
Engine Message :
Dynamic SQL Error
SQL error code = -104
Token unknown - line 6, column 1
PLAN