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 8919221FEA for ; Thu, 3 May 2018 13:16:46 -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 jWB2SPHfi8VT for ; Thu, 3 May 2018 13:16:46 -0400 (EDT) Received: from mail-lf0-f65.google.com (mail-lf0-f65.google.com [209.85.215.65]) (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 060C321FDD for ; Thu, 3 May 2018 13:16:45 -0400 (EDT) Received: by mail-lf0-f65.google.com with SMTP id w8-v6so27121748lfe.3 for ; Thu, 03 May 2018 10:16:45 -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: <1CAC631B-C9A4-4DF3-9C89-706865E4AB4E@tarantool.org> From: Hollow111 Date: Thu, 03 May 2018 17:16:33 +0000 Message-ID: Subject: [tarantool-patches] Re: [PATCH] sql: analyze on VIEW lead to an assertion Content-Type: multipart/alternative; boundary="00000000000022cf36056b505ede" 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 --00000000000022cf36056b505ede Content-Type: text/plain; charset="UTF-8" Diff for the newer version of patch after fixing remarks: diff --git a/src/box/sql/analyze.c b/src/box/sql/analyze.c index f0054c5..d95d534 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))) { + if (space_is_view(pTab)) + sqlite3ErrorMsg(pParse, "VIEWs aren'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..5d25a1d 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(11) testprefix = "analyzeD" @@ -139,5 +139,26 @@ 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_catchsql_test( + "analyzeD-1.10", + [[ + ANALYZE v; + ]], { + -- + 1, "VIEWs aren't allowed to be analyzed" + -- + }) test:finish_test() --00000000000022cf36056b505ede Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
Diff for the newer version of patch after fixing remarks:<= div>
=C2=A0
diff --git a/src/box/sql/analyze.c= b/src/box/sql/analyze.c
index f0054c5..d95d534 100644
= --- a/src/box/sql/analyze.c
+++ b/src/box/sql/analyze.c
@@ -1123,6 +1123,8 @@ analyzeDatabase(Parse * pParse)
=C2=A0 iTab =3D pParse->nTab;
=C2= =A0 for (k =3D sqliteHashFirst(&= pSchema->tblHash); k; k =3D sqliteHashNext(k)) {
=C2=A0 Table *pTab =3D (Table *) sqliteHashData(= k);
+ if (space_is_view(p= Tab))
+ continue;
<= div>=C2=A0 analyzeOneTable(pParse, = pTab, 0, iStatCur, iMem, iTab);
=C2=A0 }
=C2=A0 load= Analysis(pParse);
@@ -1179,8 +1181,12 @@ sqlite3Analyze(Parse * p= Parse, Token * pName)
=C2=A0 /* Form 2:=C2=A0 Analyze table named */
=C2=A0 z =3D sqlite3NameFromToken(db, pName);
= =C2=A0 if (z) {
- if ((pTab =3D sqlite3LocateTable(pParse, = 0, z)) !=3D 0) {
- anal= yzeTable(pParse, pTab, 0);
+ if ((pTab =3D sqlite3LocateTable(pParse, 0, z))) {
+ if (space_is_view(pTab))
+ sqlite3ErrorMsg(pParse, "VIEWs= aren't "
+ &= quot;allowed to be analyzed");
+ else
+ = analyzeTable(pParse, pTab, 0);
=C2=A0 }
=C2=A0 }<= /div>
=C2=A0 sqlite3DbFree(db, = z);
diff --git a/test/sql-tap/analyzeD.test.lua b/test/sql-tap/an= alyzeD.test.lua
index 8fdadf5..5d25a1d 100755
--- a/tes= t/sql-tap/analyzeD.test.lua
+++ b/test/sql-tap/analyzeD.test.lua<= /div>
@@ -1,6 +1,6 @@
=C2=A0#!/usr/bin/env tarantool
=C2=A0test =3D require("sqltester")
-test:plan(9)
+test:plan(11)
=C2=A0
=C2=A0testprefix =3D "= ;analyzeD"
=C2=A0
@@ -139,5 +139,26 @@ test:do_exe= csql_test(
=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0-- </1.8>
=C2=A0 =C2=A0 })
= =C2=A0
+test:do_catchsql_test(
+ "analyzeD-1.9",
+ [[
+ C= REATE TABLE table1(id INT PRIMARY KEY, a INT);
+ CREATE VIEW v AS SELECT * FROM table1;
+<= span style=3D"white-space:pre"> ANALYZE;
+ ]], {
+ = -- <analyzeD-1.9>
+= 0
+ -- <analy= zeD-1.9>
+ })
+
+test:do_catchsql_test(
+ "analyzeD-1.10",
+ [[
+ ANAL= YZE v;
+ ]], {
+= -- <analyzeD-1.10>
+ 1, "VIEWs aren't allowe= d to be analyzed"
+ = -- <analyzeD-1.10>
+ })
=C2=A0
=C2=A0test:finish_test()
--00000000000022cf36056b505ede--