[tarantool-patches] [PATCH] sql: remove unused VDBE routine

Nikita Pettik korablev at tarantool.org
Mon May 14 14:57:34 MSK 2018


---
This patch simply removes useless/obsolete routine from VDBE
and auxiliary functions.

Branch: https://github.com/tarantool/tarantool/commits/np/vdbe-cleanup

 src/box/sql/vdbe.c    |  21 +--
 src/box/sql/vdbe.h    |   3 -
 src/box/sql/vdbeInt.h |   4 -
 src/box/sql/vdbeaux.c | 492 --------------------------------------------------
 4 files changed, 2 insertions(+), 518 deletions(-)

diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index 2adc17ed2..62d1f04f5 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -2524,10 +2524,6 @@ case OP_Column: {
 	pC = p->apCsr[pOp->p1];
 	p2 = pOp->p2;
 
-	/* If the cursor cache is stale, bring it up-to-date */
-	rc = sqlite3VdbeCursorMoveto(&pC, &p2);
-	if (rc) goto abort_due_to_error;
-
 	assert(pOp->p3>0 && pOp->p3<=(p->nMem+1 - p->nCursor));
 	pDest = &aMem[pOp->p3];
 	memAboutToChange(p, pDest);
@@ -3572,7 +3568,6 @@ case OP_SeekGT: {       /* jump, in3 */
 		assert(res!=0);
 		goto seek_not_found;
 	}
-	pC->deferredMoveto = 0;
 	pC->cacheStatus = CACHE_STALE;
 #ifdef SQLITE_TEST
 	sql_search_count++;
@@ -3738,7 +3733,6 @@ case OP_Found: {        /* jump, in3 */
 	pC->seekResult = res;
 	alreadyExists = (res==0);
 	pC->nullRow = 1-alreadyExists;
-	pC->deferredMoveto = 0;
 	pC->cacheStatus = CACHE_STALE;
 	if (pOp->opcode==OP_Found) {
 		VdbeBranchTaken(alreadyExists!=0,2);
@@ -3887,7 +3881,6 @@ case OP_Delete: {
 	assert(pC!=0);
 	assert(pC->eCurType==CURTYPE_TARANTOOL);
 	assert(pC->uc.pCursor!=0);
-	assert(pC->deferredMoveto==0);
 	assert(pBtCur->eState == CURSOR_VALID);
 
 	if (pBtCur->curFlags & BTCF_TaCursor) {
@@ -4015,13 +4008,9 @@ case OP_RowData: {
 	 * OP_Rewind/Op_Next with no intervening instructions
 	 * that might invalidate the cursor.
 	 * If this where not the case, on of the following assert()s
-	 * would fail.  Should this ever change (because of changes in the code
-	 * generator) then the fix would be to insert a call to
-	 * sqlite3VdbeCursorMoveto().
+	 * would fail.
 	 */
-	assert(pC->deferredMoveto==0);
 	assert(sqlite3CursorIsValid(pCrsr));
-
 	assert(pCrsr->eState == CURSOR_VALID);
 	assert(pCrsr->curFlags & BTCF_TaCursor ||
 	       pCrsr->curFlags & BTCF_TEphemCursor);
@@ -4101,7 +4090,6 @@ case OP_Last: {        /* jump */
 	if (pOp->p3==0 || !sqlite3CursorIsValidNN(pCrsr)) {
 		rc = tarantoolSqlite3Last(pCrsr, &res);
 		pC->nullRow = (u8)res;
-		pC->deferredMoveto = 0;
 		pC->cacheStatus = CACHE_STALE;
 		if (rc) goto abort_due_to_error;
 		if (pOp->p2>0) {
@@ -4178,7 +4166,6 @@ case OP_Rewind: {        /* jump */
 		pCrsr = pC->uc.pCursor;
 		assert(pCrsr);
 		rc = tarantoolSqlite3First(pCrsr, &res);
-		pC->deferredMoveto = 0;
 		pC->cacheStatus = CACHE_STALE;
 	}
 	if (rc) goto abort_due_to_error;
@@ -4277,7 +4264,6 @@ case OP_Next:          /* jump */
 	pC = p->apCsr[pOp->p1];
 	res = pOp->p3;
 	assert(pC!=0);
-	assert(pC->deferredMoveto==0);
 	assert(pC->eCurType==CURTYPE_TARANTOOL);
 	assert(res==0 || res==1);
 	testcase( res==1);
@@ -4373,7 +4359,6 @@ case OP_IdxInsert: {        /* in2 */
 		} else {
 			unreachable();
 		}
-		assert(pC->deferredMoveto==0);
 		pC->cacheStatus = CACHE_STALE;
 	}
 
@@ -4507,7 +4492,6 @@ case OP_IdxDelete: {
 		}
 		if (rc) goto abort_due_to_error;
 	}
-	assert(pC->deferredMoveto==0);
 	pC->cacheStatus = CACHE_STALE;
 	pC->seekResult = 0;
 	break;
@@ -4570,7 +4554,6 @@ case OP_IdxGE:  {       /* jump */
 	assert(pC!=0);
 	assert(pC->eCurType==CURTYPE_TARANTOOL);
 	assert(pC->uc.pCursor!=0);
-	assert(pC->deferredMoveto==0);
 	assert(pOp->p5==0 || pOp->p5==1);
 	assert(pOp->p4type==P4_INT32);
 	r.pKeyInfo = pC->pKeyInfo;
@@ -4587,7 +4570,7 @@ case OP_IdxGE:  {       /* jump */
 	{ int i; for(i=0; i<r.nField; i++) assert(memIsValid(&r.aMem[i])); }
 #endif
 	res = 0;  /* Not needed.  Only used to silence a warning. */
-	rc = sqlite3VdbeIdxKeyCompare(db, pC, &r, &res);
+	rc =  tarantoolSqlite3IdxKeyCompare(pC->uc.pCursor, &r, &res);
 	assert((OP_IdxLE&1)==(OP_IdxLT&1) && (OP_IdxGE&1)==(OP_IdxGT&1));
 	if ((pOp->opcode&1)==(OP_IdxLT&1)) {
 		assert(pOp->opcode==OP_IdxLE || pOp->opcode==OP_IdxLT);
diff --git a/src/box/sql/vdbe.h b/src/box/sql/vdbe.h
index c31983f21..bcc6009f3 100644
--- a/src/box/sql/vdbe.h
+++ b/src/box/sql/vdbe.h
@@ -281,13 +281,10 @@ int sqlite3MemCompare(const Mem *, const Mem *, const struct coll *);
 
 void sqlite3VdbeRecordUnpackMsgpack(KeyInfo *, int, const void *,
 				    UnpackedRecord *);
-int sqlite3VdbeRecordCompare(int, const void *, UnpackedRecord *);
-int sqlite3VdbeRecordCompareWithSkip(int, const void *, UnpackedRecord *, int);
 UnpackedRecord *sqlite3VdbeAllocUnpackedRecord(KeyInfo *);
 int sql_vdbe_mem_alloc_region(Mem *, uint32_t);
 
 typedef int (*RecordCompare) (int, const void *, UnpackedRecord *);
-RecordCompare sqlite3VdbeFindCompare(UnpackedRecord *);
 
 #ifndef SQLITE_OMIT_TRIGGER
 void sqlite3VdbeLinkSubProgram(Vdbe *, SubProgram *);
diff --git a/src/box/sql/vdbeInt.h b/src/box/sql/vdbeInt.h
index 3a907cd93..190889bac 100644
--- a/src/box/sql/vdbeInt.h
+++ b/src/box/sql/vdbeInt.h
@@ -82,7 +82,6 @@ typedef struct VdbeCursor VdbeCursor;
 struct VdbeCursor {
 	u8 eCurType;		/* One of the CURTYPE_* values above */
 	u8 nullRow;		/* True if pointing to a row with no data */
-	u8 deferredMoveto;	/* A call to sqlite3CursorMoveto() is needed */
 #ifdef SQLITE_DEBUG
 	u8 seekOp;		/* Most recent seek operation on this cursor */
 #endif
@@ -446,19 +445,16 @@ struct PreUpdate {
 void sqlite3VdbeError(Vdbe *, const char *, ...);
 void sqlite3VdbeFreeCursor(Vdbe *, VdbeCursor *);
 void sqliteVdbePopStack(Vdbe *, int);
-int sqlite3VdbeCursorMoveto(VdbeCursor **, int *);
 int sqlite3VdbeCursorRestore(VdbeCursor *);
 #if defined(SQLITE_DEBUG) || defined(VDBE_PROFILE)
 void sqlite3VdbePrintOp(FILE *, int, Op *);
 #endif
 u32 sqlite3VdbeSerialTypeLen(u32);
-u8 sqlite3VdbeOneByteSerialTypeLen(u8);
 u32 sqlite3VdbeSerialType(Mem *, int, u32 *);
 u32 sqlite3VdbeSerialPut(unsigned char *, Mem *, u32);
 u32 sqlite3VdbeSerialGet(const unsigned char *, u32, Mem *);
 void sqlite3VdbeDeleteAuxData(sqlite3 *, AuxData **, int, int);
 
-int sqlite3VdbeIdxKeyCompare(sqlite3 *, VdbeCursor *, UnpackedRecord *, int *);
 int sqlite3VdbeExec(Vdbe *);
 int sqlite3VdbeList(Vdbe *);
 int
diff --git a/src/box/sql/vdbeaux.c b/src/box/sql/vdbeaux.c
index ead96592d..660b8ba6b 100644
--- a/src/box/sql/vdbeaux.c
+++ b/src/box/sql/vdbeaux.c
@@ -3036,59 +3036,6 @@ sqlite3VdbeDelete(Vdbe * p)
 	sqlite3DbFree(db, p);
 }
 
-/*
- * The cursor "p" has a pending seek operation that has not yet been
- * carried out.  Seek the cursor now.  If an error occurs, return
- * the appropriate error code.
- */
-static int SQLITE_NOINLINE
-handleDeferredMoveto(VdbeCursor * p)
-{
-	int res, rc;
-#ifdef SQLITE_TEST
-	extern int sql_search_count;
-#endif
-	assert(p->deferredMoveto);
-	assert(p->eCurType == CURTYPE_TARANTOOL);
-	rc = sqlite3CursorMovetoUnpacked(p->uc.pCursor, 0, &res);
-	if (rc)
-		return rc;
-	if (res != 0)
-		return SQLITE_CORRUPT_BKPT;
-#ifdef SQLITE_TEST
-	sql_search_count++;
-#endif
-	p->deferredMoveto = 0;
-	p->cacheStatus = CACHE_STALE;
-	return SQLITE_OK;
-}
-
-/*
- * Make sure the cursor p is ready to read or write the row to which it
- * was last positioned.  Return an error code if an OOM fault or I/O error
- * prevents us from positioning the cursor to its correct position.
- *
- * If a MoveTo operation is pending on the given cursor, then do that
- * MoveTo now.  If no move is pending, check to see if the row has been
- * deleted out from under the cursor and if it has, mark the row as
- * a NULL row.
- *
- * If the cursor is already pointing to the correct row and that row has
- * not been deleted out from under the cursor, then this routine is a no-op.
- */
-int
-sqlite3VdbeCursorMoveto(VdbeCursor ** pp, int *piCol)
-{
-	(void)piCol;
-	VdbeCursor *p = *pp;
-	if (p->eCurType == CURTYPE_TARANTOOL) {
-		if (p->deferredMoveto) {
-			return handleDeferredMoveto(p);
-		}
-	}
-	return SQLITE_OK;
-}
-
 /*
  * The following functions:
  *
@@ -3233,13 +3180,6 @@ sqlite3VdbeSerialTypeLen(u32 serial_type)
 	}
 }
 
-u8
-sqlite3VdbeOneByteSerialTypeLen(u8 serial_type)
-{
-	assert(serial_type < 128);
-	return sqlite3SmallTypeSizes[serial_type];
-}
-
 /*
  * If we are on an architecture with mixed-endian floating
  * points (ex: ARM7) then swap the lower 4 bytes with the
@@ -3547,121 +3487,6 @@ sql_vdbe_mem_alloc_region(Mem *vdbe_mem, uint32_t size)
 	return SQLITE_OK;
 }
 
-#if SQLITE_DEBUG
-/*
- * This function compares two index or table record keys in the same way
- * as the sqlite3VdbeRecordCompare() routine. Unlike VdbeRecordCompare(),
- * this function deserializes and compares values using the
- * sqlite3VdbeSerialGet() and sqlite3MemCompare() functions. It is used
- * in assert() statements to ensure that the optimized code in
- * sqlite3VdbeRecordCompare() returns results with these two primitives.
- *
- * Return true if the result of comparison is equivalent to desiredResult.
- * Return false if there is a disagreement.
- */
-static int
-vdbeRecordCompareDebug(int nKey1, const void *pKey1,	/* Left key */
-		       const UnpackedRecord * pPKey2,	/* Right key */
-		       int desiredResult)		/* Correct answer */
-{
-	u32 d1;			/* Offset into aKey[] of next data element */
-	u32 idx1;		/* Offset into aKey[] of next header element */
-	u32 szHdr1;		/* Number of bytes in header */
-	int i = 0;
-	int rc = 0;
-	const unsigned char *aKey1 = (const unsigned char *)pKey1;
-	KeyInfo *pKeyInfo;
-	Mem mem1;
-
-	pKeyInfo = pPKey2->pKeyInfo;
-	if (pKeyInfo->db == 0)
-		return 1;
-	mem1.db = pKeyInfo->db;
-	/* mem1.flags = 0;  // Will be initialized by sqlite3VdbeSerialGet() */
-	VVA_ONLY(mem1.szMalloc = 0;
-	    )
-
-	    /* Only needed by assert() statements */
-	    /* Compilers may complain that mem1.u.i is potentially uninitialized.
-	     * We could initialize it, as shown here, to silence those complaints.
-	     * But in fact, mem1.u.i will never actually be used uninitialized, and doing
-	     * the unnecessary initialization has a measurable negative performance
-	     * impact, since this routine is a very high runner.  And so, we choose
-	     * to ignore the compiler warnings and leave this variable uninitialized.
-	     */
-	    /*  mem1.u.i = 0;  // not needed, here to silence compiler warning */
-	    idx1 = getVarint32(aKey1, szHdr1);
-	if (szHdr1 > 98307)
-		return SQLITE_CORRUPT;
-	d1 = szHdr1;
-	assert(pKeyInfo->nField + pKeyInfo->nXField >= pPKey2->nField
-	       || CORRUPT_DB);
-	assert(pKeyInfo->aSortOrder != 0);
-	assert(pKeyInfo->nField > 0);
-	assert(idx1 <= szHdr1 || CORRUPT_DB);
-	do {
-		u32 serial_type1;
-
-		/* Read the serial types for the next element in each key. */
-		idx1 += getVarint32(aKey1 + idx1, serial_type1);
-
-		/* Verify that there is enough key space remaining to avoid
-		 * a buffer overread.  The "d1+serial_type1+2" subexpression will
-		 * always be greater than or equal to the amount of required key space.
-		 * Use that approximation to avoid the more expensive call to
-		 * sqlite3VdbeSerialTypeLen() in the common case.
-		 */
-		if (d1 + serial_type1 + 2 > (u32) nKey1
-		    && d1 + sqlite3VdbeSerialTypeLen(serial_type1) >
-		    (u32) nKey1) {
-			break;
-		}
-
-		/* Extract the values to be compared.
-		 */
-		d1 += sqlite3VdbeSerialGet(&aKey1[d1], serial_type1, &mem1);
-
-		/* Do the comparison
-		 */
-		rc = sqlite3MemCompare(&mem1, &pPKey2->aMem[i],
-				       pKeyInfo->aColl[i]);
-		if (rc != 0) {
-			assert(mem1.szMalloc == 0);	/* See comment below */
-			if (pKeyInfo->aSortOrder[i]) {
-				rc = -rc;	/* Invert the result for DESC sort order. */
-			}
-			goto debugCompareEnd;
-		}
-		i++;
-	} while (idx1 < szHdr1 && i < pPKey2->nField);
-
-	/* No memory allocation is ever used on mem1.  Prove this using
-	 * the following assert().  If the assert() fails, it indicates a
-	 * memory leak and a need to call sqlite3VdbeMemRelease(&mem1).
-	 */
-	assert(mem1.szMalloc == 0);
-
-	/* rc==0 here means that one of the keys ran out of fields and
-	 * all the fields up to that point were equal. Return the default_rc
-	 * value.
-	 */
-	rc = pPKey2->default_rc;
-
- debugCompareEnd:
-	if (desiredResult == 0 && rc == 0)
-		return 1;
-	if (desiredResult < 0 && rc < 0)
-		return 1;
-	if (desiredResult > 0 && rc > 0)
-		return 1;
-	if (CORRUPT_DB)
-		return 1;
-	if (pKeyInfo->db->mallocFailed)
-		return 1;
-	return 0;
-}
-#endif
-
 /*
  * Both *pMem1 and *pMem2 contain string values. Compare the two values
  * using the collation sequence pColl. As usual, return a negative , zero
@@ -3868,323 +3693,6 @@ sqlite3MemCompare(const Mem * pMem1, const Mem * pMem2, const struct coll * pCol
 	return sqlite3BlobCompare(pMem1, pMem2);
 }
 
-/*
- * The first argument passed to this function is a serial-type that
- * corresponds to an integer - all values between 1 and 9 inclusive
- * except 7. The second points to a buffer containing an integer value
- * serialized according to serial_type. This function deserializes
- * and returns the value.
- */
-static i64
-vdbeRecordDecodeInt(u32 serial_type, const u8 * aKey)
-{
-	u32 y;
-	assert(CORRUPT_DB
-	       || (serial_type >= 1 && serial_type <= 9 && serial_type != 7));
-	switch (serial_type) {
-	case 0:
-	case 1:
-		testcase(aKey[0] & 0x80);
-		return ONE_BYTE_INT(aKey);
-	case 2:
-		testcase(aKey[0] & 0x80);
-		return TWO_BYTE_INT(aKey);
-	case 3:
-		testcase(aKey[0] & 0x80);
-		return THREE_BYTE_INT(aKey);
-	case 4:{
-			testcase(aKey[0] & 0x80);
-			y = FOUR_BYTE_UINT(aKey);
-			return (i64) * (int *)&y;
-		}
-	case 5:{
-			testcase(aKey[0] & 0x80);
-			return FOUR_BYTE_UINT(aKey + 2) +
-			    (((i64) 1) << 32) * TWO_BYTE_INT(aKey);
-		}
-	case 6:{
-			u64 x = FOUR_BYTE_UINT(aKey);
-			testcase(aKey[0] & 0x80);
-			x = (x << 32) | FOUR_BYTE_UINT(aKey + 4);
-			return (i64) * (i64 *) & x;
-		}
-	}
-
-	return (serial_type - 8);
-}
-
-/*
- * This function compares the two table rows or index records
- * specified by {nKey1, pKey1} and pPKey2.  It returns a negative, zero
- * or positive integer if key1 is less than, equal to or
- * greater than key2.  The {nKey1, pKey1} key must be a blob
- * created by the OP_MakeRecord opcode of the VDBE.  The pPKey2
- * key must be a parsed key such as obtained from
- * sqlite3VdbeParseRecord.
- *
- * If argument bSkip is non-zero, it is assumed that the caller has already
- * determined that the first fields of the keys are equal.
- *
- * Key1 and Key2 do not have to contain the same number of fields. If all
- * fields that appear in both keys are equal, then pPKey2->default_rc is
- * returned.
- *
- * If database corruption is discovered, set pPKey2->errCode to
- * SQLITE_CORRUPT and return 0. If an OOM error is encountered,
- * pPKey2->errCode is set to SQLITE_NOMEM and, if it is not NULL, the
- * malloc-failed flag set on database handle (pPKey2->pKeyInfo->db).
- */
-int
-sqlite3VdbeRecordCompareWithSkip(int nKey1, const void *pKey1,	/* Left key */
-				 UnpackedRecord * pPKey2,	/* Right key */
-				 int bSkip)			/* If true, skip the first field */
-{
-	u32 d1;			/* Offset into aKey[] of next data element */
-	int i;			/* Index of next field to compare */
-	u32 szHdr1;		/* Size of record header in bytes */
-	u32 idx1;		/* Offset of first type in header */
-	int rc = 0;		/* Return value */
-	Mem *pRhs = pPKey2->aMem;	/* Next field of pPKey2 to compare */
-	KeyInfo *pKeyInfo = pPKey2->pKeyInfo;
-	const unsigned char *aKey1 = (const unsigned char *)pKey1;
-	Mem mem1;
-
-	/* If bSkip is true, then the caller has already determined that the first
-	 * two elements in the keys are equal. Fix the various stack variables so
-	 * that this routine begins comparing at the second field.
-	 */
-	if (bSkip) {
-		u32 s1;
-		idx1 = 1 + getVarint32(&aKey1[1], s1);
-		szHdr1 = aKey1[0];
-		d1 = szHdr1 + sqlite3VdbeSerialTypeLen(s1);
-		i = 1;
-		pRhs++;
-	} else {
-		idx1 = getVarint32(aKey1, szHdr1);
-		d1 = szHdr1;
-		if (d1 > (unsigned)nKey1) {
-			pPKey2->errCode = (u8) SQLITE_CORRUPT_BKPT;
-			return 0;	/* Corruption */
-		}
-		i = 0;
-	}
-
-	VVA_ONLY(mem1.szMalloc = 0;
-	    )			/* Only needed by assert() statements */
-	    assert(pPKey2->pKeyInfo->nField + pPKey2->pKeyInfo->nXField >=
-		   pPKey2->nField || CORRUPT_DB);
-	assert(pPKey2->pKeyInfo->aSortOrder != 0);
-	assert(pPKey2->pKeyInfo->nField > 0);
-	assert(idx1 <= szHdr1 || CORRUPT_DB);
-	do {
-		u32 serial_type;
-
-		/* RHS is an integer */
-		if (pRhs->flags & MEM_Int) {
-			serial_type = aKey1[idx1];
-			testcase(serial_type == 12);
-			if (serial_type >= 10) {
-				rc = +1;
-			} else if (serial_type == 0) {
-				rc = -1;
-			} else if (serial_type == 7) {
-				sqlite3VdbeSerialGet(&aKey1[d1], serial_type,
-						     &mem1);
-				rc = -sqlite3IntFloatCompare(pRhs->u.i,
-							     mem1.u.r);
-			} else {
-				i64 lhs =
-				    vdbeRecordDecodeInt(serial_type,
-							&aKey1[d1]);
-				i64 rhs = pRhs->u.i;
-				if (lhs < rhs) {
-					rc = -1;
-				} else if (lhs > rhs) {
-					rc = +1;
-				}
-			}
-		}
-
-		/* RHS is real */
-		else if (pRhs->flags & MEM_Real) {
-			serial_type = aKey1[idx1];
-			if (serial_type >= 10) {
-				/* Serial types 12 or greater are strings and blobs (greater than
-				 * numbers). Types 10 and 11 are currently "reserved for future
-				 * use", so it doesn't really matter what the results of comparing
-				 * them to numberic values are.
-				 */
-				rc = +1;
-			} else if (serial_type == 0) {
-				rc = -1;
-			} else {
-				sqlite3VdbeSerialGet(&aKey1[d1], serial_type,
-						     &mem1);
-				if (serial_type == 7) {
-					if (mem1.u.r < pRhs->u.r) {
-						rc = -1;
-					} else if (mem1.u.r > pRhs->u.r) {
-						rc = +1;
-					}
-				} else {
-					rc = sqlite3IntFloatCompare(mem1.u.i,
-								    pRhs->u.r);
-				}
-			}
-		}
-
-		/* RHS is a string */
-		else if (pRhs->flags & MEM_Str) {
-			getVarint32(&aKey1[idx1], serial_type);
-			testcase(serial_type == 12);
-			if (serial_type < 12) {
-				rc = -1;
-			} else if (!(serial_type & 0x01)) {
-				rc = +1;
-			} else {
-				mem1.n = (serial_type - 12) / 2;
-				testcase((d1 + mem1.n) == (unsigned)nKey1);
-				testcase((d1 + mem1.n + 1) == (unsigned)nKey1);
-				if ((d1 + mem1.n) > (unsigned)nKey1) {
-					pPKey2->errCode =
-					    (u8) SQLITE_CORRUPT_BKPT;
-					return 0;	/* Corruption */
-				} else if (pKeyInfo->aColl[i]) {
-					mem1.db = pKeyInfo->db;
-					mem1.flags = MEM_Str;
-					mem1.z = (char *)&aKey1[d1];
-					rc = vdbeCompareMemString(&mem1, pRhs,
-								  pKeyInfo->
-								  aColl[i],
-								  &pPKey2->
-								  errCode);
-				} else {
-					int nCmp = MIN(mem1.n, pRhs->n);
-					rc = memcmp(&aKey1[d1], pRhs->z, nCmp);
-					if (rc == 0)
-						rc = mem1.n - pRhs->n;
-				}
-			}
-		}
-
-		/* RHS is a blob */
-		else if (pRhs->flags & MEM_Blob) {
-			assert((pRhs->flags & MEM_Zero) == 0 || pRhs->n == 0);
-			getVarint32(&aKey1[idx1], serial_type);
-			testcase(serial_type == 12);
-			if (serial_type < 12 || (serial_type & 0x01)) {
-				rc = -1;
-			} else {
-				int nStr = (serial_type - 12) / 2;
-				testcase((d1 + nStr) == (unsigned)nKey1);
-				testcase((d1 + nStr + 1) == (unsigned)nKey1);
-				if ((d1 + nStr) > (unsigned)nKey1) {
-					pPKey2->errCode =
-					    (u8) SQLITE_CORRUPT_BKPT;
-					return 0;	/* Corruption */
-				} else if (pRhs->flags & MEM_Zero) {
-					if (!isAllZero
-					    ((const char *)&aKey1[d1], nStr)) {
-						rc = 1;
-					} else {
-						rc = nStr - pRhs->u.nZero;
-					}
-				} else {
-					int nCmp = MIN(nStr, pRhs->n);
-					rc = memcmp(&aKey1[d1], pRhs->z, nCmp);
-					if (rc == 0)
-						rc = nStr - pRhs->n;
-				}
-			}
-		}
-
-		/* RHS is null */
-		else {
-			serial_type = aKey1[idx1];
-			rc = (serial_type != 0);
-		}
-
-		if (rc != 0) {
-			if (pKeyInfo->aSortOrder[i]) {
-				rc = -rc;
-			}
-			assert(vdbeRecordCompareDebug
-			       (nKey1, pKey1, pPKey2, rc));
-			assert(mem1.szMalloc == 0);	/* See comment below */
-			return rc;
-		}
-
-		i++;
-		pRhs++;
-		d1 += sqlite3VdbeSerialTypeLen(serial_type);
-		idx1 += sqlite3VarintLen(serial_type);
-	} while (idx1 < (unsigned)szHdr1 && i < pPKey2->nField
-		 && d1 <= (unsigned)nKey1);
-
-	/* No memory allocation is ever used on mem1.  Prove this using
-	 * the following assert().  If the assert() fails, it indicates a
-	 * memory leak and a need to call sqlite3VdbeMemRelease(&mem1).
-	 */
-	assert(mem1.szMalloc == 0);
-
-	/* rc==0 here means that one or both of the keys ran out of fields and
-	 * all the fields up to that point were equal. Return the default_rc
-	 * value.
-	 */
-	assert(CORRUPT_DB
-	       || vdbeRecordCompareDebug(nKey1, pKey1, pPKey2,
-					 pPKey2->default_rc)
-	       || pKeyInfo->db->mallocFailed);
-	pPKey2->eqSeen = 1;
-	return pPKey2->default_rc;
-}
-
-int
-sqlite3VdbeRecordCompare(int nKey1, const void *pKey1,	/* Left key */
-			 UnpackedRecord * pPKey2)	/* Right key */
-{
-	return sqlite3VdbeRecordCompareWithSkip(nKey1, pKey1, pPKey2, 0);
-}
-
-/*
- * Return a pointer to an sqlite3VdbeRecordCompare() compatible function
- * suitable for comparing serialized records to the unpacked record passed
- * as the only argument.
- */
-RecordCompare
-sqlite3VdbeFindCompare(UnpackedRecord * p)
-{
-	(void)p;
-	return sqlite3VdbeRecordCompareMsgpack;
-}
-
-/*
- * Compare the key of the index entry that cursor pC is pointing to against
- * the key string in pUnpacked.  Write into *pRes a number
- * that is negative, zero, or positive if pC is less than, equal to,
- * or greater than pUnpacked.  Return SQLITE_OK on success.
- */
-int
-sqlite3VdbeIdxKeyCompare(sqlite3 * db,			/* Database connection */
-			 VdbeCursor * pC,		/* The cursor to compare against */
-			 UnpackedRecord * pUnpacked,	/* Unpacked version of key */
-			 int *res)			/* Write the comparison result here */
-{
-	(void)db;
-	BtCursor *pCur;
-
-	assert(pC->eCurType == CURTYPE_TARANTOOL);
-	pCur = pC->uc.pCursor;
-	assert(sqlite3CursorIsValid(pCur));
-	if (pCur->curFlags & BTCF_TaCursor ||
-	    pCur->curFlags & BTCF_TEphemCursor) {
-		return tarantoolSqlite3IdxKeyCompare(pCur, pUnpacked, res);
-	}
-	unreachable();
-	return SQLITE_OK;
-}
-
 /*
  * This routine sets the value to be returned by subsequent calls to
  * sqlite3_changes() on the database handle 'db'.
-- 
2.15.1





More information about the Tarantool-patches mailing list