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 6C2452221B for ; Thu, 3 May 2018 13:19:24 -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 fRDAeH-5pgdl for ; Thu, 3 May 2018 13:19:24 -0400 (EDT) Received: from mail-lf0-f67.google.com (mail-lf0-f67.google.com [209.85.215.67]) (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 DEF7522219 for ; Thu, 3 May 2018 13:19:23 -0400 (EDT) Received: by mail-lf0-f67.google.com with SMTP id u21-v6so27098954lfu.9 for ; Thu, 03 May 2018 10:19:23 -0700 (PDT) MIME-Version: 1.0 References: <1525267540-23152-1-git-send-email-hollow653@gmail.com> <1CAC631B-C9A4-4DF3-9C89-706865E4AB4E@tarantool.org> In-Reply-To: From: Hollow111 Date: Thu, 03 May 2018 17:19:11 +0000 Message-ID: Subject: [tarantool-patches] Re: [PATCH] sql: analyze on VIEW lead to an assertion Content-Type: multipart/alternative; boundary="0000000000008a229d056b506773" 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: korablev@tarantool.org Cc: tarantool-patches@freelists.org --0000000000008a229d056b506773 Content-Type: text/plain; charset="UTF-8" I'm sorry it was wrong diff if the patch diff --git a/src/box/sql/analyze.c b/src/box/sql/analyze.c index f0054c5..6ac035b 100644 --- a/src/box/sql/analyze.c +++ b/src/box/sql/analyze.c @@ -1123,6 +1123,8 @@ analyzeDatabase(Parse * pParse) iTab = pParse->nTab; for (k = sqliteHashFirst(&pSchema->tblHash); k; k = sqliteHashNext(k)) { Table *pTab = (Table *) sqliteHashData(k); + if (space_is_view(pTab)) + continue; analyzeOneTable(pParse, pTab, 0, iStatCur, iMem, iTab); } loadAnalysis(pParse); @@ -1179,8 +1181,12 @@ sqlite3Analyze(Parse * pParse, Token * pName) /* Form 2: Analyze table named */ z = sqlite3NameFromToken(db, pName); if (z) { - if ((pTab = sqlite3LocateTable(pParse, 0, z)) != 0) { - analyzeTable(pParse, pTab, 0); + if ((pTab = sqlite3LocateTable(pParse, 0, z)) != NULL) { + if (space_is_view(pTab)) + sqlite3ErrorMsg(pParse, "VIEW isn't " + "allowed to be analyzed"); + else + analyzeTable(pParse, pTab, 0); } } sqlite3DbFree(db, z); diff --git a/test/sql-tap/analyzeD.test.lua b/test/sql-tap/analyzeD.test.lua index 8fdadf5..ef6aced 100755 --- a/test/sql-tap/analyzeD.test.lua +++ b/test/sql-tap/analyzeD.test.lua @@ -1,6 +1,6 @@ #!/usr/bin/env tarantool test = require("sqltester") -test:plan(9) +test:plan(15) testprefix = "analyzeD" @@ -139,5 +139,66 @@ test:do_execsql_test( -- }) +test:do_catchsql_test( + "analyzeD-1.9", + [[ + CREATE TABLE table1(id INT PRIMARY KEY, a INT); + CREATE VIEW v AS SELECT * FROM table1; + ANALYZE; + ]], { + -- + 0 + -- + }) + +test:do_execsql_test( + "analyzeD-1.10", + [[ + SELECT * FROM "_sql_stat4" WHERE "tbl" = 'v'; + ]], { + -- + + -- + }) + +test:do_execsql_test( + "analyzeD-1.11", + [[ + SELECT * FROM "_sql_stat1" WHERE "tbl" = 'v'; + ]], { + -- + + -- + }) + +test:do_catchsql_test( + "analyzeD-1.12", + [[ + ANALYZE v; + ]], { + -- + 1, "VIEW isn't allowed to be analyzed" + -- + }) + +test:do_execsql_test( + "analyzeD-1.13", + [[ + SELECT * FROM "_sql_stat4" WHERE "tbl" = 'v'; + ]], { + -- + + -- + }) + +test:do_execsql_test( + "analyzeD-1.14", + [[ + SELECT * FROM "_sql_stat1" WHERE "tbl" = 'v'; + ]], { + -- + + -- + }) test:finish_test() --0000000000008a229d056b506773 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
I'm sorry it was wrong diff if the patch

d= iff --git a/src/box/sql/analyze.c b/src/box/sql/analyze.c
index f= 0054c5..6ac035b 100644
--- a/src/box/sql/analyze.c
+++ = b/src/box/sql/analyze.c
@@ -1123,6 +1123,8 @@ analyzeDatabase(Par= se * pParse)
=C2=A0 iTab = =3D pParse->nTab;
=C2=A0 for (k =3D sqliteHashFirst(&pSchema->tblHash); k; k =3D sqliteHash= Next(k)) {
=C2=A0 Table *= pTab =3D (Table *) sqliteHashData(k);
+ if (space_is_view(pTab))
+ continue;
=C2=A0 analyzeOneTable(pParse, pTab, 0, iStatCur, iMem, iTab);
=C2=A0 }
=C2=A0 loadAnalysis(pParse);
@@ -1179,8 +1= 181,12 @@ sqlite3Analyze(Parse * pParse, Token * pName)
=C2=A0 /* Form 2:=C2=A0 Analyze table named = */
=C2=A0 z =3D sqlite3Na= meFromToken(db, pName);
=C2=A0 <= /span>if (z) {
- if ((pT= ab =3D sqlite3LocateTable(pParse, 0, z)) !=3D 0) {
- analyzeTable(pParse, pTab, 0);
+<= span style=3D"white-space:pre"> if ((pTab =3D sqlite3LocateTable(p= Parse, 0, z)) !=3D NULL) {
+ <= /span>if (space_is_view(pTab))
+ = sqlite3ErrorMsg(pParse, "VIEW isn't "
+<= span style=3D"white-space:pre"> "allowed to be analyzed&quo= t;);
+ else
+= analyzeTable(pParse, pTab, 0);<= /div>
=C2=A0 }
=C2= =A0 }
=C2=A0 sqlite3DbFree(db, z);
diff --git a/= test/sql-tap/analyzeD.test.lua b/test/sql-tap/analyzeD.test.lua
i= ndex 8fdadf5..ef6aced 100755
--- a/test/sql-tap/analyzeD.test.lua=
+++ b/test/sql-tap/analyzeD.test.lua
@@ -1,6 +1,6 @@
=C2=A0#!/usr/bin/env tarantool
=C2=A0test =3D require(&q= uot;sqltester")
-test:plan(9)
+test:plan(15)
=
=C2=A0
=C2=A0testprefix =3D "analyzeD"
= =C2=A0
@@ -139,5 +139,66 @@ test:do_execsql_test(
=C2= =A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0-- </1.8>
=C2=A0 =C2=A0 })
=C2=A0
+test:do_= catchsql_test(
+ "ana= lyzeD-1.9",
+ [[
+ CREATE TABLE table1(id INT = PRIMARY KEY, a INT);
+ CR= EATE VIEW v AS SELECT * FROM table1;
+ ANALYZE;
+ ]= ], {
+ -- <analyzeD-1.= 9>
+ 0
+ -- <analyzeD-1.9>
+ })
+
+test:do_exec= sql_test(
+ "analyzeD= -1.10",
+ [[
+ SELECT * FROM "_sql_stat4&= quot; WHERE "tbl" =3D 'v';
+ ]], {
+ -- <analyzeD-1.10>
+ <= /span>
+ -- <analyzeD-= 1.10>
+ })
+<= /div>
+test:do_execsql_test(
+ "analyzeD-1.11",
+ [[
+ SELECT *= FROM "_sql_stat1" WHERE "tbl" =3D 'v';
+ ]], {
+ -- <analyzeD-1.11>
+
+ = -- <analyzeD-1.11>
+ })
+
+test:do_catchsql_test(
+ "analyzeD-1.12",
+ [[
+ ANALYZE v;
+ ]], {
+ -- <analyz= eD-1.12>
+ 1, "VI= EW isn't allowed to be analyzed"
+ -- <analyzeD-1.12>
+ })
+
+test:do_execsql_test(
+ "analyzeD-1.13",
+ [[
+ SELECT * FROM "_sql_stat4" WHERE "= ;tbl" =3D 'v';
+ ]], {
+ -- <analyz= eD-1.13>
+
= + -- <analyzeD-1.13>
+ })
+
+test:d= o_execsql_test(
+ "an= alyzeD-1.14",
+ [[
+ SELECT * FROM "_sql_= stat1" WHERE "tbl" =3D 'v';
+ ]], {
+ -- <analyzeD-1.14>
+
+ -- <a= nalyzeD-1.14>
+ })
=C2=A0
=C2=A0test:finish_test()

--0000000000008a229d056b506773--