From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id D55062288C for ; Mon, 2 Jul 2018 08:11:52 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id sgHAoztl87kX for ; Mon, 2 Jul 2018 08:11:52 -0400 (EDT) Received: from mail-lj1-f193.google.com (mail-lj1-f193.google.com [209.85.208.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 6C1BF2281D for ; Mon, 2 Jul 2018 08:11:52 -0400 (EDT) Received: by mail-lj1-f193.google.com with SMTP id p6-v6so1022467ljc.5 for ; Mon, 02 Jul 2018 05:11:52 -0700 (PDT) From: "N.Tatunov" Subject: [tarantool-patches] [PATCH] sql: assertion fail on nested select Date: Mon, 2 Jul 2018 15:11:40 +0300 Message-Id: <1530533500-9666-1-git-send-email-hollow653@gmail.com> Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-help: List-unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-subscribe: List-owner: List-post: List-archive: To: tarantool-patches@freelists.org Cc: alexander.turenko@tarantool.org, "N.Tatunov" To optimize the select-subquery tarantool uses subquery flattening function which is only used with respect to some restrictions. One of them was implemented improperly. Closes: #3353 --- Issue: https://github.com/tarantool/tarantool/issues/3353 Branch: https://github.com/tarantool/tarantool/tree/N_Tatunov/gh-3353-assertion-on-nested-select src/box/sql/select.c | 6 +++--- test/sql-tap/subquery.test.lua | 48 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 50 insertions(+), 4 deletions(-) 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 */ + } 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..d1e17b3 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( -- }) +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'); + ]], { + -- + 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); + ]], { + -- + 1, 'ORDER BY clause should come after UNION ALL not before' + -- + }) + +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); + ]], { + -- + 'abc','abc','abc','abc','abc','abc' + -- + }) +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); + ]], { + -- + 1, 'ORDER BY clause should come after UNION ALL not before' + -- + }) test:finish_test() -- 2.7.4