Tarantool development patches archive
 help / color / mirror / Atom feed
From: "n.pettik" <korablev@tarantool.org>
To: tarantool-patches@freelists.org
Cc: Roman Khabibov <roman.habibov@tarantool.org>
Subject: [tarantool-patches] Re: [PATCH 1/2 v2] test: check that collations isn't ignored in SELECTs
Date: Tue, 2 Jul 2019 20:21:02 +0300	[thread overview]
Message-ID: <B937E18B-8AAB-4112-9BAC-0B7822C32158@tarantool.org> (raw)
In-Reply-To: <AE5F8A72-D7CD-40A0-BC72-34CD56EC396D@tarantool.org>

[-- Attachment #1: Type: text/plain, Size: 4730 bytes --]



> On 28 Jun 2019, at 16:11, Roman Khabibov <roman.habibov@tarantool.org> wrote:
> 
> Hi! Thanks for the review.
> 
>> On Jun 25, 2019, at 8:30 PM, n.pettik <korablev@tarantool.org <mailto:korablev@tarantool.org>> wrote:
>>> On 24 Jun 2019, at 13:54, Roman Khabibov <roman.habibov@tarantool.org <mailto:roman.habibov@tarantool.org>> wrote:
>>> 
>>> Add test to check that a new collation isn't ignored regardless
>>> of a name of a previous one in the following patterns of quries:
>> 
>> Nit: quries -> queries
> Fixed.
> 
>>> 
>>> SELECT s COLLATE "unicode_ci" FROM a ORDER BY s COLLATE “unicode_ci"
>> 
>> Why do you consider this kind of query? What can be wrong with it?
>> Specifying collation for result set members doesn’t make much sense btw.
> I consider it, because it didn’t work after my addition of checking from the
> second patch:
> +static int
> +check_collate_arg(struct Parse *parse, struct Expr *expr)
> +{
> +	struct Expr *left = expr->pLeft;
> +	while (left->op == TK_COLLATE)
> +		left = left->pLeft;
> +	enum field_type type = sql_expr_type(left);
> +	if (type != FIELD_TYPE_STRING && type != FIELD_TYPE_SCALAR) {
> +		diag_set(ClientError, ER_SQL_PARSER_GENERIC,
> +			 "COLLATE clause can't be used with non-string "
> +			 "arguments");
> +		parse->is_aborted = true;
> +		return -1;
> +	}
> +	return 0;
> +}
> The tree of this query included sequence of collations on left nodes. This is
> the result of optimizations in multiSelectOrderBy. Now I can not exactly say how
> It occurs. At first time, I didn’t use loop to descend throughout left nodes.
> I added this loop, because of that reason.

Wait, in the example like this:

 SELECT s COLLATE "unicode_ci" FROM a ORDER BY s COLLATE “unicode_ci"

collate clauses refer to independent parts of query and
can’t contradict to each other. As I already said:

"First one is used during sorting
routines, second one is simply ignored (since values of
resulting set are not supposed to be compared with anything else)."

Why then are they organised into list? Please, investigate reasons
of this “optimisation”.

>>> Also note: It is disallowed to compare strings with different
>>> collations: ISO/IEC JTC 1/SC 32, Part 2: Foundation, page 531
>>> ---
>>> src/box/sql/resolve.c           |  7 +++++++
>>> test/sql-tap/collation.test.lua | 19 ++++++++++++++++++-
>>> 2 files changed, 25 insertions(+), 1 deletion(-)
>>> 
>>> diff --git a/src/box/sql/resolve.c b/src/box/sql/resolve.c
>>> index fdf3703da..348b3ea9a 100644
>>> --- a/src/box/sql/resolve.c
>>> +++ b/src/box/sql/resolve.c
>>> @@ -109,6 +109,13 @@ resolveAlias(Parse * pParse,	/* Parsing context */
>>> 		return;
>>> 	if (zType[0] != 'G')
>>> 		incrAggFunctionDepth(pDup, nSubquery);
>>> +	/*
>>> +	 * If there was typed more than one explicit collations in
>>> +	 * query, it will be a sequence of left nodes with the
>>> +	 * collations in a tree. There is nothing special about
>>> +	 * keeping the sequence. Only one collation could be
>>> +	 * stored, but the present solution is simpler.
>>> +	 */
>> 
>> Do not understand how mentioned example is related to this code.
>> I suppose you might mean example like:
>> 
>> SELECT s COLLATE “unicode” COLLATE “binary” COLLATE “unicode_ci” …
>> 
>> Is this syntax allowed by ANSI? If so, which one (first or last) collation must be used?
>> 
>>> 	if (pExpr->op == TK_COLLATE) {
>>> 		pDup =
>>> 		    sqlExprAddCollateString(pParse, pDup, pExpr->u.zToken);
>>> diff --git a/test/sql-tap/collation.test.lua b/test/sql-tap/collation.test.lua
>>> index 79547361c..f36540fc2 100755
>>> --- a/test/sql-tap/collation.test.lua
>>> +++ b/test/sql-tap/collation.test.lua
>>> @@ -1,6 +1,6 @@
>>> #!/usr/bin/env tarantool
>>> test = require("sqltester")
>>> -test:plan(174)
>>> +test:plan(177)
>>> 
>>> local prefix = "collation-"
>>> 
>>> @@ -529,4 +529,21 @@ test:do_catchsql_test(
>>>       'CREATE TABLE test3 (a int, b int, c int, PRIMARY KEY (a, a COLLATE foo, b, c))',
>>>       {1, "Collation 'FOO' does not exist"})
>>> 
>>> +-- gh-3805 Check that collation is not ignored.
>> 
>> Why these test cases are related to the mentioned ticket?
>> Which collation might be ignored? I see two collations in
>> two different parts of query. First one is used during sorting
>> routines, second one is simply ignored (since values of
>> resulting set are not supposed to be compared with anything else).
> See above.

See above what?:) Please drop this commit or provide
decent explanation. Now I can’t understand how provided
test is related to the ticket and what’s wrong with this case
at all.


[-- Attachment #2: Type: text/html, Size: 39478 bytes --]

  parent reply	other threads:[~2019-07-02 17:21 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1561372731.git.roman.habibov@tarantool.org>
     [not found] ` <49f3a1279811efc66c580c6039cf1b890ff37889.1561372731.git.roman.habibov@tarantool.org>
2019-06-25 17:30   ` n.pettik
2019-06-25 17:55     ` Vladislav Shpilevoy
2019-06-28 13:11     ` Roman Khabibov
2019-06-28 13:13       ` Roman Khabibov
2019-07-02 17:21       ` n.pettik [this message]
     [not found] ` <91edd7e8b72a93c5b5c0592c181576fca98e66fd.1561372731.git.roman.habibov@tarantool.org>
2019-06-25 17:30   ` [tarantool-patches] Re: [PATCH 2/2 v2] sql: allow <COLLATE> only for string-like args n.pettik
2019-06-28 12:57     ` Roman Khabibov
2019-07-02 15:55       ` n.pettik
2019-07-06  1:04         ` Roman Khabibov
2019-07-08 13:38           ` n.pettik
2019-07-16 13:09     ` Kirill Yukhin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=B937E18B-8AAB-4112-9BAC-0B7822C32158@tarantool.org \
    --to=korablev@tarantool.org \
    --cc=roman.habibov@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='[tarantool-patches] Re: [PATCH 1/2 v2] test: check that collations isn'\''t ignored in SELECTs' \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox