Tarantool development patches archive
 help / color / mirror / Atom feed
From: Nikita Tatunov <hollow653@gmail.com>
To: korablev@tarantool.org
Cc: tarantool-patches@freelists.org
Subject: [tarantool-patches] Re: [PATCH] sql: assertion fail on nested select
Date: Thu, 19 Jul 2018 15:47:04 +0300	[thread overview]
Message-ID: <CAEi+_apsi6mHUMv6RPVwN8vaRStdw7ULqF6oaq9sx9fnYUiJww@mail.gmail.com> (raw)
In-Reply-To: <A93655E5-CB38-41D9-AA7A-872CD8D9F77E@tarantool.org>

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

ср, 18 июл. 2018 г. в 23:36, n.pettik <korablev@tarantool.org>:

>
> > diff --git a/src/box/sql/select.c b/src/box/sql/select.c
> > index 54f78a9..c035691 100644
> > --- a/src/box/sql/select.c
> > +++ b/src/box/sql/select.c
> > @@ -3893,14 +3893,14 @@ flattenSubquery(Parse * pParse,               /*
> Parsing context */
> >        * queries.
> >        */
> >       if (pSub->pPrior) {
> > -             if (pSub->pOrderBy) {
> > -                     return 0;       /* Restriction 20 */
> > -             }
> >               if (isAgg || (p->selFlags & SF_Distinct) != 0
> >                   || pSrc->nSrc != 1) {
> >                       return 0;
> >               }
> >               for (pSub1 = pSub; pSub1; pSub1 = pSub1->pPrior) {
> > +                     if (pSub1->pOrderBy) {
> > +                             return 0;       /* Restriction 20 */
> > +                     }
>
> According to our code style:
> - use explicit != NULL comparison;
> - don’t put bracers around one-line if statement;
> - put comment above the code to be commented;
>
>
Fixed.


> >diff --git a/test/sql-tap/subquery.test.lua
> b/test/sql-tap/subquery.test.lua
> >--- a/test/sql-tap/subquery.test.lua
> >+++ b/test/sql-tap/subquery.test.lua
> >+test:do_execsql_test(
> >+       "subquery-9.2",
> >+       [[
> >+               SELECT 'abc' FROM (SELECT * FROM table1 UNION ALL
> >+                                   SELECT * FROM table1 UNION ALL
> >+                                  SELECT * FROM table1 ORDER BY 1);
> >+       ]], {
> >+               -- <subquery-9.2>
> >+               'abc','abc','abc','abc','abc','abc'
> >+               -- <subquery-9.2>
> >+       })
>
> Why did you use here SELECT ‘abc’ and in other tests - SELECT *?
> It is nitpicking, but just tests look a little weird..


Yes, kind of weird. Why not though?
Fixed, anyways.

Diff:

diff --git a/src/box/sql/select.c b/src/box/sql/select.c
index 54f78a9..1a6b034 100644
--- a/src/box/sql/select.c
+++ b/src/box/sql/select.c
@@ -3893,14 +3893,14 @@ flattenSubquery(Parse * pParse, /* Parsing context
*/
  * queries.
  */
  if (pSub->pPrior) {
- if (pSub->pOrderBy) {
- return 0; /* Restriction 20 */
- }
  if (isAgg || (p->selFlags & SF_Distinct) != 0
      || pSrc->nSrc != 1) {
  return 0;
  }
  for (pSub1 = pSub; pSub1; pSub1 = pSub1->pPrior) {
+ /* Restriction 20 */
+ if (pSub1->pOrderBy != NULL)
+ return 0;
  testcase((pSub1->
    selFlags & (SF_Distinct | SF_Aggregate)) ==
  SF_Distinct);
diff --git a/test/sql-tap/subquery.test.lua b/test/sql-tap/subquery.test.lua
index 06631c1..8fde62d 100755
--- a/test/sql-tap/subquery.test.lua
+++ b/test/sql-tap/subquery.test.lua
@@ -1,6 +1,6 @@
 #!/usr/bin/env tarantool
 test = require("sqltester")
-test:plan(69)
+test:plan(73)

 --!./tcltestrunner.lua
 -- 2005 January 19
@@ -926,6 +926,52 @@ test:do_execsql_test(
         -- </subquery-8.1>
     })

+test:do_catchsql_test(
+ "subquery-9.0",
+ [[
+ DROP TABLE IF EXISTS table1;
+ CREATE TABLE table1 (id VARCHAR(100) PRIMARY KEY);
+ INSERT INTO table1 VALUES ('abc'), ('abd');
+ ]], {
+ -- <subquery-9.0>
+ 0
+ -- <subquery-9.0>
+ })
+
+test:do_catchsql_test(
+ "subquery-9.1",
+ [[
+ SELECT * FROM (SELECT * FROM table1 UNION ALL
+                               SELECT * FROM table1 ORDER BY 1 UNION ALL
+        SELECT * FROM table1);
+ ]], {
+ -- <subquery-9.1>
+ 1, 'ORDER BY clause should come after UNION ALL not before'
+ -- <subquery-9.1>
+ })
+
+test:do_execsql_test(
+ "subquery-9.2",
+ [[
+ SELECT * FROM (SELECT * FROM table1 UNION ALL
+                                   SELECT * FROM table1 UNION ALL
+    SELECT * FROM table1 ORDER BY 1);
+ ]], {
+ -- <subquery-9.2>
+ 'abc', 'abc', 'abc', 'abd', 'abd', 'abd'
+ -- <subquery-9.2>
+ })

+test:do_catchsql_test(
+ "subquery-9.3",
+ [[
+ SELECT * FROM (SELECT * FROM table1 ORDER BY 1 UNION ALL
+                               SELECT * FROM table1 UNION ALL
+        SELECT * FROM table1);
+ ]], {
+             -- <subquery-9.3>
+             1, 'ORDER BY clause should come after UNION ALL not before'
+             -- <subquery-9.3>
+ })

 test:finish_test()

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

  reply	other threads:[~2018-07-19 12:47 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-02 12:11 [tarantool-patches] " N.Tatunov
2018-07-17 13:59 ` [tarantool-patches] " Alexander Turenko
2018-07-18 12:34   ` Nikita Tatunov
2018-07-18 13:41     ` Nikita Tatunov
     [not found]       ` <07E4F387-E976-432B-A80B-E01B40BCF126@corp.mail.ru>
2018-07-18 15:37         ` Nikita Tatunov
2018-07-18 16:51           ` Alexander Turenko
2018-07-18 20:36 ` n.pettik
2018-07-19 12:47   ` Nikita Tatunov [this message]
2018-07-19 13:09     ` n.pettik
2018-07-19 15:22       ` Vladislav Shpilevoy
2018-07-20 13:21 ` 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=CAEi+_apsi6mHUMv6RPVwN8vaRStdw7ULqF6oaq9sx9fnYUiJww@mail.gmail.com \
    --to=hollow653@gmail.com \
    --cc=korablev@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --subject='[tarantool-patches] Re: [PATCH] sql: assertion fail on nested select' \
    /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