Subject Re: [Firebird-Architect] Uses of named s aka aliases
Author Arno Brinkman
Hi,

> However your quoting of the rules does beg the question about
> what to do with actual derived columns (expressions)...
>
> SELECT (ACOL + BCOL) AS XCOL
> FROM ATABLE
> WHERE XCOL = 25;
>
> Is this the same as:
>
> SELECT (ACOL + BCOL) AS XCOL
> FROM ATABLE
> WHERE (ACOL + BCOL) = 25;
>
> (ie. the derivation of the value is actually performed twice,
> which could be important in more complicated derivations)
>
> or will it be possible to make the alias actually reference
> the value from the extracted row data. eg:
>
> SELECT (ACOL + BCOL) AS XCOL
> FROM ATABLE
> WHERE <value of field 1> = 25;
>
> that is; like using an ordinal in an ORDER BY clause.

Currently a ORDER BY does exactly the same as your first option. There's no easy
way in the engine to create a reference to an other expression. The only
situations where this is used is by aggregates and unions. You can test this
very simple with a sub-select :

SELECT
(SELECT RDB$RELATION_ID FROM RDB$DATABASE)
FROM
RDB$DATABASE

PLAN (RDB$DATABASE NATURAL)
PLAN (RDB$DATABASE NATURAL)

Two PLANs

SELECT
(SELECT RDB$RELATION_ID FROM RDB$DATABASE)
FROM
RDB$DATABASE
ORDER BY
1

PLAN SORT ((RDB$DATABASE NATURAL))
PLAN (RDB$DATABASE NATURAL)
PLAN (RDB$DATABASE NATURAL)


Three PLANs, the sub-select is a new expression in the ORDER BY.
The same goes for GROUP BY <ordinal>

And Yes, this can/must be optimized in the future.

Regards,
Arno Brinkman
ABVisie

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Firebird open source database (based on IB-OE) with many SQL-99 features :
http://www.firebirdsql.org
http://www.firebirdsql.info
http://www.fingerbird.de/
http://www.comunidade-firebird.org/

Support list for Interbase and Firebird users :
firebird-support@yahoogroups.com

Nederlandse firebird nieuwsgroep :
news://newsgroups.firebirdsql.info