[Tarantool-patches] [PATCH v1 04/21] sql: refactor LENGTH() function

Mergen Imeev imeevma at tarantool.org
Tue Nov 2 14:39:21 MSK 2021


Thank you for the review! My answer below.

On Sat, Oct 30, 2021 at 01:42:49AM +0200, Vladislav Shpilevoy wrote:
> >>> diff --git a/src/box/sql/func.c b/src/box/sql/func.c
> >>> index e5d763be1..863dbf1c4 100644
> >>> --- a/src/box/sql/func.c
> >>> +++ b/src/box/sql/func.c
> >>> @@ -833,6 +833,19 @@ func_hex(struct sql_context *ctx, int argc, struct Mem *argv)
> >>>  	mem_set_str_allocated(ctx->pOut, str, size);
> >>>  }
> >>>  
> >>> +/** Implementation of the OCTET_LENGTH() function. */
> >>> +static void
> >>> +func_octet_length(struct sql_context *ctx, int argc, struct Mem *argv)
> >>
> >> Why is the function LENGTH defined as 'octet_length' instead of just 'length'?
> > ANSI defines two functions: CHAR_LENGTH() (with CHARACTER_LENGTH() as the other
> > name) and OCTET_LENGTH(). The first accepts only STRING values and returns the
> > length in characters or length in octets (depending on the USING clause). The
> > second accepts VARBINARY or STRING and returns the length in octets.
> > 
> > We have a LENGTH() function that returns the character length if the argument is
> > STRING, and the octet length if the argument is VARBINARY.
> > 
> > Since I am planning to introduce the USING clause, I find it better to use the
> > CHAR_LENGTH() and OCTET_LENGTH() implementations for LENGTH() depending on the
> > type of the argument. The func_octet_length() function will be used cases such
> > as this:
> > SELECT char_length(string_value USING OCTETS);
> > 
> > At the moment, I have no plans to introduce OCTET_LENGTH().
> 
> Does ANSI define 'USING' or 'OCTET_LENGTH'? Or both?
ANSI defines both. However CHAR_LENGTH(s USING <CHARACTERS or OCTETS>) defined
for STRING argument only, and OCTET_SIZE() defined for both STRING and
VARBINARY.



More information about the Tarantool-patches mailing list