feat(query): enable selectivity with first/last for stable
This commit is contained in:
parent
d91443ce71
commit
c3d26dc73e
|
@ -2409,11 +2409,11 @@ int32_t apercentileCombine(SqlFunctionCtx* pDestCtx, SqlFunctionCtx* pSourceCtx)
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t getFirstLastInfoSize(int32_t resBytes) { return sizeof(SFirstLastRes) + resBytes + sizeof(int64_t); }
|
int32_t getFirstLastInfoSize(int32_t resBytes) { return sizeof(SFirstLastRes) + resBytes + sizeof(int64_t) + sizeof(STuplePos); }
|
||||||
|
|
||||||
bool getFirstLastFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
|
bool getFirstLastFuncEnv(SFunctionNode* pFunc, SFuncExecEnv* pEnv) {
|
||||||
SColumnNode* pNode = (SColumnNode*)nodesListGetNode(pFunc->pParameterList, 0);
|
SColumnNode* pNode = (SColumnNode*)nodesListGetNode(pFunc->pParameterList, 0);
|
||||||
pEnv->calcMemSize = sizeof(SFirstLastRes) + pNode->node.resType.bytes + sizeof(int64_t) + sizeof(STuplePos);
|
pEnv->calcMemSize = getFirstLastInfoSize(pNode->node.resType.bytes);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2642,7 +2642,10 @@ int32_t lastFunction(SqlFunctionCtx* pCtx) {
|
||||||
return TSDB_CODE_SUCCESS;
|
return TSDB_CODE_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void firstLastTransferInfo(SFirstLastRes* pInput, SFirstLastRes* pOutput, bool isFirst) {
|
static void firstLastTransferInfo(SqlFunctionCtx* pCtx, SFirstLastRes* pInput, SFirstLastRes* pOutput, bool isFirst) {
|
||||||
|
SInputColumnInfoData* pColInfo = &pCtx->input;
|
||||||
|
int32_t start = pColInfo->startRowIndex;
|
||||||
|
|
||||||
pOutput->bytes = pInput->bytes;
|
pOutput->bytes = pInput->bytes;
|
||||||
TSKEY* tsIn = (TSKEY*)(pInput->buf + pInput->bytes);
|
TSKEY* tsIn = (TSKEY*)(pInput->buf + pInput->bytes);
|
||||||
TSKEY* tsOut = (TSKEY*)(pOutput->buf + pInput->bytes);
|
TSKEY* tsOut = (TSKEY*)(pOutput->buf + pInput->bytes);
|
||||||
|
@ -2659,7 +2662,14 @@ static void firstLastTransferInfo(SFirstLastRes* pInput, SFirstLastRes* pOutput,
|
||||||
}
|
}
|
||||||
*tsOut = *tsIn;
|
*tsOut = *tsIn;
|
||||||
memcpy(pOutput->buf, pInput->buf, pOutput->bytes);
|
memcpy(pOutput->buf, pInput->buf, pOutput->bytes);
|
||||||
pOutput->hasResult = true;
|
//handle selectivity
|
||||||
|
STuplePos* pTuplePos = (STuplePos*)(pOutput->buf + pOutput->bytes + sizeof(TSKEY));
|
||||||
|
if (!pOutput->hasResult) {
|
||||||
|
saveTupleData(pCtx, start, pCtx->pSrcBlock, pTuplePos);
|
||||||
|
pOutput->hasResult = true;
|
||||||
|
} else {
|
||||||
|
copyTupleData(pCtx, start, pCtx->pSrcBlock, pTuplePos);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2674,7 +2684,7 @@ static int32_t firstLastFunctionMergeImpl(SqlFunctionCtx* pCtx, bool isFirstQuer
|
||||||
char* data = colDataGetData(pCol, start);
|
char* data = colDataGetData(pCol, start);
|
||||||
SFirstLastRes* pInputInfo = (SFirstLastRes*)varDataVal(data);
|
SFirstLastRes* pInputInfo = (SFirstLastRes*)varDataVal(data);
|
||||||
|
|
||||||
firstLastTransferInfo(pInputInfo, pInfo, isFirstQuery);
|
firstLastTransferInfo(pCtx, pInputInfo, pInfo, isFirstQuery);
|
||||||
|
|
||||||
int32_t numOfElems = pInputInfo->hasResult ? 1 : 0;
|
int32_t numOfElems = pInputInfo->hasResult ? 1 : 0;
|
||||||
|
|
||||||
|
@ -2696,6 +2706,7 @@ int32_t firstLastFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
||||||
|
|
||||||
SFirstLastRes* pRes = GET_ROWCELL_INTERBUF(pResInfo);
|
SFirstLastRes* pRes = GET_ROWCELL_INTERBUF(pResInfo);
|
||||||
colDataAppend(pCol, pBlock->info.rows, pRes->buf, pResInfo->isNullRes);
|
colDataAppend(pCol, pBlock->info.rows, pRes->buf, pResInfo->isNullRes);
|
||||||
|
//handle selectivity
|
||||||
STuplePos* pTuplePos = (STuplePos*)(pRes->buf + pRes->bytes + sizeof(TSKEY));
|
STuplePos* pTuplePos = (STuplePos*)(pRes->buf + pRes->bytes + sizeof(TSKEY));
|
||||||
setSelectivityValue(pCtx, pBlock, pTuplePos, pBlock->info.rows);
|
setSelectivityValue(pCtx, pBlock, pTuplePos, pBlock->info.rows);
|
||||||
|
|
||||||
|
@ -2716,6 +2727,9 @@ int32_t firstLastPartialFinalize(SqlFunctionCtx* pCtx, SSDataBlock* pBlock) {
|
||||||
SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId);
|
SColumnInfoData* pCol = taosArrayGet(pBlock->pDataBlock, slotId);
|
||||||
|
|
||||||
colDataAppend(pCol, pBlock->info.rows, res, false);
|
colDataAppend(pCol, pBlock->info.rows, res, false);
|
||||||
|
//handle selectivity
|
||||||
|
STuplePos* pTuplePos = (STuplePos*)(pRes->buf + pRes->bytes + sizeof(TSKEY));
|
||||||
|
setSelectivityValue(pCtx, pBlock, pTuplePos, pBlock->info.rows);
|
||||||
|
|
||||||
taosMemoryFree(res);
|
taosMemoryFree(res);
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -562,7 +562,7 @@ class TDTestCase:
|
||||||
tdSql.checkRows(3)
|
tdSql.checkRows(3)
|
||||||
tdSql.query("select round(dataint) from jsons1 where jtag->'tag1'>1")
|
tdSql.query("select round(dataint) from jsons1 where jtag->'tag1'>1")
|
||||||
tdSql.checkRows(3)
|
tdSql.checkRows(3)
|
||||||
|
|
||||||
#math function
|
#math function
|
||||||
tdSql.query("select sin(dataint) from jsons1 where jtag->'tag1'>1;")
|
tdSql.query("select sin(dataint) from jsons1 where jtag->'tag1'>1;")
|
||||||
tdSql.checkRows(3)
|
tdSql.checkRows(3)
|
||||||
|
@ -606,7 +606,7 @@ class TDTestCase:
|
||||||
tdSql.checkRows(1)
|
tdSql.checkRows(1)
|
||||||
tdSql.query("select twa(dataint) from jsons1 where jtag->'tag1'>1;")
|
tdSql.query("select twa(dataint) from jsons1 where jtag->'tag1'>1;")
|
||||||
tdSql.checkRows(1)
|
tdSql.checkRows(1)
|
||||||
|
|
||||||
# function not ready
|
# function not ready
|
||||||
# tdSql.query("select tail(dataint,1) from jsons1 where jtag->'tag1'>1;")
|
# tdSql.query("select tail(dataint,1) from jsons1 where jtag->'tag1'>1;")
|
||||||
# tdSql.checkRows(3)
|
# tdSql.checkRows(3)
|
||||||
|
@ -616,7 +616,7 @@ class TDTestCase:
|
||||||
# tdSql.checkRows(3)
|
# tdSql.checkRows(3)
|
||||||
# tdSql.query("select irate(dataint) from jsons1 where jtag->'tag1'>1;")
|
# tdSql.query("select irate(dataint) from jsons1 where jtag->'tag1'>1;")
|
||||||
# tdSql.checkRows(1)
|
# tdSql.checkRows(1)
|
||||||
|
|
||||||
#str function
|
#str function
|
||||||
tdSql.query("select upper(dataStr) from jsons1 where jtag->'tag1'>1;")
|
tdSql.query("select upper(dataStr) from jsons1 where jtag->'tag1'>1;")
|
||||||
tdSql.checkRows(3)
|
tdSql.checkRows(3)
|
||||||
|
@ -658,7 +658,7 @@ class TDTestCase:
|
||||||
tdSql.checkRows(3)
|
tdSql.checkRows(3)
|
||||||
tdSql.query("select ELAPSED(ts,1h) from jsons1 where jtag->'tag1'>1;")
|
tdSql.query("select ELAPSED(ts,1h) from jsons1 where jtag->'tag1'>1;")
|
||||||
tdSql.checkRows(1)
|
tdSql.checkRows(1)
|
||||||
|
|
||||||
#
|
#
|
||||||
# #test TD-12077
|
# #test TD-12077
|
||||||
tdSql.execute("insert into jsons1_16 using jsons1 tags('{\"tag1\":\"收到货\",\"tag2\":\"\",\"tag3\":-2.111}') values(1591062628000, 2, NULL, '你就会', 'dws')")
|
tdSql.execute("insert into jsons1_16 using jsons1 tags('{\"tag1\":\"收到货\",\"tag2\":\"\",\"tag3\":-2.111}') values(1591062628000, 2, NULL, '你就会', 'dws')")
|
||||||
|
|
Loading…
Reference in New Issue