Subject Re: [firebird-support] Why PLAN token is not allowed after ORDER BY?
Author Mark Rotteveel
On 3-6-2012 3:05, Alec Swan wrote:
> I would have never expected a parser token error if the query syntax is
> correct but the plan itself is bad. That would have been a run-time, not
> compile-time error!
>
> And I just verified that what I am saying looks like an FB bug. Here is a
> very simple example that reproduces the bug:
>
> create table T (a int);
> create asc index idx_Ta on T (a);
> select * from T order by a; -- generates PLAN (T ORDER IDX_TA)
> select * from T order by a PLAN (T ORDER IDX_TA);
> ERROR: An "Invalid token ... Token unknown - line 4, column 28 PLAN"
>
> Is there a workaround for specifying PLAN after ORDER BY?


No you cannot, because the grammar of Firebird expects it to be before.

Simply put the grammar specification contains (simplified):
select_expr : with_clause select_expr_body order_clause rows_clause
select_expr_body : query_term
query_term : query_spec
query_spec : SELECT limit_clause
distinct_clause
select_list
from_clause
where_clause
group_clause
having_clause
===> plan_clause

As you can see: the plan_clause is part of the select_expr_body, which
is followed by the order_clause.

Mark

--
Mark Rotteveel