[td-225] refactor code.
This commit is contained in:
parent
88fc56d14d
commit
a9ec970d12
|
@ -110,8 +110,6 @@ STableMeta* tscCreateTableMetaFromMsg(STableMetaMsg* pTableMetaMsg, size_t* size
|
||||||
//todo tags value as well as the table id structure needs refactor
|
//todo tags value as well as the table id structure needs refactor
|
||||||
char *tsGetTagsValue(STableMeta *pMeta);
|
char *tsGetTagsValue(STableMeta *pMeta);
|
||||||
|
|
||||||
void extractTableNameFromToken(SSQLToken *pToken, SSQLToken* pTable);
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "qast.h"
|
|
||||||
#include "qextbuffer.h"
|
#include "qextbuffer.h"
|
||||||
#include "qfill.h"
|
#include "qfill.h"
|
||||||
#include "qhistogram.h"
|
#include "qhistogram.h"
|
||||||
|
@ -23,6 +22,7 @@
|
||||||
#include "qtsbuf.h"
|
#include "qtsbuf.h"
|
||||||
#include "taosdef.h"
|
#include "taosdef.h"
|
||||||
#include "taosmsg.h"
|
#include "taosmsg.h"
|
||||||
|
#include "qast.h"
|
||||||
#include "tscLog.h"
|
#include "tscLog.h"
|
||||||
#include "tscSubquery.h"
|
#include "tscSubquery.h"
|
||||||
#include "tscompression.h"
|
#include "tscompression.h"
|
||||||
|
|
|
@ -18,19 +18,19 @@
|
||||||
#define _DEFAULT_SOURCE
|
#define _DEFAULT_SOURCE
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "qast.h"
|
|
||||||
#include "taos.h"
|
#include "taos.h"
|
||||||
#include "taosmsg.h"
|
#include "taosmsg.h"
|
||||||
#include "tstoken.h"
|
#include "qast.h"
|
||||||
#include "tstrbuild.h"
|
#include "tcompare.h"
|
||||||
#include "ttime.h"
|
#include "tname.h"
|
||||||
#include "tscLog.h"
|
#include "tscLog.h"
|
||||||
#include "tscUtil.h"
|
#include "tscUtil.h"
|
||||||
#include "tschemautil.h"
|
#include "tschemautil.h"
|
||||||
#include "tsclient.h"
|
#include "tsclient.h"
|
||||||
|
#include "tstoken.h"
|
||||||
|
#include "tstrbuild.h"
|
||||||
|
#include "ttime.h"
|
||||||
#include "ttokendef.h"
|
#include "ttokendef.h"
|
||||||
#include "tname.h"
|
|
||||||
#include "tcompare.h"
|
|
||||||
|
|
||||||
#define DEFAULT_PRIMARY_TIMESTAMP_COL_NAME "_c0"
|
#define DEFAULT_PRIMARY_TIMESTAMP_COL_NAME "_c0"
|
||||||
|
|
||||||
|
|
|
@ -215,25 +215,3 @@ __attribute__ ((unused)) static FORCE_INLINE size_t copy(char* dst, const char*
|
||||||
return len;
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
* tablePrefix.columnName
|
|
||||||
* extract table name and save it in pTable, with only column name in pToken
|
|
||||||
*/
|
|
||||||
void extractTableNameFromToken(SSQLToken* pToken, SSQLToken* pTable) {
|
|
||||||
const char sep = TS_PATH_DELIMITER[0];
|
|
||||||
|
|
||||||
if (pToken == pTable || pToken == NULL || pTable == NULL) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
char* r = strnchr(pToken->z, sep, pToken->n, false);
|
|
||||||
|
|
||||||
if (r != NULL) { // record the table name token
|
|
||||||
pTable->n = r - pToken->z;
|
|
||||||
pTable->z = pToken->z;
|
|
||||||
|
|
||||||
r += 1;
|
|
||||||
pToken->n -= (r - pToken->z);
|
|
||||||
pToken->z = r;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -14,12 +14,12 @@
|
||||||
*/
|
*/
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
|
|
||||||
#include "tscSubquery.h"
|
#include "qtsbuf.h"
|
||||||
#include "qast.h"
|
#include "qast.h"
|
||||||
#include "tcompare.h"
|
#include "tcompare.h"
|
||||||
#include "tschemautil.h"
|
|
||||||
#include "qtsbuf.h"
|
|
||||||
#include "tscLog.h"
|
#include "tscLog.h"
|
||||||
|
#include "tscSubquery.h"
|
||||||
|
#include "tschemautil.h"
|
||||||
#include "tsclient.h"
|
#include "tsclient.h"
|
||||||
|
|
||||||
typedef struct SInsertSupporter {
|
typedef struct SInsertSupporter {
|
||||||
|
|
|
@ -14,21 +14,21 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "qast.h"
|
#include "hash.h"
|
||||||
|
#include "tscUtil.h"
|
||||||
#include "taosmsg.h"
|
#include "taosmsg.h"
|
||||||
|
#include "qast.h"
|
||||||
#include "tcache.h"
|
#include "tcache.h"
|
||||||
#include "tkey.h"
|
#include "tkey.h"
|
||||||
#include "tmd5.h"
|
#include "tmd5.h"
|
||||||
#include "tscProfile.h"
|
|
||||||
#include "tscLocalMerge.h"
|
#include "tscLocalMerge.h"
|
||||||
|
#include "tscLog.h"
|
||||||
|
#include "tscProfile.h"
|
||||||
#include "tscSubquery.h"
|
#include "tscSubquery.h"
|
||||||
#include "tschemautil.h"
|
#include "tschemautil.h"
|
||||||
#include "tsclient.h"
|
#include "tsclient.h"
|
||||||
#include "ttimer.h"
|
#include "ttimer.h"
|
||||||
#include "ttokendef.h"
|
#include "ttokendef.h"
|
||||||
#include "tscLog.h"
|
|
||||||
#include "tscUtil.h"
|
|
||||||
#include "hash.h"
|
|
||||||
|
|
||||||
static void freeQueryInfoImpl(SQueryInfo* pQueryInfo);
|
static void freeQueryInfoImpl(SQueryInfo* pQueryInfo);
|
||||||
static void clearAllTableMetaInfo(SQueryInfo* pQueryInfo, const char* address, bool removeFromCache);
|
static void clearAllTableMetaInfo(SQueryInfo* pQueryInfo, const char* address, bool removeFromCache);
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "taosmsg.h"
|
#include "taosmsg.h"
|
||||||
|
#include "tstoken.h"
|
||||||
|
|
||||||
typedef struct SDataStatis {
|
typedef struct SDataStatis {
|
||||||
int16_t colId;
|
int16_t colId;
|
||||||
|
@ -23,6 +24,8 @@ void extractTableName(const char *tableId, char *name);
|
||||||
|
|
||||||
char* extractDBName(const char *tableId, char *name);
|
char* extractDBName(const char *tableId, char *name);
|
||||||
|
|
||||||
|
void extractTableNameFromToken(SSQLToken *pToken, SSQLToken* pTable);
|
||||||
|
|
||||||
SSchema tGetTableNameColumnSchema();
|
SSchema tGetTableNameColumnSchema();
|
||||||
|
|
||||||
bool tscValidateTableNameLength(size_t len);
|
bool tscValidateTableNameLength(size_t len);
|
||||||
|
|
|
@ -105,3 +105,26 @@ int64_t taosGetIntervalStartTimestamp(int64_t startTime, int64_t slidingTime, in
|
||||||
}
|
}
|
||||||
return start;
|
return start;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* tablePrefix.columnName
|
||||||
|
* extract table name and save it in pTable, with only column name in pToken
|
||||||
|
*/
|
||||||
|
void extractTableNameFromToken(SSQLToken* pToken, SSQLToken* pTable) {
|
||||||
|
const char sep = TS_PATH_DELIMITER[0];
|
||||||
|
|
||||||
|
if (pToken == pTable || pToken == NULL || pTable == NULL) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
char* r = strnchr(pToken->z, sep, pToken->n, false);
|
||||||
|
|
||||||
|
if (r != NULL) { // record the table name token
|
||||||
|
pTable->n = r - pToken->z;
|
||||||
|
pTable->z = pToken->z;
|
||||||
|
|
||||||
|
r += 1;
|
||||||
|
pToken->n -= (r - pToken->z);
|
||||||
|
pToken->z = r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -18,18 +18,18 @@
|
||||||
#include "qfill.h"
|
#include "qfill.h"
|
||||||
#include "taosmsg.h"
|
#include "taosmsg.h"
|
||||||
|
|
||||||
|
#include "exception.h"
|
||||||
#include "hash.h"
|
#include "hash.h"
|
||||||
#include "qExecutor.h"
|
#include "qExecutor.h"
|
||||||
#include "qUtil.h"
|
#include "qUtil.h"
|
||||||
#include "qast.h"
|
|
||||||
#include "qresultBuf.h"
|
#include "qresultBuf.h"
|
||||||
#include "query.h"
|
#include "query.h"
|
||||||
#include "queryLog.h"
|
#include "queryLog.h"
|
||||||
|
#include "qast.h"
|
||||||
|
#include "tfile.h"
|
||||||
#include "tlosertree.h"
|
#include "tlosertree.h"
|
||||||
#include "exception.h"
|
|
||||||
#include "tscompression.h"
|
#include "tscompression.h"
|
||||||
#include "ttime.h"
|
#include "ttime.h"
|
||||||
#include "tfile.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check if the primary column is load by default, otherwise, the program will
|
* check if the primary column is load by default, otherwise, the program will
|
||||||
|
|
|
@ -13,25 +13,26 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#include "os.h"
|
#include "os.h"
|
||||||
#include "tulog.h"
|
|
||||||
#include "tutil.h"
|
#include "tname.h"
|
||||||
#include "tbuffer.h"
|
|
||||||
#include "qast.h"
|
#include "qast.h"
|
||||||
#include "tcompare.h"
|
#include "tsdb.h"
|
||||||
|
#include "exception.h"
|
||||||
#include "qsqlparser.h"
|
#include "qsqlparser.h"
|
||||||
#include "qsyntaxtreefunction.h"
|
#include "qsyntaxtreefunction.h"
|
||||||
#include "taosdef.h"
|
#include "taosdef.h"
|
||||||
#include "taosmsg.h"
|
#include "taosmsg.h"
|
||||||
|
#include "tarray.h"
|
||||||
|
#include "tbuffer.h"
|
||||||
|
#include "tcompare.h"
|
||||||
|
#include "tskiplist.h"
|
||||||
#include "tsqlfunction.h"
|
#include "tsqlfunction.h"
|
||||||
#include "tstoken.h"
|
#include "tstoken.h"
|
||||||
#include "ttokendef.h"
|
#include "ttokendef.h"
|
||||||
#include "tschemautil.h"
|
#include "tulog.h"
|
||||||
#include "tarray.h"
|
#include "tutil.h"
|
||||||
#include "tskiplist.h"
|
|
||||||
#include "queryLog.h"
|
|
||||||
#include "tsdbMain.h"
|
|
||||||
#include "exception.h"
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*
|
*
|
||||||
|
@ -675,8 +676,7 @@ static void tQueryIndexlessColumn(SSkipList* pSkipList, tQueryInfo* pQueryInfo,
|
||||||
SSkipListNode *pNode = tSkipListIterGet(iter);
|
SSkipListNode *pNode = tSkipListIterGet(iter);
|
||||||
char * pData = SL_GET_NODE_DATA(pNode);
|
char * pData = SL_GET_NODE_DATA(pNode);
|
||||||
|
|
||||||
// todo refactor:
|
tstr *name = (tstr*) tsdbGetTableName(*(void**) pData);
|
||||||
tstr *name = (*(STable **)pData)->name;
|
|
||||||
// todo speed up by using hash
|
// todo speed up by using hash
|
||||||
if (pQueryInfo->colIndex == TSDB_TBNAME_COLUMN_INDEX) {
|
if (pQueryInfo->colIndex == TSDB_TBNAME_COLUMN_INDEX) {
|
||||||
if (pQueryInfo->optr == TSDB_RELATION_IN) {
|
if (pQueryInfo->optr == TSDB_RELATION_IN) {
|
||||||
|
|
|
@ -192,11 +192,6 @@ char *tsdbGetTableName(void* pTable) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
STableId tsdbGetTableId(void *pTable) {
|
|
||||||
assert(pTable);
|
|
||||||
return ((STable*)pTable)->tableId;
|
|
||||||
}
|
|
||||||
|
|
||||||
STableCfg *tsdbCreateTableCfgFromMsg(SMDCreateTableMsg *pMsg) {
|
STableCfg *tsdbCreateTableCfgFromMsg(SMDCreateTableMsg *pMsg) {
|
||||||
if (pMsg == NULL) return NULL;
|
if (pMsg == NULL) return NULL;
|
||||||
|
|
||||||
|
|
|
@ -122,7 +122,7 @@ static void changeQueryHandleForInterpQuery(TsdbQueryHandleT pHandle);
|
||||||
static void doMergeTwoLevelData(STsdbQueryHandle* pQueryHandle, STableCheckInfo* pCheckInfo, SCompBlock* pBlock,
|
static void doMergeTwoLevelData(STsdbQueryHandle* pQueryHandle, STableCheckInfo* pCheckInfo, SCompBlock* pBlock,
|
||||||
SArray* sa);
|
SArray* sa);
|
||||||
static int32_t binarySearchForKey(char* pValue, int num, TSKEY key, int order);
|
static int32_t binarySearchForKey(char* pValue, int num, TSKEY key, int order);
|
||||||
static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int maxRowsToRead, TSKEY* skey, TSKEY* ekey,
|
static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int maxRowsToRead, STimeWindow* win,
|
||||||
STsdbQueryHandle* pQueryHandle);
|
STsdbQueryHandle* pQueryHandle);
|
||||||
|
|
||||||
static void tsdbInitDataBlockLoadInfo(SDataBlockLoadInfo* pBlockLoadInfo) {
|
static void tsdbInitDataBlockLoadInfo(SDataBlockLoadInfo* pBlockLoadInfo) {
|
||||||
|
@ -412,8 +412,7 @@ static bool hasMoreDataInCache(STsdbQueryHandle* pHandle) {
|
||||||
|
|
||||||
int32_t step = ASCENDING_TRAVERSE(pHandle->order)? 1:-1;
|
int32_t step = ASCENDING_TRAVERSE(pHandle->order)? 1:-1;
|
||||||
STimeWindow* win = &pHandle->cur.win;
|
STimeWindow* win = &pHandle->cur.win;
|
||||||
pHandle->cur.rows = tsdbReadRowsFromCache(pCheckInfo, pHandle->window.ekey,
|
pHandle->cur.rows = tsdbReadRowsFromCache(pCheckInfo, pHandle->window.ekey, pHandle->outputCapacity, win, pHandle);
|
||||||
pHandle->outputCapacity, &win->skey, &win->ekey, pHandle); // todo refactor API
|
|
||||||
|
|
||||||
// update the last key value
|
// update the last key value
|
||||||
pCheckInfo->lastKey = win->ekey + step;
|
pCheckInfo->lastKey = win->ekey + step;
|
||||||
|
@ -643,7 +642,7 @@ static void handleDataMergeIfNeeded(STsdbQueryHandle* pQueryHandle, SCompBlock*
|
||||||
int32_t step = ASCENDING_TRAVERSE(pQueryHandle->order) ? 1 : -1;
|
int32_t step = ASCENDING_TRAVERSE(pQueryHandle->order) ? 1 : -1;
|
||||||
|
|
||||||
cur->rows = tsdbReadRowsFromCache(pCheckInfo, binfo.window.skey - step,
|
cur->rows = tsdbReadRowsFromCache(pCheckInfo, binfo.window.skey - step,
|
||||||
pQueryHandle->outputCapacity, &cur->win.skey, &cur->win.ekey, pQueryHandle);
|
pQueryHandle->outputCapacity, &cur->win, pQueryHandle);
|
||||||
pQueryHandle->realNumOfRows = cur->rows;
|
pQueryHandle->realNumOfRows = cur->rows;
|
||||||
|
|
||||||
// update the last key value
|
// update the last key value
|
||||||
|
@ -1244,7 +1243,6 @@ static int32_t dataBlockOrderCompar(const void* pLeft, const void* pRight, void*
|
||||||
// assert(pLeftBlockInfoEx->compBlock->offset != pRightBlockInfoEx->compBlock->offset);
|
// assert(pLeftBlockInfoEx->compBlock->offset != pRightBlockInfoEx->compBlock->offset);
|
||||||
if (pLeftBlockInfoEx->compBlock->offset == pRightBlockInfoEx->compBlock->offset &&
|
if (pLeftBlockInfoEx->compBlock->offset == pRightBlockInfoEx->compBlock->offset &&
|
||||||
pLeftBlockInfoEx->compBlock->last == pRightBlockInfoEx->compBlock->last) {
|
pLeftBlockInfoEx->compBlock->last == pRightBlockInfoEx->compBlock->last) {
|
||||||
// todo add more information
|
|
||||||
tsdbError("error in header file, two block with same offset:%" PRId64, (int64_t)pLeftBlockInfoEx->compBlock->offset);
|
tsdbError("error in header file, two block with same offset:%" PRId64, (int64_t)pLeftBlockInfoEx->compBlock->offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1701,11 +1699,11 @@ static void changeQueryHandleForInterpQuery(TsdbQueryHandleT pHandle) {
|
||||||
pQueryHandle->window = (STimeWindow) {info.lastKey, TSKEY_INITIAL_VAL};
|
pQueryHandle->window = (STimeWindow) {info.lastKey, TSKEY_INITIAL_VAL};
|
||||||
}
|
}
|
||||||
|
|
||||||
static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int maxRowsToRead, TSKEY* skey, TSKEY* ekey,
|
static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int maxRowsToRead, STimeWindow* win,
|
||||||
STsdbQueryHandle* pQueryHandle) {
|
STsdbQueryHandle* pQueryHandle) {
|
||||||
int numOfRows = 0;
|
int numOfRows = 0;
|
||||||
int32_t numOfCols = taosArrayGetSize(pQueryHandle->pColumns);
|
int32_t numOfCols = taosArrayGetSize(pQueryHandle->pColumns);
|
||||||
*skey = TSKEY_INITIAL_VAL;
|
win->skey = TSKEY_INITIAL_VAL;
|
||||||
|
|
||||||
int64_t st = taosGetTimestampUs();
|
int64_t st = taosGetTimestampUs();
|
||||||
STsdbMeta* pMeta = tsdbGetMeta(pQueryHandle->pTsdb);
|
STsdbMeta* pMeta = tsdbGetMeta(pQueryHandle->pTsdb);
|
||||||
|
@ -1725,11 +1723,11 @@ static int tsdbReadRowsFromCache(STableCheckInfo* pCheckInfo, TSKEY maxKey, int
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*skey == INT64_MIN) {
|
if (win->skey == INT64_MIN) {
|
||||||
*skey = key;
|
win->skey = key;
|
||||||
}
|
}
|
||||||
|
|
||||||
*ekey = key;
|
win->ekey = key;
|
||||||
copyOneRowFromMem(pQueryHandle, maxRowsToRead, numOfRows, row, pMeta, numOfCols, pTable);
|
copyOneRowFromMem(pQueryHandle, maxRowsToRead, numOfRows, row, pMeta, numOfCols, pTable);
|
||||||
|
|
||||||
if (++numOfRows >= maxRowsToRead) {
|
if (++numOfRows >= maxRowsToRead) {
|
||||||
|
@ -1978,9 +1976,9 @@ int32_t tableGroupComparFn(const void *p1, const void *p2, const void *param) {
|
||||||
int32_t type = 0;
|
int32_t type = 0;
|
||||||
int32_t bytes = 0;
|
int32_t bytes = 0;
|
||||||
|
|
||||||
if (colIndex == TSDB_TBNAME_COLUMN_INDEX) { // todo refactor extract method , to queryExecutor to generate tags values
|
if (colIndex == TSDB_TBNAME_COLUMN_INDEX) {
|
||||||
f1 = (char*) pTable1->name;
|
f1 = (char*) TABLE_NAME(pTable1);
|
||||||
f2 = (char*) pTable2->name;
|
f2 = (char*) TABLE_NAME(pTable2);
|
||||||
type = TSDB_DATA_TYPE_BINARY;
|
type = TSDB_DATA_TYPE_BINARY;
|
||||||
bytes = tGetTableNameColumnSchema().bytes;
|
bytes = tGetTableNameColumnSchema().bytes;
|
||||||
} else {
|
} else {
|
||||||
|
@ -2089,13 +2087,17 @@ bool indexedNodeFilterFp(const void* pNode, void* param) {
|
||||||
char* val = NULL;
|
char* val = NULL;
|
||||||
|
|
||||||
if (pInfo->colIndex == TSDB_TBNAME_COLUMN_INDEX) {
|
if (pInfo->colIndex == TSDB_TBNAME_COLUMN_INDEX) {
|
||||||
val = (char*) pTable->name;
|
val = (char*) TABLE_NAME(pTable);
|
||||||
} else {
|
} else {
|
||||||
val = tdGetKVRowValOfCol(pTable->tagVal, pInfo->sch.colId);
|
val = tdGetKVRowValOfCol(pTable->tagVal, pInfo->sch.colId);
|
||||||
}
|
}
|
||||||
|
|
||||||
//todo :the val is possible to be null, so check it out carefully
|
int32_t ret = 0;
|
||||||
int32_t ret = pInfo->compare(val, pInfo->q);
|
if (val == NULL) { //the val is possible to be null, so check it out carefully
|
||||||
|
ret = -1; // val is missing in table tags value pairs
|
||||||
|
} else {
|
||||||
|
ret = pInfo->compare(val, pInfo->q);
|
||||||
|
}
|
||||||
|
|
||||||
switch (pInfo->optr) {
|
switch (pInfo->optr) {
|
||||||
case TSDB_RELATION_EQUAL: {
|
case TSDB_RELATION_EQUAL: {
|
||||||
|
|
Loading…
Reference in New Issue