From e7b43b8299337c02229885c8e757f8e9228c879c Mon Sep 17 00:00:00 2001 From: Alexey Antipovsky Date: Wed, 16 Dec 2020 22:39:46 +0300 Subject: [PATCH] MCOL-4455 Fix ignoring LIMIT offset "SELECT DISTINCT col FROM table LIMIT O,N" should skip first O rows --- dbcon/joblist/tupleannexstep.cpp | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/dbcon/joblist/tupleannexstep.cpp b/dbcon/joblist/tupleannexstep.cpp index 6861681a5..cca0977ba 100644 --- a/dbcon/joblist/tupleannexstep.cpp +++ b/dbcon/joblist/tupleannexstep.cpp @@ -513,26 +513,31 @@ void TupleAnnexStep::executeNoOrderByWithDistinct() { pair inserted; - if (fConstant) - fConstant->fillInConstants(fRowIn, fRowOut); - else - copyRow(fRowIn, &fRowOut); - + inserted = distinctMap->insert(fRowIn.getPointer()); ++fRowsProcessed; - fRowIn.nextRow(); - - inserted = distinctMap->insert(fRowOut.getPointer()); if (inserted.second) { + // skip first limit-start rows + if (distinctMap->size() <= fLimitStart) + { + fRowIn.nextRow(); + continue; + } + if (UNLIKELY(fRowsReturned >= fLimitCount)) { fLimitHit = true; fJobList->abortOnLimit((JobStep*) this); - continue; + break; } ++fRowsReturned; + if (fConstant) + fConstant->fillInConstants(fRowIn, fRowOut); + else + copyRow(fRowIn, &fRowOut); + fRowGroupOut.incRowCount(); fRowOut.nextRow(); @@ -545,6 +550,8 @@ void TupleAnnexStep::executeNoOrderByWithDistinct() fRowGroupOut.getRow(0, &fRowOut); } } + + fRowIn.nextRow(); } more = fInputDL->next(fInputIterator, &rgDataIn);