[tarantool-patches] [PATCH v5 2/6] sql: refactor OP_Column vdbe instruction
Kirill Shcherbatov
kshcherbatov at tarantool.org
Thu May 23 13:19:35 MSK 2019
This preparatory refactoring is necessary to simplify the process
of introducing a new OP_Fetch statement in the next patch.
- got rid of useless sMem local variable
- got rid of useless payloadSize in VdbeCursor structure
Needed for #3691
---
src/box/sql/vdbe.c | 35 +++++++----------------------------
src/box/sql/vdbeInt.h | 1 -
2 files changed, 7 insertions(+), 29 deletions(-)
diff --git a/src/box/sql/vdbe.c b/src/box/sql/vdbe.c
index 11f5685f3..5d37f63fb 100644
--- a/src/box/sql/vdbe.c
+++ b/src/box/sql/vdbe.c
@@ -2600,7 +2600,6 @@ case OP_Column: {
u32 *aOffset; /* aOffset[i] is offset to start of data for i-th column */
int i; /* Loop counter */
Mem *pDest; /* Where to write the extracted value */
- Mem sMem; /* For storing the record being decoded */
const u8 *zData; /* Part of the record being decoded */
const u8 MAYBE_UNUSED *zEnd; /* Data end */
const u8 *zParse; /* Next unparsed byte of the row */
@@ -2626,7 +2625,7 @@ case OP_Column: {
pReg = &aMem[pC->uc.pseudoTableReg];
assert(pReg->flags & MEM_Blob);
assert(memIsValid(pReg));
- pC->payloadSize = pC->szRow = pReg->n;
+ pC->szRow = pReg->n;
pC->aRow = (u8*)pReg->z;
} else {
sqlVdbeMemSetNull(pDest);
@@ -2639,9 +2638,7 @@ case OP_Column: {
assert(sqlCursorIsValid(pCrsr));
assert(pCrsr->curFlags & BTCF_TaCursor ||
pCrsr->curFlags & BTCF_TEphemCursor);
- pC->aRow = tarantoolsqlPayloadFetch(pCrsr,
- &pC->payloadSize);
- pC->szRow = pC->payloadSize;
+ pC->aRow = tarantoolsqlPayloadFetch(pCrsr, &pC->szRow);
}
pC->cacheStatus = p->cacheCtr;
@@ -2659,22 +2656,8 @@ case OP_Column: {
}
goto op_column_out;
}
-
- /* Sometimes the data is too large and overflow pages come into play.
- * In the later case allocate a buffer and reassamble the row.
- * Stock sql utilized several clever techniques to optimize here.
- * The techniques we ripped out to simplify the code.
- */
- if (pC->szRow==pC->payloadSize) {
- zData = pC->aRow;
- zEnd = zData + pC->payloadSize;
- } else {
- memset(&sMem, 0, sizeof(sMem));
- rc = sqlVdbeMemFromBtree(pC->uc.pCursor, 0, pC->payloadSize, &sMem);
- if (rc!=SQL_OK) goto abort_due_to_error;
- zData = (u8*)sMem.z;
- zEnd = zData + pC->payloadSize;
- }
+ zData = pC->aRow;
+ zEnd = zData + pC->szRow;
/*
* Make sure at least the first p2+1 entries of the header
@@ -2767,7 +2750,8 @@ case OP_Column: {
if ((pDest->flags & (MEM_Ephem | MEM_Str)) == (MEM_Ephem | MEM_Str)) {
int len = pDest->n;
if (pDest->szMalloc<len+1) {
- if (sqlVdbeMemGrow(pDest, len+1, 1)) goto op_column_error;
+ if (sqlVdbeMemGrow(pDest, len+1, 1))
+ goto abort_due_to_error;
} else {
pDest->z = memcpy(pDest->zMalloc, pDest->z, len);
pDest->flags &= ~MEM_Ephem;
@@ -2776,15 +2760,10 @@ case OP_Column: {
pDest->flags |= MEM_Term;
}
- if (zData!=pC->aRow) sqlVdbeMemRelease(&sMem);
- op_column_out:
+op_column_out:
UPDATE_MAX_BLOBSIZE(pDest);
REGISTER_TRACE(p, pOp->p3, pDest);
break;
-
- op_column_error:
- if (zData!=pC->aRow) sqlVdbeMemRelease(&sMem);
- goto abort_due_to_error;
}
/* Opcode: ApplyType P1 P2 * P4 *
diff --git a/src/box/sql/vdbeInt.h b/src/box/sql/vdbeInt.h
index 240283927..d58e3df7b 100644
--- a/src/box/sql/vdbeInt.h
+++ b/src/box/sql/vdbeInt.h
@@ -114,7 +114,6 @@ struct VdbeCursor {
i16 nField; /* Number of fields in the header */
u16 nHdrParsed; /* Number of header fields parsed so far */
const u8 *aRow; /* Data for the current row, if all on one page */
- u32 payloadSize; /* Total number of bytes in the record */
u32 szRow; /* Byte available in aRow */
#ifdef SQL_ENABLE_COLUMN_USED_MASK
u64 maskUsed; /* Mask of columns used by this cursor */
--
2.21.0
More information about the Tarantool-patches
mailing list