[patches] [PATCH V2 1/9] sql: remove OMIT_AUTOINCREMENT ifndef

Bulat Niatshin niatshin at tarantool.org
Tue Feb 27 16:54:46 MSK 2018


Refactor all code under OMIT_AUTOINCREMENT define.

For #3119
---
 src/box/sql/alter.c   | 11 -----------
 src/box/sql/build.c   | 14 --------------
 src/box/sql/opcodes.c | 17 ++++++++---------
 src/box/sql/opcodes.h | 21 ++++++++++-----------
 src/box/sql/vdbe.c    | 31 -------------------------------
 5 files changed, 18 insertions(+), 76 deletions(-)

diff --git a/src/box/sql/alter.c b/src/box/sql/alter.c
index 00d160a33..22345397a 100644
--- a/src/box/sql/alter.c
+++ b/src/box/sql/alter.c
@@ -131,17 +131,6 @@ sqlite3AlterRenameTable(Parse * pParse,	/* Parser context. */
 	}
 	sqlite3BeginWriteOperation(pParse, false);
 
-#ifndef SQLITE_OMIT_AUTOINCREMENT
-	/* If the sqlite_sequence table exists in this database, then update
-	 * it with the new table name.
-	 */
-	if (sqlite3FindTable(db, "sqlite_sequence")) {
-		sqlite3NestedParse(pParse,
-				   "UPDATE sqlite_sequence set name = %Q WHERE name = %Q",
-				   zName, pTab->zName);
-	}
-#endif
-
 	/* Drop and reload the internal table schema. */
 	reloadTableSchema(pParse, pTab, zName);
 
diff --git a/src/box/sql/build.c b/src/box/sql/build.c
index 9f45c6224..d5e25a3b0 100644
--- a/src/box/sql/build.c
+++ b/src/box/sql/build.c
@@ -730,16 +730,6 @@ sqlite3StartTable(Parse *pParse, Token *pName, int noErr)
 	assert(pParse->pNewTable == 0);
 	pParse->pNewTable = pTable;
 
