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);