[tarantool-patches] Re: [PATCH 1/2] sql: derive collation for built-in functions

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Thu Mar 7 17:40:24 MSK 2019



>> For user-defined functions and for
>> bind parameters it does not fit. How can you determine
>> a function's result collation, if it is not builtin, and
>> does not depend on arguments?
> 
> In no way. We can extend signature of sql_create_function
> and allow to pass collation to be applied to returning value.
> But I am not sure that we should do this. Anyway, it wouldn't
> help us with the initial issue: in our case collation is dependent
> on one of arguments, so it *dynamically* changes. Hence, I
> guess these problems are barely related.
> 
> Also, inlining comment from P.Gulutzan:
> (https://github.com/tarantool/tarantool/issues/3932)
> 
> ‘’'
> 
> It is true that user-defined functions will not know some things about
> what an SQL caller is passing. We don't promise that they will, so I
> think it is okay that it is the caller's responsibility to make sure
> relevant information is passed explicitly. A possible issue is that the
> function cannot use the utf8 module for all possible collations, but
> that is not an SQL issue.
> 
> ‘''

So do you mean that any string returned from a user defined function
always has no any collation?

I do not talk about Lua functions only. In future we are going to
introduce SQL functions.

> 
>> Does SQL standard allow to define user functions without
>> a runtime defined collation? If SQL standard does not define
>> SQL functions at all, then what other vendors do with that
>> problem?
> 
> There’s no such opportunity in ANSI, if I’m not mistaking.
> Generally speaking, other vendors have procedural SQL.
> And since PSQL is a part of SQL, there are no such problems:
> collation is a part of string-like types.
> 

It contradicts with your way of collation return. If PSQL states
that collation is a part of string-like type, then it is
possible to implement a function doing something like this:

     function my_func()
         if (rand() % 2 == 0) then
             return 'abc' collate 'unicode_ci';
         return 'abc' collate 'unicode';
     end;

(I do not know PSQL syntax - the code above is pseudo- ).

As I see, now we have no runtime defined collations at all -
all of them are known during compilation. Struct Mem, storing
function return value, even has no collation member. I guess,
we can not implement runtime collations now.




More information about the Tarantool-patches mailing list