Tarantool development patches archive
 help / color / mirror / Atom feed
From: Nikita Pettik <korablev@tarantool.org>
To: tarantool-patches@freelists.org
Cc: v.shpilevoy@tarantool.org, Nikita Pettik <korablev@tarantool.org>
Subject: [tarantool-patches] [PATCH 04/10] sql: remove flags from struct Table
Date: Sun, 12 Aug 2018 17:13:00 +0300	[thread overview]
Message-ID: <2e3030fa0e25bad36c4d847babff2be4d6ff2c69.1534001739.git.korablev@tarantool.org> (raw)
In-Reply-To: <cover.1534001739.git.korablev@tarantool.org>
In-Reply-To: <cover.1534001739.git.korablev@tarantool.org>

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

  parent reply	other threads:[~2018-08-12 14:13 UTC|newest]

Thread overview: 38+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-08-12 14:12 [tarantool-patches] [PATCH 00/10] sql: cleanup in struct Index and " Nikita Pettik
2018-08-12 14:12 ` [tarantool-patches] [PATCH 01/10] sql: remove suport of ALTER TABLE ADD COLUMN Nikita Pettik
2018-08-13 20:24   ` [tarantool-patches] " Vladislav Shpilevoy
2018-08-12 14:12 ` [tarantool-patches] [PATCH 02/10] sql: remove string of fields collation from Table Nikita Pettik
2018-08-13 20:24   ` [tarantool-patches] " Vladislav Shpilevoy
2018-08-12 14:12 ` [tarantool-patches] [PATCH 03/10] sql: remove index hash from struct Table Nikita Pettik
2018-08-13 20:24   ` [tarantool-patches] " Vladislav Shpilevoy
2018-08-12 14:13 ` Nikita Pettik [this message]
2018-08-13 20:24   ` [tarantool-patches] Re: [PATCH 04/10] sql: remove flags " Vladislav Shpilevoy
2018-08-12 14:13 ` [tarantool-patches] [PATCH 05/10] sql: remove affinity string of columns from Index Nikita Pettik
2018-08-13 20:24   ` [tarantool-patches] " Vladislav Shpilevoy
2018-08-21 16:31     ` n.pettik
2018-08-24 21:04       ` Vladislav Shpilevoy
2018-08-26 19:45         ` n.pettik
2018-08-12 14:13 ` [tarantool-patches] [PATCH 06/10] sql: completely remove support of partial indexes Nikita Pettik
2018-08-13 20:24   ` [tarantool-patches] " Vladislav Shpilevoy
2018-08-21 16:31     ` n.pettik
2018-08-24 21:04       ` Vladislav Shpilevoy
2018-08-26 19:44         ` n.pettik
2018-08-12 14:13 ` [tarantool-patches] [PATCH 07/10] sql: remove index type from struct Index Nikita Pettik
2018-08-13 20:24   ` [tarantool-patches] " Vladislav Shpilevoy
2018-08-21 16:31     ` n.pettik
2018-08-12 14:13 ` [tarantool-patches] [PATCH 08/10] sql: use secondary indexes to process OP_Delete Nikita Pettik
2018-08-13 20:24   ` [tarantool-patches] " Vladislav Shpilevoy
2018-08-12 14:13 ` [tarantool-patches] [PATCH 09/10] sql: disable ON CONFLICT actions for indexes Nikita Pettik
2018-08-13 20:24   ` [tarantool-patches] " Vladislav Shpilevoy
2018-08-21 16:31     ` n.pettik
2018-08-24 21:04       ` Vladislav Shpilevoy
2018-08-26 19:44         ` n.pettik
2018-08-27 17:24           ` Vladislav Shpilevoy
2018-08-12 14:13 ` [tarantool-patches] [PATCH 10/10] sql: move autoincrement field number to server Nikita Pettik
2018-08-13 20:24   ` [tarantool-patches] " Vladislav Shpilevoy
2018-08-21 16:31     ` n.pettik
2018-08-24 21:03       ` Vladislav Shpilevoy
2018-08-26 19:44         ` n.pettik
2018-08-27 17:24           ` Vladislav Shpilevoy
2018-08-27 17:24 ` [tarantool-patches] Re: [PATCH 00/10] sql: cleanup in struct Index and struct Table Vladislav Shpilevoy
2018-08-29 14:11 ` Kirill Yukhin

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=2e3030fa0e25bad36c4d847babff2be4d6ff2c69.1534001739.git.korablev@tarantool.org \
    --to=korablev@tarantool.org \
    --cc=tarantool-patches@freelists.org \
    --cc=v.shpilevoy@tarantool.org \
    --subject='Re: [tarantool-patches] [PATCH 04/10] sql: remove flags from struct Table' \
    /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