On Wed, 2005-03-23 at 09:02 -0500, Thomas Briggs wrote:
>    Bearing in mind that I'm aware of the published workaround for
> COUNT(DISTINCT x), and also that as of yet I know nothing of the
> internals of SQLite: what would be involved in extending SQLite to
> support the traditional "COUNT(DISTINCT x)" syntax?  Is this something
> that hasn't been done because the workaround has always been sufficient,
> or something that would require a complete redesign to be feasible?
> 

This would require a major redesign.

Functions are parsed as    function-name "(" expression "," ... ")"
So the first rework would be to somehow allow the "DISTINCT" keyword for
the
"COUNT" function while disallowing it elsewhere.

Functions are implemented by calling a function at the appropriate
time.  (See the sqlite3_create_function API.)  Functions do not
fundamentally change the processing of a statement.  The parser and
code generate doe not know anything about functions other than a
pointer to the C-procedure used to implement them.  But to
implement COUNT(DISTINCT) all that would have to change.  The
COUNT(DISTINCT) function would have to be handled separately.
The parser and code generator would have to generate completely
different VM code to implement an SQL statement depending on 
whether or not a COUNT(DISTINCT) was present or not.

The sqlite3_create_function API currently allows the user to
override any function.  If COUNT(DISTINCT) where implemented, this
would have to change to make an exception for the COUNT() function,
presumably.  Or else the parser/code generator would have to detect
that COUNT() had been overloaded and not do its special processing
for COUNT(DISTINCT) and in fact disallow COUNT(DISTINCT).

These are just a few of the complications that spring to mind.
I'm sure I would think of others if I spent some time on the
subject.
-- 
D. Richard Hipp <[EMAIL PROTECTED]>

Reply via email to