[EMAIL PROTECTED] wrote:
Nathan Kurz <[EMAIL PROTECTED]> wrote:
SELECT uid, match("complex", "function", vector) AS match FROM vectors
ORDER BY match DESC LIMIT 20;
SELECT uid, mx FROM
(SELECT uid, match(...) AS mx FROM vectors LIMIT -1)
ORDER BY mx DESC LIMIT 20;
The LIMIT -1 on the subquery is to fake out the optimizer and prevent
it from folding the subquery back into the main query, resulting in the
same statement you started with. A "LIMIT -1" is effectively a no-op.
It does no limiting. But subqueries that contain a limit will not be
folded into outer queries that also contain a limit.
That strikes me as a hack, and also a matter of allowing implementation
to leak into interface. The current implementation seems to assume that
all functions are idempotent; once you allow user-defined functions,
that's no longer a safe assumption and it can lead to incorrect, as well
as inefficient, behavior if a user-defined function has side effects.