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 5E6DD2F537 for ; Wed, 29 May 2019 10:01:44 -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 fEV9y1iBwCSL for ; Wed, 29 May 2019 10:01:44 -0400 (EDT) Received: from smtp47.i.mail.ru (smtp47.i.mail.ru [94.100.177.107]) (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 E466D2F528 for ; Wed, 29 May 2019 10:01:43 -0400 (EDT) From: Stanislav Zudin Subject: [tarantool-patches] [PATCH v2 9/9] sql: cleanup code from obsolete macros Date: Wed, 29 May 2019 17:01:31 +0300 Message-Id: <39a02dd81db696c3156bfe403413fbfb6dd34e69.1559138377.git.szudin@tarantool.org> In-Reply-To: References: In-Reply-To: References: 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, korablev@tarantool.org Cc: Stanislav Zudin Removes unused blocks enabled by SQL_OMIT_AUTOINCREMENT SQL_OMIT_CONFLICT_CLAUSE and SQL_OMIT_PRAGMA Removed the remains of multithreading in the VDBE sorting tools. Part of #3978 --- extra/mkkeywordhash.c | 12 ---- src/box/sql/vdbesort.c | 145 +++++++++++++++-------------------------- 2 files changed, 54 insertions(+), 103 deletions(-) diff --git a/extra/mkkeywordhash.c b/extra/mkkeywordhash.c index 5fbb82471..b83294cb3 100644 --- a/extra/mkkeywordhash.c +++ b/extra/mkkeywordhash.c @@ -55,25 +55,13 @@ struct Keyword { */ #define ALTER 0x00000001 #define ALWAYS 0x00000002 -#ifdef SQL_OMIT_AUTOINCREMENT -# define AUTOINCR 0 -#else # define AUTOINCR 0x00000010 -#endif # define CAST 0x00000020 # define COMPOUND 0x00000040 -#ifdef SQL_OMIT_CONFLICT_CLAUSE -# define CONFLICT 0 -#else # define CONFLICT 0x00000080 -#endif #define EXPLAIN 0x00000100 #define FKEY 0x00000200 -#ifdef SQL_OMIT_PRAGMA -# define PRAGMA 0 -#else # define PRAGMA 0x00000400 -#endif #define SUBQUERY 0x00001000 # define TRIGGER 0x00002000 # define VIEW 0x00008000 diff --git a/src/box/sql/vdbesort.c b/src/box/sql/vdbesort.c index a37fbd911..3d9d1663c 100644 --- a/src/box/sql/vdbesort.c +++ b/src/box/sql/vdbesort.c @@ -278,27 +278,12 @@ struct MergeEngine { * * Essentially, this structure contains all those fields of the VdbeSorter * structure for which each thread requires a separate instance. For example, - * each thread requries its own UnpackedRecord object to unpack records in + * each thread requires its own UnpackedRecord object to unpack records in * as part of comparison operations. - * - * Before a background thread is launched, variable bDone is set to 0. Then, - * right before it exits, the thread itself sets bDone to 1. This is used for - * the following purpose: - * - * When flushing the contents of memory to a level-0 PMA on disk, to - * attempt to select a SortSubtask for which there is not already an - * active background thread (since doing so causes the main thread - * to block until it finishes). - * - * The effects of the main thread seeing (bDone==0) even - * after the thread has finished are not dire. So we don't worry about - * memory barriers and such here. */ typedef int (*SorterCompare) (SortSubtask *, bool *, const void *, const void *); struct SortSubtask { - sqlThread *pThread; /* Background thread, if any */ - int bDone; /* Set if thread is finished but not joined */ VdbeSorter *pSorter; /* Sorter that owns this sub-task */ UnpackedRecord *pUnpacked; /* Space to unpack a record */ SorterList list; /* List for thread to write to a PMA */ @@ -331,11 +316,8 @@ struct VdbeSorter { int iMemory; /* Offset of free space in list.aMemory */ int nMemory; /* Size of list.aMemory allocation in bytes */ u8 bUsePMA; /* True if one or more PMAs created */ - u8 bUseThreads; /* True to use background threads */ - u8 iPrev; /* Previous thread used to flush PMA */ - u8 nTask; /* Size of aTask[] array */ u8 typeMask; - SortSubtask aTask[1]; /* One or more subtasks */ + SortSubtask aTask; /* A single subtask */ }; #define SORTER_TYPE_INTEGER 0x01 @@ -834,7 +816,6 @@ sqlVdbeSorterInit(sql * db, /* Database connection (for malloc()) */ ) { int pgsz; /* Page size of main database */ - int i; /* Used to iterate through aTask[] */ VdbeSorter *pSorter; /* The new sorter */ int rc = SQL_OK; @@ -848,14 +829,8 @@ sqlVdbeSorterInit(sql * db, /* Database connection (for malloc()) */ } else { pSorter->key_def = pCsr->key_def; pSorter->pgsz = pgsz = 1024; - pSorter->nTask = 1; - pSorter->iPrev = (u8) (-1); - pSorter->bUseThreads = (pSorter->nTask > 1); pSorter->db = db; - for (i = 0; i < pSorter->nTask; i++) { - SortSubtask *pTask = &pSorter->aTask[i]; - pTask->pSorter = pSorter; - } + pSorter->aTask.pSorter = pSorter; i64 mxCache; /* Cache size in bytes */ u32 szPma = sqlGlobalConfig.szPma; @@ -992,16 +967,12 @@ vdbeIncrFree(IncrMerger * pIncr) void sqlVdbeSorterReset(sql * db, VdbeSorter * pSorter) { - int i; (void)vdbeSorterJoinAll(pSorter, SQL_OK); - assert(pSorter->bUseThreads || pSorter->pReader == 0); + assert(pSorter->pReader == 0); vdbeMergeEngineFree(pSorter->pMerger); pSorter->pMerger = 0; - for (i = 0; i < pSorter->nTask; i++) { - SortSubtask *pTask = &pSorter->aTask[i]; - vdbeSortSubtaskCleanup(db, pTask); - pTask->pSorter = pSorter; - } + vdbeSortSubtaskCleanup(db, &pSorter->aTask); + pSorter->aTask.pSorter = pSorter; if (pSorter->list.aMemory == 0) { vdbeSorterRecordFree(0, pSorter->list.pList); } @@ -1482,7 +1453,7 @@ static int vdbeSorterFlushPMA(VdbeSorter * pSorter) { pSorter->bUsePMA = 1; - return vdbeSorterListToPMA(&pSorter->aTask[0], &pSorter->list); + return vdbeSorterListToPMA(&pSorter->aTask, &pSorter->list); } /* @@ -2011,54 +1982,51 @@ vdbeSorterMergeTreeBuild(VdbeSorter * pSorter, /* The VDBE cursor that implement { MergeEngine *pMain = 0; int rc = SQL_OK; - int iTask; - - for (iTask = 0; rc == SQL_OK && iTask < pSorter->nTask; iTask++) { - SortSubtask *pTask = &pSorter->aTask[iTask]; - assert(pTask->nPMA > 0); - if (pTask->nPMA) { - MergeEngine *pRoot = 0; /* Root node of tree for this task */ - int nDepth = vdbeSorterTreeDepth(pTask->nPMA); - i64 iReadOff = 0; - - if (pTask->nPMA <= SORTER_MAX_MERGE_COUNT) { - rc = vdbeMergeEngineLevel0(pTask, pTask->nPMA, - &iReadOff, &pRoot); - } else { - int i; - int iSeq = 0; - pRoot = - vdbeMergeEngineNew(SORTER_MAX_MERGE_COUNT); - if (pRoot == 0) - rc = SQL_NOMEM; - for (i = 0; i < pTask->nPMA && rc == SQL_OK; - i += SORTER_MAX_MERGE_COUNT) { - MergeEngine *pMerger = 0; /* New level-0 PMA merger */ - int nReader; /* Number of level-0 PMAs to merge */ - - nReader = - MIN(pTask->nPMA - i, - SORTER_MAX_MERGE_COUNT); - rc = vdbeMergeEngineLevel0(pTask, - nReader, - &iReadOff, - &pMerger); - if (rc == SQL_OK) { - rc = vdbeSorterAddToTree(pTask, - nDepth, - iSeq++, - pRoot, - pMerger); - } + + SortSubtask *pTask = &pSorter->aTask; + assert(pTask->nPMA > 0); + if (pTask->nPMA) { + MergeEngine *pRoot = 0; /* Root node of tree for this task */ + int nDepth = vdbeSorterTreeDepth(pTask->nPMA); + i64 iReadOff = 0; + + if (pTask->nPMA <= SORTER_MAX_MERGE_COUNT) { + rc = vdbeMergeEngineLevel0(pTask, pTask->nPMA, + &iReadOff, &pRoot); + } else { + int i; + int iSeq = 0; + pRoot = + vdbeMergeEngineNew(SORTER_MAX_MERGE_COUNT); + if (pRoot == 0) + rc = SQL_NOMEM; + for (i = 0; i < pTask->nPMA && rc == SQL_OK; + i += SORTER_MAX_MERGE_COUNT) { + MergeEngine *pMerger = 0; /* New level-0 PMA merger */ + int nReader; /* Number of level-0 PMAs to merge */ + + nReader = + MIN(pTask->nPMA - i, + SORTER_MAX_MERGE_COUNT); + rc = vdbeMergeEngineLevel0(pTask, + nReader, + &iReadOff, + &pMerger); + if (rc == SQL_OK) { + rc = vdbeSorterAddToTree(pTask, + nDepth, + iSeq++, + pRoot, + pMerger); } } + } - if (rc == SQL_OK) { - assert(pMain == 0); - pMain = pRoot; - } else { - vdbeMergeEngineFree(pRoot); - } + if (rc == SQL_OK) { + assert(pMain == 0); + pMain = pRoot; + } else { + vdbeMergeEngineFree(pRoot); } } @@ -2083,12 +2051,11 @@ static int vdbeSorterSetupMerge(VdbeSorter * pSorter) { int rc; /* Return code */ - SortSubtask *pTask0 = &pSorter->aTask[0]; MergeEngine *pMain = 0; rc = vdbeSorterMergeTreeBuild(pSorter, &pMain); if (rc == SQL_OK) { - rc = vdbeMergeEngineInit(pTask0, pMain); + rc = vdbeMergeEngineInit(&pSorter->aTask, pMain); pSorter->pMerger = pMain; pMain = 0; } @@ -2121,7 +2088,7 @@ sqlVdbeSorterRewind(const VdbeCursor * pCsr, int *pbEof) if (pSorter->bUsePMA == 0) { if (pSorter->list.pList) { *pbEof = 0; - rc = vdbeSorterSort(&pSorter->aTask[0], &pSorter->list); + rc = vdbeSorterSort(&pSorter->aTask, &pSorter->list); } else { *pbEof = 1; } @@ -2166,13 +2133,9 @@ sqlVdbeSorterNext(sql * db, const VdbeCursor * pCsr, int *pbEof) || (pSorter->pReader == 0 && pSorter->pMerger == 0)); if (pSorter->bUsePMA) { assert(pSorter->pReader == 0 || pSorter->pMerger == 0); - assert(pSorter->bUseThreads == 0 || pSorter->pReader); - assert(pSorter->bUseThreads == 1 || pSorter->pMerger); - /*if( !pSorter->bUseThreads ) */ { - assert(pSorter->pMerger != 0); - assert(pSorter->pMerger->pTask == (&pSorter->aTask[0])); - rc = vdbeMergeEngineStep(pSorter->pMerger, pbEof); - } + assert(pSorter->pMerger); + assert(pSorter->pMerger->pTask == &pSorter->aTask); + rc = vdbeMergeEngineStep(pSorter->pMerger, pbEof); } else { SorterRecord *pFree = pSorter->list.pList; pSorter->list.pList = pFree->u.pNext; -- 2.17.1