db-derby-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Daniel John Debrunner <...@debrunners.com>
Subject Re: About improvement of DERBY-134
Date Sat, 12 Mar 2005 01:17:31 GMT
Jack Klebanoff wrote:


> I think that most people would be surprised to find that "ORDER BY 1 +
> 1" behaves differently than "ORDER BY 2". I also think that it is
> simpler for us to treat all integer constants the same. It is hard to
> get the parser to distinguish between a literal constant and a complex
> expression that starts with an integer literal. That is why Tomohito
> Nakayama needed to use complex lookahead in his parser change.
> 
> I think that it is better to distinguish between integer constants and
> other expressions in the OrderByColumn class. ValueNodes have
> isConstantExpression(), getTypeID(), and getConstantValueAsObject()
> methods that OrderByColumn can use to see if the expression is an
> integer constant and, if so, what the value is. OrderByColumn can test
> whether the order by expression is an instanceOf ColumnReference or
> ResultColumn to special case a simple column reference. This simplifies
> the parser significantly and causes us to treat "ORDER BY 1 + 1" the
> same as "ORDER BY 2".

Whichever path is taken, we need some very clearly defined rules, such
that we understand what the sort order will be with different
expressions. I'm nervous about sometimes expressions map to values and
sometimes to column positions.

If C1 is an integer column, then is

ORDER BY C1/C1 the same as ORDER BY 1

??

I can imagine a compiler in the future that looked for constant
expressions and replaced them with actual constants, that code should
not care about what is in the tree above it.

If it made it clearer I would prefer that a compilation error is raised
for order by expressions that do resolve to constants, since supporting
them adds no value. How this error would be raised I'm not sure about.

ORDER BY 1 - ok (column position 1)
ORDER BY C1 - ok
ORDER BY FN(C1) - ok
ORDER BY 1 + 1 - disallow
ORDER BY C1/C1 - disallow

Dan.


Mime
View raw message