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 55635281D0 for ; Sun, 12 Aug 2018 10:13:25 -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 TW3m_S-8P5x8 for ; Sun, 12 Aug 2018 10:13:25 -0400 (EDT) Received: from smtp54.i.mail.ru (smtp54.i.mail.ru [217.69.128.34]) (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 307492808B for ; Sun, 12 Aug 2018 10:13:22 -0400 (EDT) From: Nikita Pettik Subject: [tarantool-patches] [PATCH 04/10] sql: remove flags from struct Table Date: Sun, 12 Aug 2018 17:13:00 +0300 Message-Id: <2e3030fa0e25bad36c4d847babff2be4d6ff2c69.1534001739.git.korablev@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, Nikita Pettik Check on flag TF_HasPrimaryKey replaced with simple PK lookup in the list of table indexes. Check on flag TF_Ephemeral replaced with table->def->id == 0. Check on flag TF_Autoincrement replaced with table->iAutoinc >= 0. Part of #3561 --- src/box/sql/build.c | 11 ++++------- src/box/sql/insert.c | 12 ++++-------- src/box/sql/select.c | 4 +--- src/box/sql/sqliteInt.h | 8 -------- src/box/sql/where.c | 3 +-- 5 files changed, 10 insertions(+), 28 deletions(-) diff --git a/src/box/sql/build.c b/src/box/sql/build.c index 78206a1ed..31b91a4e2 100644 --- a/src/box/sql/build.c +++ b/src/box/sql/build.c @@ -883,13 +883,12 @@ sqlite3AddPrimaryKey(Parse * pParse, /* Parsing context */ int nTerm; if (pTab == 0) goto primary_key_exit; - if (pTab->tabFlags & TF_HasPrimaryKey) { + if (sqlite3PrimaryKeyIndex(pTab) != NULL) { sqlite3ErrorMsg(pParse, "table \"%s\" has more than one primary key", pTab->def->name); goto primary_key_exit; } - pTab->tabFlags |= TF_HasPrimaryKey; if (pList == 0) { iCol = pTab->def->field_count - 1; nTerm = 1; @@ -918,10 +917,8 @@ sqlite3AddPrimaryKey(Parse * pParse, /* Parsing context */ pTab->def->fields[iCol].type == FIELD_TYPE_INTEGER && sortOrder != SORT_ORDER_DESC) { assert(autoInc == 0 || autoInc == 1); - if (autoInc) { + if (autoInc) pTab->iAutoIncPKey = iCol; - pTab->tabFlags |= TF_Autoincrement; - } struct sqlite3 *db = pParse->db; struct ExprList *list; struct Token token; @@ -1698,7 +1695,7 @@ sqlite3EndTable(Parse * pParse, /* Parse context */ } if (!p->def->opts.is_view) { - if ((p->tabFlags & TF_HasPrimaryKey) == 0) { + if (sqlite3PrimaryKeyIndex(p) == NULL) { sqlite3ErrorMsg(pParse, "PRIMARY KEY missing on table %s", p->def->name); @@ -1767,7 +1764,7 @@ sqlite3EndTable(Parse * pParse, /* Parse context */ * Check to see if we need to create an _sequence table * for keeping track of autoincrement keys. */ - if ((p->tabFlags & TF_Autoincrement) != 0) { + if (p->iAutoIncPKey >= 0) { assert(reg_space_id != 0); /* Do an insertion into _sequence. */ int reg_seq_id = ++pParse->nMem; diff --git a/src/box/sql/insert.c b/src/box/sql/insert.c index 50c30fd82..ddd7f932b 100644 --- a/src/box/sql/insert.c +++ b/src/box/sql/insert.c @@ -714,8 +714,7 @@ sqlite3Insert(Parse * pParse, /* Parser context */ dflt, iRegStore); } else if (useTempTable) { - if ((pTab->tabFlags & TF_Autoincrement) - && (i == pTab->iAutoIncPKey)) { + if (i == pTab->iAutoIncPKey) { int regTmp = ++pParse->nMem; /* Emit code which doesn't override * autoinc-ed value with select result @@ -734,8 +733,7 @@ sqlite3Insert(Parse * pParse, /* Parser context */ } } else if (pSelect) { if (regFromSelect != regData) { - if ((pTab->tabFlags & TF_Autoincrement) - && (i == pTab->iAutoIncPKey)) { + if (i == pTab->iAutoIncPKey) { /* Emit code which doesn't override * autoinc-ed value with select result * in case that result is NULL @@ -1022,9 +1020,7 @@ sqlite3GenerateConstraintChecks(Parse * pParse, /* The parser context */ /* Don't bother checking for NOT NULL on columns that do not change */ continue; } - if (def->fields[i].is_nullable || - (pTab->tabFlags & TF_Autoincrement && - pTab->iAutoIncPKey == (int) i)) + if (def->fields[i].is_nullable || pTab->iAutoIncPKey == (int) i) continue; /* This column is allowed to be NULL */ on_error = table_column_nullable_action(pTab, i); @@ -1203,7 +1199,7 @@ sqlite3GenerateConstraintChecks(Parse * pParse, /* The parser context */ if (pTab->def->fields[fieldno].affinity == AFFINITY_INTEGER) { int skip_if_null = sqlite3VdbeMakeLabel(v); - if ((pTab->tabFlags & TF_Autoincrement) != 0) { + if (pTab->iAutoIncPKey >= 0) { sqlite3VdbeAddOp2(v, OP_IsNull, reg_pk, skip_if_null); diff --git a/src/box/sql/select.c b/src/box/sql/select.c index 6738ba54f..d22f4e0a9 100644 --- a/src/box/sql/select.c +++ b/src/box/sql/select.c @@ -4601,7 +4601,6 @@ withExpand(Walker * pWalker, struct SrcList_item *pFrom) pTab->tuple_log_count = DEFAULT_TUPLE_LOG_COUNT; assert(sqlite3LogEst(DEFAULT_TUPLE_COUNT) == DEFAULT_TUPLE_LOG_COUNT); - pTab->tabFlags |= TF_Ephemeral; pFrom->pSelect = sqlite3SelectDup(db, pCte->pSelect, 0); if (db->mallocFailed) return SQLITE_NOMEM_BKPT; @@ -4803,7 +4802,6 @@ selectExpander(Walker * pWalker, Select * p) pTab->tuple_log_count = DEFAULT_TUPLE_LOG_COUNT; assert(sqlite3LogEst(DEFAULT_TUPLE_COUNT) == DEFAULT_TUPLE_LOG_COUNT); - pTab->tabFlags |= TF_Ephemeral; } else { /* * An ordinary table or view name in the @@ -5157,7 +5155,7 @@ selectAddSubqueryTypeInfo(Walker * pWalker, Select * p) for (i = 0, pFrom = pTabList->a; i < pTabList->nSrc; i++, pFrom++) { Table *pTab = pFrom->pTab; assert(pTab != 0); - if ((pTab->tabFlags & TF_Ephemeral) != 0) { + if (pTab->def->id == 0) { /* A sub-query in the FROM clause of a SELECT */ Select *pSel = pFrom->pSelect; if (pSel) { diff --git a/src/box/sql/sqliteInt.h b/src/box/sql/sqliteInt.h index 5757efe49..e13e6ad34 100644 --- a/src/box/sql/sqliteInt.h +++ b/src/box/sql/sqliteInt.h @@ -1884,7 +1884,6 @@ struct Table { * can be fetched from space struct. */ LogEst tuple_log_count; - u8 tabFlags; /* Mask of TF_* values */ Schema *pSchema; /* Schema that contains this table */ Table *pNextZombie; /* Next on the Parse.pZombieTab list */ /** Space definition with Tarantool metadata. */ @@ -1901,13 +1900,6 @@ struct Table { LogEst sql_space_tuple_log_count(struct Table *tab); -/* - * Allowed values for Table.tabFlags. - */ -#define TF_Ephemeral 0x02 /* An ephemeral table */ -#define TF_HasPrimaryKey 0x04 /* Table has a primary key */ -#define TF_Autoincrement 0x08 /* Integer primary key is autoincrement */ - /* * Each foreign key constraint is an instance of the following structure. * diff --git a/src/box/sql/where.c b/src/box/sql/where.c index 117357662..db8d0bf80 100644 --- a/src/box/sql/where.c +++ b/src/box/sql/where.c @@ -4673,8 +4673,7 @@ sqlite3WhereBegin(Parse * pParse, /* The parser context */ struct SrcList_item *pTabItem = &pTabList->a[pLevel->iFrom]; Table *pTab = pTabItem->pTab; pLoop = pLevel->pWLoop; - if ((pTab->tabFlags & TF_Ephemeral) != 0 || - pTab->def->opts.is_view) { + if (pTab->def->id == 0 || pTab->def->opts.is_view) { /* Do nothing */ } else if ((pLoop->wsFlags & WHERE_IDX_ONLY) == 0 && (wctrlFlags & WHERE_OR_SUBCLAUSE) == 0) { -- 2.15.1