[td-2895] refactor.
This commit is contained in:
parent
18112c74cb
commit
dd3174df37
|
@ -494,8 +494,6 @@ int tscProcessSql(SSqlObj *pSql) {
|
|||
return pSql->res.code;
|
||||
}
|
||||
} else if (pCmd->command >= TSDB_SQL_LOCAL) {
|
||||
//pSql->epSet = tscMgmtEpSet;
|
||||
// } else { // local handler
|
||||
return (*tscProcessMsgRsp[pCmd->command])(pSql);
|
||||
}
|
||||
|
||||
|
|
|
@ -497,6 +497,7 @@ static int32_t tscLaunchRealSubqueries(SSqlObj* pSql) {
|
|||
SSqlExpr* pExpr = tscSqlExprGet(pQueryInfo, 0);
|
||||
int16_t funcId = pExpr->functionId;
|
||||
|
||||
// add the invisible timestamp column
|
||||
if ((pExpr->colInfo.colId != PRIMARYKEY_TIMESTAMP_COL_INDEX) ||
|
||||
(funcId != TSDB_FUNC_TS && funcId != TSDB_FUNC_TS_DUMMY && funcId != TSDB_FUNC_PRJ)) {
|
||||
|
||||
|
|
|
@ -307,7 +307,7 @@ int32_t tsdbQuerySTableByTagCond(STsdbRepo *tsdb, uint64_t uid, TSKEY key, const
|
|||
SColIndex *pColIndex, int32_t numOfCols);
|
||||
|
||||
/**
|
||||
* destory the created table group list, which is generated by tag query
|
||||
* destroy the created table group list, which is generated by tag query
|
||||
* @param pGroupList
|
||||
*/
|
||||
void tsdbDestroyTableGroup(STableGroupInfo *pGroupList);
|
||||
|
@ -339,6 +339,8 @@ void tsdbCleanupQueryHandle(TsdbQueryHandleT queryHandle);
|
|||
|
||||
void tsdbResetQueryHandle(TsdbQueryHandleT queryHandle, STsdbQueryCond *pCond);
|
||||
|
||||
void tsdbResetQueryHandleForNewTable(TsdbQueryHandleT queryHandle, STsdbQueryCond *pCond, STableGroupInfo* groupList);
|
||||
|
||||
/**
|
||||
* get the statistics of repo usage
|
||||
* @param repo. point to the tsdbrepo
|
||||
|
|
|
@ -241,12 +241,16 @@ typedef void (*__optr_cleanup_fn_t)(void* param, int32_t num);
|
|||
|
||||
struct SOperatorInfo;
|
||||
|
||||
typedef struct {
|
||||
FILE* file; // file struct pointer
|
||||
} SFileResultInfo;
|
||||
|
||||
typedef struct SQueryRuntimeEnv {
|
||||
jmp_buf env;
|
||||
SQuery* pQuery;
|
||||
void* qinfo;
|
||||
uint16_t scanFlag; // denotes reversed scan of data or not
|
||||
SFillInfo* pFillInfo;
|
||||
SFillInfo* pFillInfo; // todo move to operatorInfo
|
||||
void* pQueryHandle;
|
||||
|
||||
int32_t prevGroupId; // previous executed group id
|
||||
|
@ -264,10 +268,10 @@ typedef struct SQueryRuntimeEnv {
|
|||
SArithmeticSupport *sasArray;
|
||||
|
||||
SSDataBlock *outputBuf;
|
||||
int32_t groupIndex;
|
||||
int32_t tableIndex;
|
||||
int32_t tableIndex; //TODO remove it
|
||||
STableGroupInfo tableqinfoGroupInfo; // this is a group array list, including SArray<STableQueryInfo*> structure
|
||||
struct SOperatorInfo *proot;
|
||||
struct SOperatorInfo *pTableScanner; // table scan operator
|
||||
SGroupResInfo groupResInfo;
|
||||
int64_t currentOffset; // dynamic offset value
|
||||
|
||||
|
@ -364,6 +368,8 @@ typedef struct STableScanInfo {
|
|||
|
||||
int32_t numOfOutput;
|
||||
int64_t elapsedTime;
|
||||
|
||||
int32_t tableIndex;
|
||||
} STableScanInfo;
|
||||
|
||||
typedef struct STagScanInfo {
|
||||
|
|
|
@ -208,7 +208,7 @@ int32_t getResultDataInfo(int32_t dataType, int32_t dataBytes, int32_t functionI
|
|||
|
||||
if (functionId == TSDB_FUNC_TS_COMP) {
|
||||
*type = TSDB_DATA_TYPE_BINARY;
|
||||
*bytes = sizeof(int32_t); // this results is compressed ts data
|
||||
*bytes = 1; // this results is compressed ts data, only one byte
|
||||
*interBytes = POINTER_BYTES;
|
||||
return TSDB_CODE_SUCCESS;
|
||||
}
|
||||
|
@ -4203,11 +4203,22 @@ static void ts_comp_finalize(SQLFunctionCtx *pCtx) {
|
|||
STSBuf * pTSbuf = pInfo->pTSBuf;
|
||||
|
||||
tsBufFlush(pTSbuf);
|
||||
|
||||
qDebug("total timestamp :%"PRId64, pTSbuf->numOfTotal);
|
||||
|
||||
// TODO refactor transfer ownership of current file
|
||||
*(FILE **)pCtx->pOutput = pTSbuf->f;
|
||||
|
||||
pResInfo->complete = true;
|
||||
|
||||
// get the file size
|
||||
struct stat fStat;
|
||||
if ((fstat(fileno(pTSbuf->f), &fStat) == 0)) {
|
||||
pResInfo->numOfRes = fStat.st_size;
|
||||
}
|
||||
|
||||
pTSbuf->remainOpen = true;
|
||||
tsBufDestroy(pTSbuf);
|
||||
|
||||
doFinalizer(pCtx);
|
||||
}
|
||||
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -312,10 +312,9 @@ int32_t qDumpRetrieveResult(qinfo_t qinfo, SRetrieveTableRsp **pRsp, int32_t *co
|
|||
|
||||
SQuery *pQuery = pQInfo->runtimeEnv.pQuery;
|
||||
SQueryRuntimeEnv* pRuntimeEnv = &pQInfo->runtimeEnv;
|
||||
int64_t s = GET_NUM_OF_RESULTS(pRuntimeEnv);
|
||||
|
||||
size_t size = getResultSize(pQInfo, &s);
|
||||
|
||||
int32_t s = GET_NUM_OF_RESULTS(pRuntimeEnv);
|
||||
size_t size = pQuery->resultRowSize * s;
|
||||
size += sizeof(int32_t);
|
||||
size += sizeof(STableIdInfo) * taosHashGetSize(pQInfo->arrTableIdInfo);
|
||||
|
||||
|
|
|
@ -295,8 +295,8 @@ static void resetCheckInfo(STsdbQueryHandle* pQueryHandle) {
|
|||
for (int32_t i = 0; i < numOfTables; ++i) {
|
||||
STableCheckInfo* pCheckInfo = (STableCheckInfo*) taosArrayGet(pQueryHandle->pTableCheckInfo, i);
|
||||
pCheckInfo->lastKey = pQueryHandle->window.skey;
|
||||
pCheckInfo->iter = tSkipListDestroyIter(pCheckInfo->iter);
|
||||
pCheckInfo->iiter = tSkipListDestroyIter(pCheckInfo->iiter);
|
||||
pCheckInfo->iter = tSkipListDestroyIter(pCheckInfo->iter);
|
||||
pCheckInfo->iiter = tSkipListDestroyIter(pCheckInfo->iiter);
|
||||
pCheckInfo->initBuf = false;
|
||||
|
||||
if (ASCENDING_TRAVERSE(pQueryHandle->order)) {
|
||||
|
@ -453,6 +453,39 @@ void tsdbResetQueryHandle(TsdbQueryHandleT queryHandle, STsdbQueryCond *pCond) {
|
|||
resetCheckInfo(pQueryHandle);
|
||||
}
|
||||
|
||||
void tsdbResetQueryHandleForNewTable(TsdbQueryHandleT queryHandle, STsdbQueryCond *pCond, STableGroupInfo* groupList) {
|
||||
STsdbQueryHandle* pQueryHandle = queryHandle;
|
||||
|
||||
pQueryHandle->order = pCond->order;
|
||||
pQueryHandle->window = pCond->twindow;
|
||||
pQueryHandle->type = TSDB_QUERY_TYPE_ALL;
|
||||
pQueryHandle->cur.fid = -1;
|
||||
pQueryHandle->cur.win = TSWINDOW_INITIALIZER;
|
||||
pQueryHandle->checkFiles = true;
|
||||
pQueryHandle->activeIndex = 0; // current active table index
|
||||
pQueryHandle->locateStart = false;
|
||||
pQueryHandle->loadExternalRow = pCond->loadExternalRows;
|
||||
|
||||
if (ASCENDING_TRAVERSE(pCond->order)) {
|
||||
assert(pQueryHandle->window.skey <= pQueryHandle->window.ekey);
|
||||
} else {
|
||||
assert(pQueryHandle->window.skey >= pQueryHandle->window.ekey);
|
||||
}
|
||||
|
||||
// allocate buffer in order to load data blocks from file
|
||||
memset(pQueryHandle->statis, 0, sizeof(SDataStatis));
|
||||
|
||||
tsdbInitDataBlockLoadInfo(&pQueryHandle->dataBlockLoadInfo);
|
||||
tsdbInitCompBlockLoadInfo(&pQueryHandle->compBlockLoadInfo);
|
||||
|
||||
STsdbMeta* pMeta = tsdbGetMeta(pQueryHandle->pTsdb);
|
||||
pQueryHandle->pTableCheckInfo = createCheckInfoFromTableGroup(pQueryHandle, groupList, pMeta);
|
||||
if (pQueryHandle->pTableCheckInfo == NULL) {
|
||||
tsdbCleanupQueryHandle(pQueryHandle);
|
||||
terrno = TSDB_CODE_TDB_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
|
||||
TsdbQueryHandleT tsdbQueryLastRow(STsdbRepo *tsdb, STsdbQueryCond *pCond, STableGroupInfo *groupList, void* qinfo, SMemRef* pMemRef) {
|
||||
pCond->twindow = updateLastrowForEachGroup(groupList);
|
||||
|
||||
|
@ -3105,23 +3138,26 @@ static void* doFreeColumnInfoData(SArray* pColumnInfoData) {
|
|||
return NULL;
|
||||
}
|
||||
|
||||
static void* destroyTableCheckInfo(SArray* pTableCheckInfo) {
|
||||
size_t size = taosArrayGetSize(pTableCheckInfo);
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
STableCheckInfo* p = taosArrayGet(pTableCheckInfo, i);
|
||||
destroyTableMemIterator(p);
|
||||
|
||||
tfree(p->pCompInfo);
|
||||
}
|
||||
|
||||
taosArrayDestroy(pTableCheckInfo);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void tsdbCleanupQueryHandle(TsdbQueryHandleT queryHandle) {
|
||||
STsdbQueryHandle* pQueryHandle = (STsdbQueryHandle*)queryHandle;
|
||||
if (pQueryHandle == NULL) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (pQueryHandle->pTableCheckInfo != NULL) {
|
||||
size_t size = taosArrayGetSize(pQueryHandle->pTableCheckInfo);
|
||||
for (int32_t i = 0; i < size; ++i) {
|
||||
STableCheckInfo* pTableCheckInfo = taosArrayGet(pQueryHandle->pTableCheckInfo, i);
|
||||
destroyTableMemIterator(pTableCheckInfo);
|
||||
|
||||
tfree(pTableCheckInfo->pCompInfo);
|
||||
}
|
||||
taosArrayDestroy(pQueryHandle->pTableCheckInfo);
|
||||
}
|
||||
|
||||
pQueryHandle->pTableCheckInfo = destroyTableCheckInfo(pQueryHandle->pTableCheckInfo);
|
||||
pQueryHandle->pColumns = doFreeColumnInfoData(pQueryHandle->pColumns);
|
||||
|
||||
taosArrayDestroy(pQueryHandle->defaultLoadColumn);
|
||||
|
|
Loading…
Reference in New Issue