diff --git a/utils/windowfunction/wf_count.cpp b/utils/windowfunction/wf_count.cpp index a37ad996d..1c5ba1c57 100644 --- a/utils/windowfunction/wf_count.cpp +++ b/utils/windowfunction/wf_count.cpp @@ -112,37 +112,57 @@ void WF_count::operator()(int64_t b, int64_t e, int64_t c) // for count(*), the column is optimized out, index[1] does not exist. int64_t colIn = (fFunctionId == WF__COUNT_ASTERISK) ? 0 : fFieldIndex[1]; - for (int64_t i = b; i <= e; i++) + // constant param will have fFieldIndex[1] of -1. Get value of constant param + if (colIn == -1) { - if (i % 1000 == 0 && fStep->cancelled()) - break; + ConstantColumn* cc = static_cast(fConstantParms[0].get()); - if (fFunctionId == WF__COUNT_ASTERISK) + if (cc) { - fCount++; - continue; + bool isNull = false; + int val = cc->getIntVal(fRow, isNull); + + if (!isNull) + { + fCount = val; + } } + } + else + { - fRow.setData(getPointer(fRowData->at(i))); - - if (colIn == -1 || fRow.isNullValue(colIn) == true) - continue; - - if (fFunctionId != WF__COUNT_DISTINCT) + for (int64_t i = b; i <= e; i++) { - fCount++; - } - else - { - T valIn; - getValue(colIn, valIn); + if (i % 1000 == 0 && fStep->cancelled()) + break; - if (fSet.find(valIn) == fSet.end()) + if (fFunctionId == WF__COUNT_ASTERISK) { fCount++; + continue; + } - if (fFunctionId == WF__COUNT_DISTINCT) - fSet.insert(valIn); + fRow.setData(getPointer(fRowData->at(i))); + + if (fRow.isNullValue(colIn) == true) + continue; + + if (fFunctionId != WF__COUNT_DISTINCT) + { + fCount++; + } + else + { + T valIn; + getValue(colIn, valIn); + + if (fSet.find(valIn) == fSet.end()) + { + fCount++; + + if (fFunctionId == WF__COUNT_DISTINCT) + fSet.insert(valIn); + } } } }