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

Vladislav Shpilevoy v.shpilevoy at tarantool.org
Mon Feb 25 15:58:35 MSK 2019


Hi! Thanks for the patch!

On 21/02/2019 21:01, Nikita Pettik wrote:
> Functions such as trim(), substr() etc should return result with
> collation derived from their arguments. So, lets add flag indicating
> that collation of first argument must be applied to function's result to
> SQL function definition. Using this flag, we can derive appropriate
> collation in sql_expr_coll().
> 
> Part of #3932
> ---
>   src/box/sql/analyze.c       |  6 +++---
>   src/box/sql/expr.c          | 23 +++++++++++++++++++++++
>   src/box/sql/func.c          | 22 +++++++++++-----------
>   src/box/sql/sqlInt.h        | 31 +++++++++++++++++++++++--------
>   test/sql/collation.result   | 28 ++++++++++++++++++++++++++++
>   test/sql/collation.test.lua | 11 +++++++++++
>   6 files changed, 99 insertions(+), 22 deletions(-)
> 
> diff --git a/src/box/sql/sqlInt.h b/src/box/sql/sqlInt.h
> index 2830ab639..5fb7285d8 100644
> --- a/src/box/sql/sqlInt.h
> +++ b/src/box/sql/sqlInt.h
> @@ -1633,6 +1633,13 @@ struct FuncDef {
>   	} u;
>   	/* Return type. */
>   	enum field_type ret_type;
> +	/**
> +	 * If function returns string, it may require collation
> +	 * to be applied on its result. For instance, result of
> +	 * substr() built-in function must have the same collation
> +	 * as its first argument.
> +	 */
> +	bool is_coll_derived;
>   };

This way works only for builtin functions taking not a
bind parameter ('?'). 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?

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?




More information about the Tarantool-patches mailing list