This what is so great and yet limiting about SQL. Carefully optimized implementations, but only for a fixed set of built-in functions. Are there any frameworks which allow user-defined functions to gain some of these optimization benefits without exposing the full internals of the data-store implementation to them?