-	/* If this is the magic _sequence table used by autoincrement,
-	 * then record a pointer to this table in the main database structure
-	 * so that INSERT can find the table easily.
-	 */
-#ifndef SQLITE_OMIT_AUTOINCREMENT
-	if (!pParse->nested && strcmp(zName, "_SEQUENCE") == 0) {
-		pTable->pSchema->pSeqTab = pTable;
-	}
-#endif
-
 	/* Begin generating the code that will create a new table.
 	 * Note in particular that we must go ahead and allocate the
 	 * record number for the table entry now.  Before any
@@ -1086,10 +1076,8 @@ sqlite3AddPrimaryKey(Parse * pParse,	/* Parsing context */
 		if (pList)
 			pParse->iPkSortOrder = pList->a[0].sortOrder;
 	} else if (autoInc) {
-#ifndef SQLITE_OMIT_AUTOINCREMENT
 		sqlite3ErrorMsg(pParse, "AUTOINCREMENT is only allowed on an "
 				"INTEGER PRIMARY KEY or INT PRIMARY KEY");
-#endif
 	} else {
 		sqlite3CreateIndex(pParse, 0, 0, pList, onError, 0,
 				   0, sortOrder, 0, SQLITE_IDXTYPE_PRIMARYKEY);
@@ -1982,7 +1970,6 @@ sqlite3EndTable(Parse * pParse,	/* Parse context */
 		createImplicitIndices(pParse, iSpaceId, iCursor, pSysIndex);
 		sqlite3VdbeAddOp1(v, OP_Close, iCursor);
 
-#ifndef SQLITE_OMIT_AUTOINCREMENT
 		/* Check to see if we need to create an _sequence table for
 		 * keeping track of autoincrement keys.
 		 */
@@ -2035,7 +2022,6 @@ sqlite3EndTable(Parse * pParse,	/* Parse context */
 
 			sqlite3VdbeAddOp1(v, OP_Close, iCursor);
 		}
-#endif
 
 		/* Reparse everything to update our internal data structures */
 		parseTableSchemaRecord(pParse, iSpaceId, zStmt);	/* consumes zStmt */
diff --git a/src/box/sql/opcodes.c b/src/box/sql/opcodes.c
index 44818952e..a7f735da9 100644
--- a/src/box/sql/opcodes.c
+++ b/src/box/sql/opcodes.c
@@ -144,15 +144,14 @@ const char *sqlite3OpcodeName(int i){
     /* 130 */ "DropTrigger"      OpHelp(""),
     /* 131 */ "Param"            OpHelp(""),
     /* 132 */ "FkCounter"        OpHelp("fkctr[P1]+=P2"),
-    /* 133 */ "MemMax"           OpHelp("r[P1]=max(r[P1],r[P2])"),
-    /* 134 */ "OffsetLimit"      OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
-    /* 135 */ "AggStep0"         OpHelp("accum=r[P3] step(r[P2 at P5])"),
-    /* 136 */ "AggStep"          OpHelp("accum=r[P3] step(r[P2 at P5])"),
-    /* 137 */ "AggFinal"         OpHelp("accum=r[P1] N=P2"),
-    /* 138 */ "Expire"           OpHelp(""),
-    /* 139 */ "IncMaxid"         OpHelp(""),
-    /* 140 */ "Noop"             OpHelp(""),
-    /* 141 */ "Explain"          OpHelp(""),
+    /* 133 */ "OffsetLimit"      OpHelp("if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1)"),
+    /* 134 */ "AggStep0"         OpHelp("accum=r[P3] step(r[P2 at P5])"),
+    /* 135 */ "AggStep"          OpHelp("accum=r[P3] step(r[P2 at P5])"),
+    /* 136 */ "AggFinal"         OpHelp("accum=r[P1] N=P2"),
+    /* 137 */ "Expire"           OpHelp(""),
+    /* 138 */ "IncMaxid"         OpHelp(""),
+    /* 139 */ "Noop"             OpHelp(""),
+    /* 140 */ "Explain"          OpHelp(""),
   };
   return azName[i];
 }
diff --git a/src/box/sql/opcodes.h b/src/box/sql/opcodes.h
index ccca23792..4bf321b03 100644
--- a/src/box/sql/opcodes.h
+++ b/src/box/sql/opcodes.h
@@ -133,15 +133,14 @@
 #define OP_DropTrigger   130
 #define OP_Param         131
 #define OP_FkCounter     132 /* synopsis: fkctr[P1]+=P2                    */
-#define OP_MemMax        133 /* synopsis: r[P1]=max(r[P1],r[P2])           */
-#define OP_OffsetLimit   134 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
-#define OP_AggStep0      135 /* synopsis: accum=r[P3] step(r[P2 at P5])       */
-#define OP_AggStep       136 /* synopsis: accum=r[P3] step(r[P2 at P5])       */
-#define OP_AggFinal      137 /* synopsis: accum=r[P1] N=P2                 */
-#define OP_Expire        138
-#define OP_IncMaxid      139
-#define OP_Noop          140
-#define OP_Explain       141
+#define OP_OffsetLimit   133 /* synopsis: if r[P1]>0 then r[P2]=r[P1]+max(0,r[P3]) else r[P2]=(-1) */
+#define OP_AggStep0      134 /* synopsis: accum=r[P3] step(r[P2 at P5])       */
+#define OP_AggStep       135 /* synopsis: accum=r[P3] step(r[P2 at P5])       */
+#define OP_AggFinal      136 /* synopsis: accum=r[P1] N=P2                 */
+#define OP_Expire        137
+#define OP_IncMaxid      138
+#define OP_Noop          139
+#define OP_Explain       140
 
 /* Properties such as "out2" or "jump" that are specified in
 ** comments following the "case" for each opcode in the vdbe.c
@@ -170,8 +169,8 @@
 /* 104 */ 0x00, 0x00, 0x10, 0x20, 0x00, 0x10, 0x00, 0x00,\
 /* 112 */ 0x00, 0x00, 0x00, 0x10, 0x00, 0x04, 0x00, 0x04,\
 /* 120 */ 0x00, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\
-/* 128 */ 0x00, 0x00, 0x00, 0x10, 0x00, 0x04, 0x1a, 0x00,\
-/* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,}
+/* 128 */ 0x00, 0x00, 0x00, 0x10, 0x00, 0x1a, 0x00, 0x00,\
+/* 136 */ 0x00, 0x00, 0x00, 0x00, 0x00,}
 
 /* The sqlite3P2Values() routine is able to run faster if it knows
 ** the value of the largest JUMP opcode.  The smaller the maximum
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index b235e7bf6..1f496d0e6 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -5186,37 +5186,6 @@ case OP_FkIfZero: {         /* jump */
 }
 #endif /* #ifndef SQLITE_OMIT_FOREIGN_KEY */
 
-#ifndef SQLITE_OMIT_AUTOINCREMENT
-/* Opcode: MemMax P1 P2 * * *
- * Synopsis: r[P1]=max(r[P1],r[P2])
- *
- * P1 is a register in the root frame of this VM (the root frame is
- * different from the current frame if this instruction is being executed
- * within a sub-program). Set the value of register P1 to the maximum of
- * its current value and the value in register P2.
- *
- * This instruction throws an error if the memory cell is not initially
- * an integer.
- */
-case OP_MemMax: {        /* in2 */
-	VdbeFrame *pFrame;
-	if (p->pFrame) {
-		for(pFrame=p->pFrame; pFrame->pParent; pFrame=pFrame->pParent);
-		pIn1 = &pFrame->aMem[pOp->p1];
-	} else {
-		pIn1 = &aMem[pOp->p1];
-	}
-	assert(memIsValid(pIn1));
-	sqlite3VdbeMemIntegerify(pIn1);
-	pIn2 = &aMem[pOp->p2];
-	sqlite3VdbeMemIntegerify(pIn2);
-	if (pIn1->u.i<pIn2->u.i) {
-		pIn1->u.i = pIn2->u.i;
-	}
-	break;
-}
-#endif /* SQLITE_OMIT_AUTOINCREMENT */
-
 /* Opcode: IfPos P1 P2 P3 * *
  * Synopsis: if r[P1]>0 then r[P1]-=P3, goto P2
  *
-- 
2.14.1




More information about the Tarantool-patches mailing list