From: Kirill Shcherbatov <kshcherbatov@tarantool.org> To: tarantool-patches@freelists.org Cc: v.shpilevoy@tarantool.org, Kirill Shcherbatov <kshcherbatov@tarantool.org> 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 [thread overview] Message-ID: <705209b9a9caee1fcdd8e4887810f62ae831978b.1524939875.git.kshcherbatov@tarantool.org> (raw) In-Reply-To: <cover.1524939874.git.kshcherbatov@tarantool.org> In-Reply-To: <cover.1524939874.git.kshcherbatov@tarantool.org> 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
next prev parent reply other threads:[~2018-04-28 18:27 UTC|newest] Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top 2018-04-25 16:52 [tarantool-patches] [PATCH v3 0/4] sql: Removed Column fields to server with region allocations Kirill Shcherbatov 2018-04-25 16:52 ` [tarantool-patches] [PATCH v3 1/4] sql: Fix code style in sqlite3Pragma Kirill Shcherbatov 2018-04-26 11:47 ` [tarantool-patches] " Vladislav Shpilevoy 2018-04-25 16:52 ` [tarantool-patches] [PATCH v3 2/4] sql: Remove zName and nColumn from SQL Kirill Shcherbatov 2018-04-25 17:10 ` [tarantool-patches] " Kirill Shcherbatov 2018-04-26 12:12 ` Vladislav Shpilevoy 2018-04-26 11:47 ` Vladislav Shpilevoy 2018-04-25 16:52 ` [tarantool-patches] [PATCH v3 3/4] sql: Removed type " Kirill Shcherbatov 2018-04-25 16:52 ` [tarantool-patches] [PATCH v3 4/4] sql: Region-based allocations Kirill Shcherbatov 2018-04-26 11:47 ` [tarantool-patches] " Vladislav Shpilevoy 2018-04-26 11:47 ` [tarantool-patches] Re: [PATCH v3 0/4] sql: Removed Column fields to server with region allocations Vladislav Shpilevoy 2018-04-28 18:26 ` [tarantool-patches] [PATCH v4 0/7] sql: refactor SQL Parser structures Kirill Shcherbatov 2018-04-28 18:26 ` [tarantool-patches] [PATCH v4 1/7] sql: fix code style in sqlite3Pragma Kirill Shcherbatov 2018-05-03 10:10 ` [tarantool-patches] " Vladislav Shpilevoy 2018-04-28 18:26 ` [tarantool-patches] [PATCH v4 2/7] sql: remove zName and nColumn from SQL Kirill Shcherbatov 2018-05-03 10:10 ` [tarantool-patches] " Vladislav Shpilevoy 2018-04-28 18:26 ` [tarantool-patches] [PATCH v4 3/7] sql: start using type from space_def Kirill Shcherbatov 2018-04-28 18:26 ` [tarantool-patches] [PATCH v4 4/7] sql: start using collations and is_nullable " Kirill Shcherbatov 2018-05-03 10:21 ` [tarantool-patches] " Vladislav Shpilevoy 2018-04-28 18:26 ` [tarantool-patches] [PATCH v4 5/7] sql: move names to server Kirill Shcherbatov 2018-05-03 11:08 ` [tarantool-patches] " Vladislav Shpilevoy 2018-04-28 18:26 ` Kirill Shcherbatov [this message] 2018-05-03 11:16 ` [tarantool-patches] Re: [PATCH v4 6/7] sql: start using is_view field from space_def Vladislav Shpilevoy 2018-04-28 18:26 ` [tarantool-patches] [PATCH v4 7/7] sql: space_def* instead of Table* in Expr Kirill Shcherbatov 2018-05-03 11:32 ` [tarantool-patches] " Vladislav Shpilevoy 2018-05-03 10:10 ` [tarantool-patches] Re: [PATCH v4 0/7] sql: refactor SQL Parser structures Vladislav Shpilevoy
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=705209b9a9caee1fcdd8e4887810f62ae831978b.1524939875.git.kshcherbatov@tarantool.org \ --to=kshcherbatov@tarantool.org \ --cc=tarantool-patches@freelists.org \ --cc=v.shpilevoy@tarantool.org \ --subject='Re: [tarantool-patches] [PATCH v4 6/7] sql: start using is_view field from space_def' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox