From: Stanislav Zudin <szudin@tarantool.org>
To: tarantool-patches@freelists.org, korablev@tarantool.org
Cc: Stanislav Zudin <szudin@tarantool.org>
Subject: [tarantool-patches] [PATCH v2 9/9] sql: cleanup code from obsolete macros
Date: Wed, 29 May 2019 17:01:31 +0300 [thread overview]
Message-ID: <39a02dd81db696c3156bfe403413fbfb6dd34e69.1559138377.git.szudin@tarantool.org> (raw)
In-Reply-To: <cover.1559138377.git.szudin@tarantool.org>
In-Reply-To: <cover.1559138377.git.szudin@tarantool.org>
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
---
| 12 ----
src/box/sql/vdbesort.c | 145 +++++++++++++++--------------------------
2 files changed, 54 insertions(+), 103 deletions(-)
--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
next prev parent reply other threads:[~2019-05-29 14:01 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-29 14:01 [tarantool-patches] [PATCH v2 0/9] " Stanislav Zudin
2019-05-29 14:01 ` [tarantool-patches] [PATCH v2 1/9] " Stanislav Zudin
2019-05-29 14:01 ` [tarantool-patches] [PATCH v2 2/9] Removes unused functions and commented many years ago code Stanislav Zudin
2019-05-29 14:01 ` [tarantool-patches] [PATCH v2 3/9] Removes unused functions Stanislav Zudin
2019-05-29 14:01 ` [tarantool-patches] [PATCH v2 4/9] Removes unused functions and macros Stanislav Zudin
2019-05-29 14:01 ` [tarantool-patches] [PATCH v2 5/9] Removes the following unused macros: SQL_ENABLE_MEMORY_MANAGEMENT SQL_ENABLE_UNKNOWN_SQL_FUNCTION SQL_SUBSTR_COMPATIBILITY SQL_ENABLE_STMT_SCANSTATUS Stanislav Zudin
2019-05-29 14:01 ` [tarantool-patches] [PATCH v2 6/9] sql: cleanup code from obsolete macros Stanislav Zudin
2019-05-29 14:01 ` [tarantool-patches] [PATCH v2 7/9] Removes unused constants Stanislav Zudin
2019-05-29 14:01 ` [tarantool-patches] [PATCH v2 8/9] Removes the following unused macros: SQL_PRINTF_PRECISION_LIMIT SQL_OMIT_COMPOUND_SELECT SQL_POWERSAFE_OVERWRITE SQL_OMIT_PROGRESS_CALLBACK SQL_OMIT_AUTORESET SQL_OMIT_DECLTYPE SQL_ENABLE_COLUMN_METADATA SQL_TRACE_SIZE_LIMIT SQL_OMIT_LIKE_OPTIMIZATION SQL_OMIT_OR_OPTIMIZATION SQL_OMIT_BETWEEN_OPTIMIZATION Stanislav Zudin
2019-05-29 14:01 ` Stanislav Zudin [this message]
2019-06-06 18:22 ` [tarantool-patches] Re: [PATCH v2 0/9] sql: cleanup code from obsolete macros n.pettik
2019-06-07 11:57 ` Stanislav Zudin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=39a02dd81db696c3156bfe403413fbfb6dd34e69.1559138377.git.szudin@tarantool.org \
--to=szudin@tarantool.org \
--cc=korablev@tarantool.org \
--cc=tarantool-patches@freelists.org \
--subject='Re: [tarantool-patches] [PATCH v2 9/9] sql: cleanup code from obsolete macros' \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox