From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id 7B2662E55A for ; Thu, 23 May 2019 06:19:43 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 19tM0swhrbkp for ; Thu, 23 May 2019 06:19:43 -0400 (EDT) Received: from smtp36.i.mail.ru (smtp36.i.mail.ru [94.100.177.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id ADC5A2E51E for ; Thu, 23 May 2019 06:19:42 -0400 (EDT) From: Kirill Shcherbatov Subject: [tarantool-patches] [PATCH v5 2/6] sql: refactor OP_Column vdbe instruction Date: Thu, 23 May 2019 13:19:35 +0300 Message-Id: In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: tarantool-patches@freelists.org, v.shpilevoy@tarantool.org Cc: Kirill Shcherbatov 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->szMallocz = 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