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 C5EDA2087B for ; Wed, 2 May 2018 09:25:58 -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 qEcGh5iFYqF7 for ; Wed, 2 May 2018 09:25:58 -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 686A82082B for ; Wed, 2 May 2018 09:25:58 -0400 (EDT) Received: by mail-lf0-f65.google.com with SMTP id b23-v6so20843125lfg.4 for ; Wed, 02 May 2018 06:25:57 -0700 (PDT) From: "N.Tatunov" Subject: [tarantool-patches] [PATCH] sql: analyze on VIEW lead to an assertion Date: Wed, 2 May 2018 16:25:40 +0300 Message-Id: <1525267540-23152-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: korablev@tarantool.org, "N.Tatunov" Currently analyze directly on VIEW or analyze on db containing a VIEW leads to an assertion. This patch adds few appropriate check to fix this problem. Closes #3324 --- Issue: https://github.com/tarantool/tarantool/issues/3324 Branch: https://github.com/tarantool/tarantool/tree/N_Tatunov/gh-3324-analyze-on-view src/box/sql/analyze.c | 10 ++++++++-- test/sql-tap/analyzeD.test.lua | 23 ++++++++++++++++++++++- 2 files changed, 30 insertions(+), 3 deletions(-) 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() -- 2.7.4