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 D36632177D for ; Sat, 28 Apr 2018 14:27:10 -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 Tyr80iDORAYS for ; Sat, 28 Apr 2018 14:27:10 -0400 (EDT) Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 8FA0E21747 for ; Sat, 28 Apr 2018 14:27:10 -0400 (EDT) From: Kirill Shcherbatov Subject: [tarantool-patches] [PATCH v4 6/7] sql: start using is_view field from space_def Date: Sat, 28 Apr 2018 21:26:57 +0300 Message-Id: <705209b9a9caee1fcdd8e4887810f62ae831978b.1524939875.git.kshcherbatov@tarantool.org> In-Reply-To: References: In-Reply-To: References: 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: v.shpilevoy@tarantool.org, Kirill Shcherbatov Part of #3272. --- src/box/sql.c | 2 ++ src/box/sql/build.c | 24 +++++++++++++++++------- src/box/sql/delete.c | 9 ++++++--- src/box/sql/expr.c | 3 ++- src/box/sql/select.c | 2 ++ src/box/sql/update.c | 3 ++- 6 files changed, 31 insertions(+), 12 deletions(-) diff --git a/src/box/sql.c b/src/box/sql.c index 47f7cb1..9f5a124 100644 --- a/src/box/sql.c +++ b/src/box/sql.c @@ -1511,6 +1511,8 @@ int tarantoolSqlite3MakeTableOpts(Table *pTable, const char *zSql, void *buf) bool is_view = false; if (pTable != NULL) is_view = pTable->pSelect != NULL; + assert(!pTable || pTable->def->opts.is_view == is_view); + p = enc->encode_map(base, is_view ? 2 : 1); p = enc->encode_str(p, "sql", 3); p = enc->encode_str(p, zSql, strlen(zSql)); diff --git a/src/box/sql/build.c b/src/box/sql/build.c index 4e0ae87..a98a6bd 100644 --- a/src/box/sql/build.c +++ b/src/box/sql/build.c @@ -1844,7 +1844,8 @@ sqlite3EndTable(Parse * pParse, /* Parse context */ if (db->init.busy) p->tnum = db->init.newTnum; - if (!p->pSelect) { + assert(p->def->opts.is_view == (p->pSelect != NULL)); + if (!p->def->opts.is_view) { if ((p->tabFlags & TF_HasPrimaryKey) == 0) { sqlite3ErrorMsg(pParse, "PRIMARY KEY missing on table %s", @@ -1892,7 +1893,8 @@ sqlite3EndTable(Parse * pParse, /* Parse context */ /* * Initialize zType for the new view or table. */ - if (p->pSelect == 0) { + assert(p->def->opts.is_view == (p->pSelect != NULL)); + if (!p->def->opts.is_view) { /* A regular table */ zType = "TABLE"; #ifndef SQLITE_OMIT_VIEW @@ -1921,7 +1923,9 @@ sqlite3EndTable(Parse * pParse, /* Parse context */ if (pSelect) { zStmt = createTableStmt(db, p); } else { - Token *pEnd2 = p->pSelect ? &pParse->sLastToken : pEnd; + assert(p->def->opts.is_view == (p->pSelect != NULL)); + Token *pEnd2 = p->def->opts.is_view ? + &pParse->sLastToken : pEnd; n = (int)(pEnd2->z - pParse->sNameToken.z); if (pEnd2->z[0] != ';') n += pEnd2->n; @@ -1933,7 +1937,8 @@ sqlite3EndTable(Parse * pParse, /* Parse context */ iSpaceId = getNewSpaceId(pParse); createSpace(pParse, iSpaceId, zStmt); /* Indexes aren't required for VIEW's. */ - if (p->pSelect == NULL) { + assert(p->def->opts.is_view == (p->pSelect != NULL)); + if (!p->def->opts.is_view) { createImplicitIndices(pParse, iSpaceId); } @@ -1981,7 +1986,8 @@ sqlite3EndTable(Parse * pParse, /* Parse context */ current_session()->sql_flags |= SQLITE_InternChanges; #ifndef SQLITE_OMIT_ALTERTABLE - if (!p->pSelect) { + assert(p->def->opts.is_view == (p->pSelect != NULL)); + if (!p->def->opts.is_view) { const char *zName = (const char *)pParse->sNameToken.z; int nName; assert(!pSelect && pCons && pEnd); @@ -2033,6 +2039,7 @@ sqlite3CreateView(Parse * pParse, /* The parsing context */ * they will persist after the current sqlite3_exec() call returns. */ p->pSelect = sqlite3SelectDup(db, pSelect, EXPRDUP_REDUCE); + p->def->opts.is_view = true; p->pCheck = sqlite3ExprListDup(db, pCNames, EXPRDUP_REDUCE); if (db->mallocFailed) goto create_view_fail; @@ -2119,6 +2126,7 @@ sqlite3ViewGetColumnNames(Parse * pParse, Table * pTable) * statement that defines the view. */ assert(pTable->pSelect); + assert(pTable->def->opts.is_view == (pTable->pSelect != NULL)); pSel = sqlite3SelectDup(db, pTable->pSelect, 0); if (pSel) { n = pParse->nTab; @@ -2197,7 +2205,8 @@ sqliteViewResetAll(sqlite3 * db) for (i = sqliteHashFirst(&db->pSchema->tblHash); i; i = sqliteHashNext(i)) { Table *pTab = sqliteHashData(i); - if (pTab->pSelect) { + assert(pTab->def->opts.is_view == (pTab->pSelect != NULL)); + if (pTab->def->opts.is_view) { sqlite3DeleteColumnNames(db, pTab); struct space_def *old_def = pTab->def; assert(old_def->opts.temporary == false); @@ -2920,7 +2929,8 @@ sqlite3CreateIndex(Parse * pParse, /* All information about this parse */ assert(pTab != 0); assert(pParse->nErr == 0); #ifndef SQLITE_OMIT_VIEW - if (pTab->pSelect) { + assert(pTab->def->opts.is_view == (pTab->pSelect != NULL)); + if (pTab->def->opts.is_view) { sqlite3ErrorMsg(pParse, "views may not be indexed"); goto exit_create_index; } diff --git a/src/box/sql/delete.c b/src/box/sql/delete.c index c6ecba6..37baca2 100644 --- a/src/box/sql/delete.c +++ b/src/box/sql/delete.c @@ -283,7 +283,8 @@ sqlite3DeleteFrom(Parse * pParse, /* The parser context */ */ #ifndef SQLITE_OMIT_TRIGGER pTrigger = sqlite3TriggersExist(pTab, TK_DELETE, 0, 0); - isView = pTab->pSelect != 0; + assert(pTab->def->opts.is_view == (pTab->pSelect != NULL)); + isView = pTab->def->opts.is_view; bComplex = pTrigger || sqlite3FkRequired(pTab, 0); #else #define pTrigger 0 @@ -512,7 +513,8 @@ sqlite3DeleteFrom(Parse * pParse, /* The parser context */ if (eOnePass != ONEPASS_OFF) { assert(nKey == nPk); /* OP_Found will use an unpacked key */ if (aToOpen[iDataCur - iTabCur]) { - assert(pPk != 0 || pTab->pSelect != 0); + assert(pTab->def->opts.is_view == (pTab->pSelect != NULL)); + assert(pPk != 0 || pTab->def->opts.is_view); sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, addrBypass, iKey, nKey); @@ -786,7 +788,8 @@ sqlite3GenerateRowDelete(Parse * pParse, /* Parsing context */ * the update-hook is not invoked for rows removed by REPLACE, but the * pre-update-hook is. */ - if (pTab->pSelect == 0) { + assert(pTab->def->opts.is_view == (pTab->pSelect != NULL)); + if (!pTab->def->opts.is_view) { u8 p5 = 0; /* kyukhin: Tarantool handles indices uypdate automatically. */ /* sqlite3GenerateRowIndexDelete(pParse, pTab, iDataCur, iIdxCur,0,iIdxNoSeek); */ diff --git a/src/box/sql/expr.c b/src/box/sql/expr.c index 5f7d741..119940c 100644 --- a/src/box/sql/expr.c +++ b/src/box/sql/expr.c @@ -2233,7 +2233,8 @@ isCandidateForInOpt(Expr * pX) return 0; /* FROM is not a subquery or view */ pTab = pSrc->a[0].pTab; assert(pTab != 0); - assert(pTab->pSelect == 0); /* FROM clause is not a view */ + assert(pTab->def->opts.is_view == (pTab->pSelect != NULL)); + assert(!pTab->def->opts.is_view); /* FROM clause is not a view */ pEList = p->pEList; assert(pEList != 0); /* All SELECT results must be columns. */ diff --git a/src/box/sql/select.c b/src/box/sql/select.c index 199caf0..34d296d 100644 --- a/src/box/sql/select.c +++ b/src/box/sql/select.c @@ -4746,6 +4746,8 @@ selectExpander(Walker * pWalker, Select * p) if (sqlite3ViewGetColumnNames(pParse, pTab)) return WRC_Abort; assert(pFrom->pSelect == 0); + assert(pTab->def->opts.is_view == + (pTab->pSelect != NULL)); pFrom->pSelect = sqlite3SelectDup(db, pTab->pSelect, 0); sqlite3SelectSetName(pFrom->pSelect, diff --git a/src/box/sql/update.c b/src/box/sql/update.c index ad00537..2f36423 100644 --- a/src/box/sql/update.c +++ b/src/box/sql/update.c @@ -72,7 +72,8 @@ void sqlite3ColumnDefault(Vdbe * v, Table * pTab, int i, int iReg) { assert(pTab != 0); - if (!pTab->pSelect) { + assert(pTab->def->opts.is_view == (pTab->pSelect != NULL)); + if (!pTab->def->opts.is_view) { sqlite3_value *pValue = 0; Column *pCol = &pTab->aCol[i]; VdbeComment((v, "%s.%s", pTab->def->name, -- 2.7.4