[patches] [PATCH V2] sql: remove unnecessary SCopy opcodes

Bulat Niatshin niatshin at tarantool.org
Mon Mar 12 13:09:40 MSK 2018


Since OP_NoConflict opcode appears in INSERT/UPDATE VDBE listings
only when UNIQUE constraint check can't be handled by Tarantool
(after pushing 2255 to 2.0), related OP_SCopy should appear in
VDBE listing only when OP_NoConflict is present. This patch
contains a small fix for that.

Fix for #2255.
---

Changes in V2:
- Fixed issues with tests and travis

 src/box/sql/insert.c | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

diff --git a/src/box/sql/insert.c b/src/box/sql/insert.c
index 54fcca5c9..959faae9e 100644
--- a/src/box/sql/insert.c
+++ b/src/box/sql/insert.c
@@ -1240,14 +1240,24 @@ sqlite3GenerateConstraintChecks(Parse * pParse,		/* The parser context */
 				VdbeComment((v, "%s column %d", pIdx->zName,
 					     i));
 			} else {
-				if (iField == pTab->iPKey) {
-					x = regNewData;
-				} else {
-					x = iField + regNewData + 1;
+				/* OP_SCopy copies value in separate register,
+				 * which lately will be used by OP_NoConflict.
+				 * But OP_NoConflict is necessary only in cases
+				 * when bytecode is needed for proper UNIQUE
+				 * constraint handling.
+				 */
+				if (uniqueByteCodeNeeded) {
+					if (iField == pTab->iPKey) {
+						x = regNewData;
+					} else {
+						x = iField + regNewData + 1;
+					}
+					assert(iField >= 0);
+					sqlite3VdbeAddOp2(v, OP_SCopy,
+							  x, regIdx + i);
+					VdbeComment((v, "%s",
+						     pTab->aCol[iField].zName));
 				}
-				assert(iField >= 0);
-				sqlite3VdbeAddOp2(v, OP_SCopy, x, regIdx + i);
-				VdbeComment((v, "%s", pTab->aCol[iField].zName));
 			}
 		}
 
-- 
2.14.1




More information about the Tarantool-patches mailing list