[td-225] refactor
This commit is contained in:
parent
40bdfdb2f8
commit
9b224d9bbc
|
@ -237,6 +237,17 @@ typedef struct SQuery {
|
||||||
STableGroupInfo tableGroupInfo; // table <tid, last_key> list SArray<STableKeyInfo>
|
STableGroupInfo tableGroupInfo; // table <tid, last_key> list SArray<STableKeyInfo>
|
||||||
} SQuery;
|
} SQuery;
|
||||||
|
|
||||||
|
typedef SSDataBlock* (*__operator_fn_t)(void* param);
|
||||||
|
|
||||||
|
typedef struct SOperatorInfo {
|
||||||
|
char *name;
|
||||||
|
bool blockingOptr;
|
||||||
|
void *optInfo;
|
||||||
|
|
||||||
|
__operator_fn_t exec;
|
||||||
|
struct SOperatorInfo *upstream;
|
||||||
|
} SOperatorInfo;
|
||||||
|
|
||||||
typedef struct SQueryRuntimeEnv {
|
typedef struct SQueryRuntimeEnv {
|
||||||
jmp_buf env;
|
jmp_buf env;
|
||||||
SQuery* pQuery;
|
SQuery* pQuery;
|
||||||
|
@ -329,8 +340,6 @@ typedef struct SQueryParam {
|
||||||
SSqlGroupbyExpr *pGroupbyExpr;
|
SSqlGroupbyExpr *pGroupbyExpr;
|
||||||
} SQueryParam;
|
} SQueryParam;
|
||||||
|
|
||||||
typedef SSDataBlock* (*__operator_fn_t)(void* param);
|
|
||||||
|
|
||||||
typedef struct STableScanInfo {
|
typedef struct STableScanInfo {
|
||||||
SQueryRuntimeEnv *pRuntimeEnv;
|
SQueryRuntimeEnv *pRuntimeEnv;
|
||||||
void *pQueryHandle;
|
void *pQueryHandle;
|
||||||
|
@ -350,23 +359,19 @@ typedef struct STableScanInfo {
|
||||||
int64_t elapsedTime;
|
int64_t elapsedTime;
|
||||||
} STableScanInfo;
|
} STableScanInfo;
|
||||||
|
|
||||||
typedef struct SOperatorInfo {
|
|
||||||
char *name;
|
|
||||||
bool blockingOptr;
|
|
||||||
void *optInfo;
|
|
||||||
|
|
||||||
__operator_fn_t exec;
|
|
||||||
} SOperatorInfo;
|
|
||||||
|
|
||||||
SOperatorInfo optrList[5];
|
SOperatorInfo optrList[5];
|
||||||
|
|
||||||
typedef struct SAggOperatorInfo {
|
typedef struct SAggOperatorInfo {
|
||||||
SResultRowInfo *pResultRowInfo;
|
SResultRowInfo *pResultRowInfo;
|
||||||
STableQueryInfo *pTableQueryInfo;
|
STableQueryInfo *pTableQueryInfo;
|
||||||
SOperatorInfo *prevOptr;
|
|
||||||
SQueryRuntimeEnv *pRuntimeEnv;
|
SQueryRuntimeEnv *pRuntimeEnv;
|
||||||
} SAggOperatorInfo;
|
} SAggOperatorInfo;
|
||||||
|
|
||||||
|
typedef struct SArithOperatorInfo {
|
||||||
|
STableQueryInfo *pTableQueryInfo;
|
||||||
|
SQueryRuntimeEnv *pRuntimeEnv;
|
||||||
|
} SArithOperatorInfo;
|
||||||
|
|
||||||
void freeParam(SQueryParam *param);
|
void freeParam(SQueryParam *param);
|
||||||
int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SQueryParam* param);
|
int32_t convertQueryMsg(SQueryTableMsg *pQueryMsg, SQueryParam* param);
|
||||||
int32_t createQueryFuncExprFromMsg(SQueryTableMsg *pQueryMsg, int32_t numOfOutput, SExprInfo **pExprInfo, SSqlFuncMsg **pExprMsg,
|
int32_t createQueryFuncExprFromMsg(SQueryTableMsg *pQueryMsg, int32_t numOfOutput, SExprInfo **pExprInfo, SSqlFuncMsg **pExprMsg,
|
||||||
|
|
|
@ -173,8 +173,8 @@ static void doRowwiseTimeWindowInterpolation(SQueryRuntimeEnv* pRuntimeEnv, SArr
|
||||||
static STsdbQueryCond createTsdbQueryCond(SQuery* pQuery, STimeWindow* win);
|
static STsdbQueryCond createTsdbQueryCond(SQuery* pQuery, STimeWindow* win);
|
||||||
static STableIdInfo createTableIdInfo(SQuery* pQuery);
|
static STableIdInfo createTableIdInfo(SQuery* pQuery);
|
||||||
|
|
||||||
static STableScanInfo* createBiDirectionTableScanInfo(void* pTsdbQueryHandle, SQueryRuntimeEnv* pRuntimeEnv, int32_t repeatTime, int32_t reverseTime);
|
static SOperatorInfo* createBiDirectionTableScanInfo(void* pTsdbQueryHandle, SQueryRuntimeEnv* pRuntimeEnv, int32_t repeatTime, int32_t reverseTime);
|
||||||
static STableScanInfo* createTableScanOperator(void* pTsdbQueryHandle, SQueryRuntimeEnv* pRuntimeEnv, int32_t repeatTime);
|
static SOperatorInfo* createTableScanOperator(void* pTsdbQueryHandle, SQueryRuntimeEnv* pRuntimeEnv, int32_t repeatTime);
|
||||||
static int32_t getNumOfScanTimes(SQuery* pQuery);
|
static int32_t getNumOfScanTimes(SQuery* pQuery);
|
||||||
|
|
||||||
static SSDataBlock* createOutputBuf(SQuery* pQuery) {
|
static SSDataBlock* createOutputBuf(SQuery* pQuery) {
|
||||||
|
@ -1220,6 +1220,63 @@ static void aggApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SSDataBlock* pSData
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void arithmeticApplyFunctions(SQueryRuntimeEnv *pRuntimeEnv, SSDataBlock* pSDataBlock) {
|
||||||
|
SArithmeticSupport arithSup = {0};
|
||||||
|
|
||||||
|
SQuery *pQuery = pRuntimeEnv->pQuery;
|
||||||
|
|
||||||
|
// create the output result buffer
|
||||||
|
tFilePage **data = calloc(pQuery->numOfExpr2, POINTER_BYTES);
|
||||||
|
for (int32_t i = 0; i < pQuery->numOfExpr2; ++i) {
|
||||||
|
int32_t bytes = pQuery->pExpr2[i].bytes;
|
||||||
|
data[i] = (tFilePage *)malloc((size_t)(bytes * pQuery->rec.rows) + sizeof(tFilePage));
|
||||||
|
}
|
||||||
|
|
||||||
|
arithSup.numOfCols = (int32_t)pSDataBlock->info.numOfCols;
|
||||||
|
arithSup.exprList = pQuery->pExpr1;
|
||||||
|
arithSup.data = calloc(arithSup.numOfCols, POINTER_BYTES);
|
||||||
|
|
||||||
|
// set the input column data
|
||||||
|
for (int32_t f = 0; f < arithSup.numOfCols; ++f) {
|
||||||
|
SColumnInfoData *pColumnInfoData = taosArrayGet(pSDataBlock->pDataBlock, f);
|
||||||
|
arithSup.data[f] = pColumnInfoData->pData;
|
||||||
|
}
|
||||||
|
|
||||||
|
// output result number of columns
|
||||||
|
for (int32_t k = 0; k < pRuntimeEnv->outputBuf->info.numOfCols; ++k) {
|
||||||
|
for (int i = 0; i < pQuery->numOfExpr2; ++i) {
|
||||||
|
SExprInfo *pExpr = &pQuery->pExpr2[i];
|
||||||
|
|
||||||
|
// calculate the result from several other columns
|
||||||
|
SSqlFuncMsg *pSqlFunc = &pExpr->base;
|
||||||
|
if (pSqlFunc->functionId != TSDB_FUNC_ARITHM) {
|
||||||
|
for (int32_t j = 0; j < pQuery->numOfOutput; ++j) {
|
||||||
|
if (pSqlFunc->functionId == pQuery->pExpr1[j].base.functionId &&
|
||||||
|
pSqlFunc->colInfo.colId == pQuery->pExpr1[j].base.colInfo.colId) {
|
||||||
|
memcpy(data[i]->data, pQuery->sdata[j]->data, (size_t)(pQuery->pExpr1[j].bytes * pSDataBlock->info.rows));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
arithSup.pArithExpr = pExpr;
|
||||||
|
arithmeticTreeTraverse(arithSup.pArithExpr->pExpr, (int32_t)pQuery->rec.rows, data[i]->data, &arithSup,
|
||||||
|
TSDB_ORDER_ASC, getArithemicInputSrc);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < pQuery->numOfExpr2; ++i) {
|
||||||
|
memcpy(pQuery->sdata[i]->data, data[i]->data, (size_t)(pQuery->pExpr2[i].bytes * pQuery->rec.rows));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int32_t i = 0; i < pQuery->numOfExpr2; ++i) {
|
||||||
|
tfree(data[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
tfree(data);
|
||||||
|
tfree(arithSup.data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* todo set the last value for pQueryTableInfo as in rowwiseapplyfunctions
|
* todo set the last value for pQueryTableInfo as in rowwiseapplyfunctions
|
||||||
* @param pRuntimeEnv
|
* @param pRuntimeEnv
|
||||||
|
@ -5890,17 +5947,16 @@ static UNUSED_FUNC SOperatorInfo* createTableScanOperator(void* pTsdbQueryHandle
|
||||||
pOptr->name = "SeqScanTableOp";
|
pOptr->name = "SeqScanTableOp";
|
||||||
pOptr->blockingOptr = false;
|
pOptr->blockingOptr = false;
|
||||||
pOptr->optInfo = pInfo;
|
pOptr->optInfo = pInfo;
|
||||||
pOptr->exec = doScanTable;
|
pOptr->exec = doTableScan;
|
||||||
|
|
||||||
return pOptr;
|
return pOptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static STableScanInfo* createBiDirectionTableScanInfo(void* pTsdbQueryHandle, SQueryRuntimeEnv* pRuntimeEnv, int32_t repeatTime, int32_t reverseTime) {
|
static SOperatorInfo* createBiDirectionTableScanInfo(void* pTsdbQueryHandle, SQueryRuntimeEnv* pRuntimeEnv, int32_t repeatTime, int32_t reverseTime) {
|
||||||
assert(repeatTime > 0);
|
assert(repeatTime > 0);
|
||||||
|
|
||||||
STableScanInfo* pInfo = calloc(1, sizeof(STableScanInfo));
|
STableScanInfo* pInfo = calloc(1, sizeof(STableScanInfo));
|
||||||
pInfo->pQueryHandle = pTsdbQueryHandle;
|
pInfo->pQueryHandle = pTsdbQueryHandle;
|
||||||
pInfo->exec = doTableScan;
|
|
||||||
pInfo->times = repeatTime;
|
pInfo->times = repeatTime;
|
||||||
pInfo->reverseTimes = reverseTime;
|
pInfo->reverseTimes = reverseTime;
|
||||||
|
|
||||||
|
@ -5908,7 +5964,14 @@ static STableScanInfo* createBiDirectionTableScanInfo(void* pTsdbQueryHandle, SQ
|
||||||
pInfo->order = pRuntimeEnv->pQuery->order.order;
|
pInfo->order = pRuntimeEnv->pQuery->order.order;
|
||||||
|
|
||||||
pInfo->pRuntimeEnv = pRuntimeEnv;
|
pInfo->pRuntimeEnv = pRuntimeEnv;
|
||||||
return pInfo;
|
|
||||||
|
SOperatorInfo* pOptr = calloc(1, sizeof(SOperatorInfo));
|
||||||
|
pOptr->name = "BidirectionSeqScanTableOp";
|
||||||
|
pOptr->blockingOptr = false;
|
||||||
|
pOptr->optInfo = pInfo;
|
||||||
|
pOptr->exec = doTableScan;
|
||||||
|
|
||||||
|
return pOptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static UNUSED_FUNC int32_t getTableScanId(STableScanInfo* pTableScanInfo) {
|
static UNUSED_FUNC int32_t getTableScanId(STableScanInfo* pTableScanInfo) {
|
||||||
|
@ -5920,34 +5983,53 @@ static UNUSED_FUNC int32_t getTableScanOrder(STableScanInfo* pTableScanInfo) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// this is a blocking operator
|
// this is a blocking operator
|
||||||
static SSDataBlock* doAggOperator(void* param) {
|
static SSDataBlock* doAggregation(void* param) {
|
||||||
SAggOperatorInfo* pInfo = (SAggOperatorInfo*) param;
|
SOperatorInfo* pOperator = (SOperatorInfo*) param;
|
||||||
SQueryRuntimeEnv* pRuntimeEnv = pInfo->pRuntimeEnv;
|
|
||||||
STableScanInfo* pTableScanInfo = pInfo->pTableScanInfo;
|
|
||||||
|
|
||||||
int32_t countId = 0;
|
SAggOperatorInfo* pAggInfo = pOperator->optInfo;
|
||||||
int32_t order = getTableScanOrder(pInfo->pTableScanInfo);
|
SQueryRuntimeEnv* pRuntimeEnv = pAggInfo->pRuntimeEnv;
|
||||||
|
|
||||||
resetDefaultResInfoOutputBuf_rv(pInfo->pRuntimeEnv);
|
SOperatorInfo* upstream = pOperator->upstream;
|
||||||
|
|
||||||
|
resetDefaultResInfoOutputBuf_rv(pRuntimeEnv);
|
||||||
pRuntimeEnv->pQuery->pos = 0;
|
pRuntimeEnv->pQuery->pos = 0;
|
||||||
|
|
||||||
while(1) {
|
while(1) {
|
||||||
SSDataBlock* pBlock = pTableScanInfo->exec(pTableScanInfo);
|
SSDataBlock* pBlock = upstream->exec(upstream->optInfo);
|
||||||
if (pBlock == NULL) {
|
if (pBlock == NULL) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (countId != getTableScanId(pTableScanInfo) && order == getTableScanOrder(pTableScanInfo)) {
|
// the pDataBlock are always the same one, no need to call this again
|
||||||
prepareRepeatTableScan(pRuntimeEnv);
|
setInputSDataBlock(pRuntimeEnv, pBlock);
|
||||||
countId = getTableScanId(pTableScanInfo);
|
aggApplyFunctions(pRuntimeEnv, pBlock);
|
||||||
|
}
|
||||||
|
|
||||||
|
setQueryStatus(pRuntimeEnv->pQuery, QUERY_COMPLETED);
|
||||||
|
finalizeQueryResult(pRuntimeEnv);
|
||||||
|
|
||||||
|
pRuntimeEnv->outputBuf->info.rows = getNumOfResult(pRuntimeEnv);
|
||||||
|
return pRuntimeEnv->outputBuf;
|
||||||
|
}
|
||||||
|
|
||||||
|
static SSDataBlock* doArithmeticOperation(void* param) {
|
||||||
|
SOperatorInfo* pOperator = (SOperatorInfo*) param;
|
||||||
|
|
||||||
|
SArithOperatorInfo* pArithInfo = pOperator->optInfo;
|
||||||
|
SQueryRuntimeEnv* pRuntimeEnv = pArithInfo->pRuntimeEnv;
|
||||||
|
|
||||||
|
SOperatorInfo* upstream = pOperator->upstream;
|
||||||
|
|
||||||
|
resetDefaultResInfoOutputBuf_rv(pRuntimeEnv);
|
||||||
|
pRuntimeEnv->pQuery->pos = 0;
|
||||||
|
|
||||||
|
while(1) {
|
||||||
|
SSDataBlock* pBlock = upstream->exec(upstream->optInfo);
|
||||||
|
if (pBlock == NULL) {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
// the order has changed
|
// the pDataBlock are always the same one, no need to call this again
|
||||||
if (order != getTableScanOrder(pTableScanInfo)) {
|
|
||||||
order = getTableScanOrder(pTableScanInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
// the pDataBlock are alway the same one, no need to call this again
|
|
||||||
setInputSDataBlock(pRuntimeEnv, pBlock);
|
setInputSDataBlock(pRuntimeEnv, pBlock);
|
||||||
aggApplyFunctions(pRuntimeEnv, pBlock);
|
aggApplyFunctions(pRuntimeEnv, pBlock);
|
||||||
}
|
}
|
||||||
|
@ -5971,29 +6053,43 @@ static int32_t getNumOfScanTimes(SQuery* pQuery) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//void createBasicOperatorInfo() {
|
static UNUSED_FUNC SOperatorInfo* createAggOperatorInfo(SResultRowInfo* pResultRowInfo, STableQueryInfo* pTableQueryInfo,
|
||||||
// optrList[0].name = "SeqScanTableOp";
|
SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* inputOptr) {
|
||||||
// optrList[0].blockingOptr = false;
|
|
||||||
// optrList[0].exec = doTableScan;
|
|
||||||
//
|
|
||||||
// optrList[0].name = "SeqScanTableOp";
|
|
||||||
// optrList[0].blockingOptr = false;
|
|
||||||
// optrList[0].exec = doTableScan;
|
|
||||||
//}
|
|
||||||
|
|
||||||
static UNUSED_FUNC SAggOperatorInfo* createAggOperatorInfo(SResultRowInfo* pResultRowInfo, STableQueryInfo* pTableQueryInfo,
|
|
||||||
SQueryRuntimeEnv* pRuntimeEnv, STableScanInfo* pTableScanInfo) {
|
|
||||||
SAggOperatorInfo* pInfo = calloc(1, sizeof(SAggOperatorInfo));
|
SAggOperatorInfo* pInfo = calloc(1, sizeof(SAggOperatorInfo));
|
||||||
|
|
||||||
pInfo->pResultRowInfo = pResultRowInfo;
|
pInfo->pResultRowInfo = pResultRowInfo;
|
||||||
pInfo->pTableQueryInfo = pTableQueryInfo;
|
pInfo->pTableQueryInfo = pTableQueryInfo;
|
||||||
pInfo->pTableScanInfo = pTableScanInfo;
|
|
||||||
pInfo->pRuntimeEnv = pRuntimeEnv;
|
pInfo->pRuntimeEnv = pRuntimeEnv;
|
||||||
pInfo->apply = doAggOperator;
|
|
||||||
|
|
||||||
return pInfo;
|
SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo));
|
||||||
|
pOperator->name = "AggregationOp";
|
||||||
|
pOperator->blockingOptr = true;
|
||||||
|
pOperator->optInfo = pInfo;
|
||||||
|
pOperator->upstream = inputOptr;
|
||||||
|
pOperator->exec = doAggregation;
|
||||||
|
|
||||||
|
return pOperator;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static UNUSED_FUNC SOperatorInfo* createArithOperatorInfo(SResultRowInfo* pResultRowInfo, STableQueryInfo* pTableQueryInfo,
|
||||||
|
SQueryRuntimeEnv* pRuntimeEnv, SOperatorInfo* inputOptr) {
|
||||||
|
SArithOperatorInfo* pInfo = calloc(1, sizeof(SArithOperatorInfo));
|
||||||
|
|
||||||
|
pInfo->pTableQueryInfo = pTableQueryInfo;
|
||||||
|
pInfo->pRuntimeEnv = pRuntimeEnv;
|
||||||
|
|
||||||
|
SOperatorInfo* pOperator = calloc(1, sizeof(SOperatorInfo));
|
||||||
|
pOperator->name = "ArithmeticOp";
|
||||||
|
pOperator->blockingOptr = false;
|
||||||
|
pOperator->optInfo = pInfo;
|
||||||
|
pOperator->upstream = inputOptr;
|
||||||
|
pOperator->exec = doArithmeticOperation;
|
||||||
|
|
||||||
|
return pOperator;
|
||||||
|
}
|
||||||
|
|
||||||
|
static
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* in each query, this function will be called only once, no retry for further result.
|
* in each query, this function will be called only once, no retry for further result.
|
||||||
*
|
*
|
||||||
|
@ -6008,10 +6104,9 @@ static void tableAggregationProcess(SQInfo *pQInfo, STableQueryInfo* pTableInfo)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
SAggOperatorInfo* pAggInfo = createAggOperatorInfo(&pRuntimeEnv->resultRowInfo, pQuery->current, pRuntimeEnv, pRuntimeEnv->pi);
|
SOperatorInfo* pAggInfo = createAggOperatorInfo(&pRuntimeEnv->resultRowInfo, pQuery->current, pRuntimeEnv, pRuntimeEnv->pi);
|
||||||
SSDataBlock* pResBlock = pAggInfo->apply(pAggInfo);
|
SSDataBlock* pResBlock = pAggInfo->exec(pAggInfo->optInfo);
|
||||||
|
|
||||||
// since the numOfRows must be identical for all functions that are allowed to be executed simutaneously.
|
|
||||||
pQuery->rec.rows = pResBlock->info.rows;
|
pQuery->rec.rows = pResBlock->info.rows;
|
||||||
// doSecondaryArithmeticProcess(pQuery);
|
// doSecondaryArithmeticProcess(pQuery);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue