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(
-- </1.8>
})
+test:do_catchsql_test(
+ "analyzeD-1.9",
+ [[
+ CREATE TABLE table1(id INT PRIMARY KEY, a INT);
+ CREATE VIEW v AS SELECT * FROM table1;
+ ANALYZE;
+ ]], {
+ -- <analyzeD-1.9>
+ 0
+ -- <analyzeD-1.9>
+ })
+
+test:do_catchsql_test(
+ "analyzeD-1.10",
+ [[
+ ANALYZE v;
+ ]], {
+ -- <analyzeD-1.10>
+ 1, "VIEWs aren't allowed to be analyzed"
+ -- <analyzeD-1.10>
+ })
test:finish_test()