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

Mergen Imeev imeevma at tarantool.org
Mon Oct 25 11:30:09 MSK 2021


Thank you for the review! My answer below.

On Fri, Oct 15, 2021 at 12:43:33AM +0200, Vladislav Shpilevoy wrote:
> Thanks for the patch!
> 
> On 08.10.2021 19:31, imeevma at tarantool.org wrote:
> > Part of #4145
> > ---
> >  src/box/sql/func.c | 55 +++++++++++++---------------------------------
> >  1 file changed, 15 insertions(+), 40 deletions(-)
> > 
> > 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().


More information about the Tarantool-patches mailing list