diff --git a/common/thorhelper/thorsort.hpp b/common/thorhelper/thorsort.hpp index f158fd0e2f3..4fa00a0cfb3 100644 --- a/common/thorhelper/thorsort.hpp +++ b/common/thorhelper/thorsort.hpp @@ -23,20 +23,9 @@ #include "thorhelper.hpp" #include "jsort.hpp" -//#define DEFAULT_MERGE_SORT - extern THORHELPER_API void msortvecstableinplace(void ** rows, size_t n, const ICompare & compare, void ** temp); extern THORHELPER_API void parmsortvecstableinplace(void ** rows, size_t n, const ICompare & compare, void ** temp); -inline void parsortvecstableinplace(void ** rows, size_t n, const ICompare & compare, void ** stableTablePtr, unsigned maxCores=0) -{ -#ifdef DEFAULT_MERGE_SORT - parmsortvecstableinplace(rows, n, compare, stableTablePtr); -#else - parqsortvecstableinplace(rows, n, compare, stableTablePtr, maxCores); -#endif -} - extern THORHELPER_API void tbbqsortvec(void **a, size_t n, const ICompare & compare); extern THORHELPER_API void tbbqsortstable(void ** rows, size_t n, const ICompare & compare, void ** temp); diff --git a/thorlcr/thorutil/thmem.cpp b/thorlcr/thorutil/thmem.cpp index 5647704fdc6..1c856f501ae 100644 --- a/thorlcr/thorutil/thmem.cpp +++ b/thorlcr/thorutil/thmem.cpp @@ -596,7 +596,10 @@ void CThorExpandingRowArray::doSort(rowidx_t n, void **const rows, ICompare &com dbgassertex(NULL != stableTable); stableTablePtr = stableTable; } - parsortvecstableinplace(rows, n, compare, stableTablePtr, maxCores); + if (useMergeSort) + parmsortvecstableinplace(rows, n, compare, stableTablePtr); + else + parqsortvecstableinplace(rows, n, compare, stableTablePtr, maxCores); } else parqsortvec((void **)rows, n, compare, maxCores); @@ -720,6 +723,12 @@ void CThorExpandingRowArray::setup(IThorRowInterfaces *_rowIf, EmptyRowSemantics ReleaseThorRow(stableTable); stableTable = NULL; } + if (stableSort_none != stableSort) + { + StringBuffer algorithm; + activity.getOpt(THOROPT_SORT_ALGORITHM, algorithm); + useMergeSort = !strieq(algorithm, "quicksort"); + } } void CThorExpandingRowArray::clearRows() diff --git a/thorlcr/thorutil/thmem.hpp b/thorlcr/thorutil/thmem.hpp index eeb371a31e1..ac7a1dd60ee 100644 --- a/thorlcr/thorutil/thmem.hpp +++ b/thorlcr/thorutil/thmem.hpp @@ -281,6 +281,7 @@ class graph_decl CThorExpandingRowArray : public CSimpleInterface const void **rows = nullptr; void **stableTable = nullptr; bool throwOnOom = true; // tested during array expansion (resize()) + bool useMergeSort = true; EmptyRowSemantics emptyRowSemantics = ers_forbidden; StableSortFlag stableSort = stableSort_none; rowidx_t maxRows = 0; // Number of rows that can fit in the allocated memory. diff --git a/thorlcr/thorutil/thormisc.hpp b/thorlcr/thorutil/thormisc.hpp index 2bfbc0d5998..6ab3bd784d1 100644 --- a/thorlcr/thorutil/thormisc.hpp +++ b/thorlcr/thorutil/thormisc.hpp @@ -113,6 +113,7 @@ #define THOROPT_MEMORY_SPILL_AT "memorySpillAt" // The threshold (%) that roxiemem will request memory to be reduced (default=80) #define THOROPT_FAIL_ON_LEAKS "failOnLeaks" // If any leaks are detected at the end of graph, fail the query (default=false) #define THOROPT_SOAP_TRACE_LEVEL "soapTraceLevel" // The trace SOAP level (default=1) +#define THOROPT_SORT_ALGORITHM "sortAlgorithm" // The algorithm used to sort records (quicksort/mergesort) #define INITIAL_SELFJOIN_MATCH_WARNING_LEVEL 20000 // max of row matches before selfjoin emits warning