未验证 提交 d4a834e2 编写于 作者: H Haojun Liao 提交者: GitHub

Merge pull request #8937 from taosdata/feature/3.0_liaohj

Feature/3.0 liaohj
...@@ -55,10 +55,18 @@ typedef struct SDataBlockInfo { ...@@ -55,10 +55,18 @@ typedef struct SDataBlockInfo {
int64_t uid; int64_t uid;
} SDataBlockInfo; } SDataBlockInfo;
typedef struct SConstantItem {
SColumnInfo info;
int32_t startIndex; // run-length-encoding to save the space for multiple rows
int32_t endIndex;
SVariant value;
} SConstantItem;
typedef struct SSDataBlock { typedef struct SSDataBlock {
SColumnDataAgg *pBlockAgg; SColumnDataAgg *pBlockAgg;
SArray *pDataBlock; // SArray<SColumnInfoData> SArray *pDataBlock; // SArray<SColumnInfoData>
SDataBlockInfo info; SArray *pConstantList; // SArray<SConstantItem>, it is a constant/tags value of the corresponding result value.
SDataBlockInfo info;
} SSDataBlock; } SSDataBlock;
typedef struct SColumnInfoData { typedef struct SColumnInfoData {
...@@ -82,7 +90,7 @@ typedef struct SLimit { ...@@ -82,7 +90,7 @@ typedef struct SLimit {
typedef struct SOrder { typedef struct SOrder {
uint32_t order; uint32_t order;
int32_t orderColId; SColumn col;
} SOrder; } SOrder;
typedef struct SGroupbyExpr { typedef struct SGroupbyExpr {
......
...@@ -281,7 +281,7 @@ typedef struct SSchema { ...@@ -281,7 +281,7 @@ typedef struct SSchema {
uint8_t type; uint8_t type;
char name[TSDB_COL_NAME_LEN]; char name[TSDB_COL_NAME_LEN];
int16_t colId; int16_t colId;
int16_t bytes; int32_t bytes;
} SSchema; } SSchema;
//#endif //#endif
......
...@@ -54,6 +54,7 @@ extern int32_t tsCompressColData; ...@@ -54,6 +54,7 @@ extern int32_t tsCompressColData;
extern int32_t tsMaxNumOfDistinctResults; extern int32_t tsMaxNumOfDistinctResults;
extern char tsTempDir[]; extern char tsTempDir[];
extern int64_t tsMaxVnodeQueuedBytes; extern int64_t tsMaxVnodeQueuedBytes;
extern int tsCompatibleModel; // 2.0 compatible model
//query buffer management //query buffer management
extern int32_t tsQueryBufferSize; // maximum allowed usage buffer size in MB for each data node during query processing extern int32_t tsQueryBufferSize; // maximum allowed usage buffer size in MB for each data node during query processing
......
...@@ -229,7 +229,7 @@ typedef struct SScalarFunctionInfo { ...@@ -229,7 +229,7 @@ typedef struct SScalarFunctionInfo {
typedef struct SMultiFunctionsDesc { typedef struct SMultiFunctionsDesc {
bool stableQuery; bool stableQuery;
bool groupbyColumn; bool groupbyColumn;
bool simpleAgg; bool agg;
bool arithmeticOnAgg; bool arithmeticOnAgg;
bool projectionQuery; bool projectionQuery;
bool hasFilter; bool hasFilter;
...@@ -261,6 +261,7 @@ int32_t qIsBuiltinFunction(const char* name, int32_t len, bool* scalarFunction); ...@@ -261,6 +261,7 @@ int32_t qIsBuiltinFunction(const char* name, int32_t len, bool* scalarFunction);
bool qIsValidUdf(SArray* pUdfInfo, const char* name, int32_t len, int32_t* functionId); bool qIsValidUdf(SArray* pUdfInfo, const char* name, int32_t len, int32_t* functionId);
bool qIsAggregateFunction(const char* functionName); bool qIsAggregateFunction(const char* functionName);
bool qIsSelectivityFunction(const char* functionName);
tExprNode* exprTreeFromBinary(const void* data, size_t size); tExprNode* exprTreeFromBinary(const void* data, size_t size);
......
...@@ -86,7 +86,7 @@ typedef struct SQueryStmtInfo { ...@@ -86,7 +86,7 @@ typedef struct SQueryStmtInfo {
SLimit slimit; SLimit slimit;
STagCond tagCond; STagCond tagCond;
SArray * colCond; SArray * colCond;
SOrder order; SArray * order;
int16_t numOfTables; int16_t numOfTables;
int16_t curTableIdx; int16_t curTableIdx;
STableMetaInfo **pTableMetaInfo; STableMetaInfo **pTableMetaInfo;
...@@ -108,10 +108,10 @@ typedef struct SQueryStmtInfo { ...@@ -108,10 +108,10 @@ typedef struct SQueryStmtInfo {
SArray *pUdfInfo; SArray *pUdfInfo;
struct SQueryStmtInfo *sibling; // sibling struct SQueryStmtInfo *sibling; // sibling
SArray *pUpstream; // SArray<struct SQueryStmtInfo>
struct SQueryStmtInfo *pDownstream; struct SQueryStmtInfo *pDownstream;
SMultiFunctionsDesc info;
SArray *pUpstream; // SArray<struct SQueryStmtInfo>
int32_t havingFieldNum; int32_t havingFieldNum;
SMultiFunctionsDesc info;
int32_t exprListLevelIndex; int32_t exprListLevelIndex;
} SQueryStmtInfo; } SQueryStmtInfo;
...@@ -176,6 +176,7 @@ typedef struct SSourceParam { ...@@ -176,6 +176,7 @@ typedef struct SSourceParam {
SExprInfo* createExprInfo(STableMetaInfo* pTableMetaInfo, const char* funcName, SSourceParam* pSource, SSchema* pResSchema, int16_t interSize); SExprInfo* createExprInfo(STableMetaInfo* pTableMetaInfo, const char* funcName, SSourceParam* pSource, SSchema* pResSchema, int16_t interSize);
int32_t copyExprInfoList(SArray* dst, const SArray* src, uint64_t uid, bool deepcopy); int32_t copyExprInfoList(SArray* dst, const SArray* src, uint64_t uid, bool deepcopy);
int32_t getExprFunctionLevel(SQueryStmtInfo* pQueryInfo);
STableMetaInfo* getMetaInfo(SQueryStmtInfo* pQueryInfo, int32_t tableIndex); STableMetaInfo* getMetaInfo(SQueryStmtInfo* pQueryInfo, int32_t tableIndex);
SSchema *getOneColumnSchema(const STableMeta* pTableMeta, int32_t colIndex); SSchema *getOneColumnSchema(const STableMeta* pTableMeta, int32_t colIndex);
......
...@@ -23,6 +23,35 @@ extern "C" { ...@@ -23,6 +23,35 @@ extern "C" {
#define QUERY_TYPE_MERGE 1 #define QUERY_TYPE_MERGE 1
#define QUERY_TYPE_PARTIAL 2 #define QUERY_TYPE_PARTIAL 2
enum OPERATOR_TYPE_E {
OP_TableScan = 1,
OP_DataBlocksOptScan = 2,
OP_TableSeqScan = 3,
OP_TagScan = 4,
OP_TableBlockInfoScan= 5,
OP_Aggregate = 6,
OP_Project = 7,
OP_Groupby = 8,
OP_Limit = 9,
OP_SLimit = 10,
OP_TimeWindow = 11,
OP_SessionWindow = 12,
OP_StateWindow = 22,
OP_Fill = 13,
OP_MultiTableAggregate = 14,
OP_MultiTableTimeInterval = 15,
// OP_DummyInput = 16, //TODO remove it after fully refactor.
// OP_MultiwayMergeSort = 17, // multi-way data merge into one input stream.
// OP_GlobalAggregate = 18, // global merge for the multi-way data sources.
OP_Filter = 19,
OP_Distinct = 20,
OP_Join = 21,
OP_AllTimeWindow = 23,
OP_AllMultiTableTimeInterval = 24,
OP_Order = 25,
OP_Exchange = 26,
};
struct SEpSet; struct SEpSet;
struct SQueryPlanNode; struct SQueryPlanNode;
struct SQueryDistPlanNode; struct SQueryDistPlanNode;
......
...@@ -75,6 +75,11 @@ int32_t tsCompressMsgSize = -1; ...@@ -75,6 +75,11 @@ int32_t tsCompressMsgSize = -1;
*/ */
int32_t tsCompressColData = -1; int32_t tsCompressColData = -1;
/*
* denote if 3.0 query pattern compatible for 2.0
*/
int32_t tsCompatibleModel = 1;
// client // client
int32_t tsMaxSQLStringLen = TSDB_MAX_ALLOWED_SQL_LEN; int32_t tsMaxSQLStringLen = TSDB_MAX_ALLOWED_SQL_LEN;
int32_t tsMaxWildCardsLen = TSDB_PATTERN_STRING_DEFAULT_LEN; int32_t tsMaxWildCardsLen = TSDB_PATTERN_STRING_DEFAULT_LEN;
......
...@@ -279,34 +279,6 @@ enum { ...@@ -279,34 +279,6 @@ enum {
OP_EXEC_DONE = 3, OP_EXEC_DONE = 3,
}; };
enum OPERATOR_TYPE_E {
OP_TableScan = 1,
OP_DataBlocksOptScan = 2,
OP_TableSeqScan = 3,
OP_TagScan = 4,
OP_TableBlockInfoScan= 5,
OP_Aggregate = 6,
OP_Project = 7,
OP_Groupby = 8,
OP_Limit = 9,
OP_SLimit = 10,
OP_TimeWindow = 11,
OP_SessionWindow = 12,
OP_Fill = 13,
OP_MultiTableAggregate = 14,
OP_MultiTableTimeInterval = 15,
OP_DummyInput = 16, //TODO remove it after fully refactor.
OP_MultiwayMergeSort = 17, // multi-way data merge into one input stream.
OP_GlobalAggregate = 18, // global merge for the multi-way data sources.
OP_Filter = 19,
OP_Distinct = 20,
OP_Join = 21,
OP_StateWindow = 22,
OP_AllTimeWindow = 23,
OP_AllMultiTableTimeInterval = 24,
OP_Order = 25,
};
typedef struct SOperatorInfo { typedef struct SOperatorInfo {
uint8_t operatorType; uint8_t operatorType;
bool blockingOptr; // block operator or not bool blockingOptr; // block operator or not
......
...@@ -4589,7 +4589,7 @@ SAggFunctionInfo aggFunc[35] = {{ ...@@ -4589,7 +4589,7 @@ SAggFunctionInfo aggFunc[35] = {{
}, },
{ {
// 16 // 16
"ts", "dummy",
FUNCTION_TYPE_AGG, FUNCTION_TYPE_AGG,
FUNCTION_TS, FUNCTION_TS,
FUNCTION_TS, FUNCTION_TS,
......
...@@ -13,6 +13,7 @@ ...@@ -13,6 +13,7 @@
* 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 "function.h"
#include "os.h" #include "os.h"
#include "exception.h" #include "exception.h"
...@@ -550,6 +551,15 @@ tExprNode* exprdup(tExprNode* pNode) { ...@@ -550,6 +551,15 @@ tExprNode* exprdup(tExprNode* pNode) {
} else if (pNode->nodeType == TEXPR_COL_NODE) { } else if (pNode->nodeType == TEXPR_COL_NODE) {
pCloned->pSchema = calloc(1, sizeof(SSchema)); pCloned->pSchema = calloc(1, sizeof(SSchema));
*pCloned->pSchema = *pNode->pSchema; *pCloned->pSchema = *pNode->pSchema;
} else if (pNode->nodeType == TEXPR_FUNCTION_NODE) {
strcpy(pCloned->_function.functionName, pNode->_function.functionName);
int32_t num = pNode->_function.num;
pCloned->_function.num = num;
pCloned->_function.pChild = calloc(num, POINTER_BYTES);
for(int32_t i = 0; i < num; ++i) {
pCloned->_function.pChild[i] = exprdup(pNode->_function.pChild[i]);
}
} }
pCloned->nodeType = pNode->nodeType; pCloned->nodeType = pNode->nodeType;
......
...@@ -54,6 +54,18 @@ bool qIsAggregateFunction(const char* functionName) { ...@@ -54,6 +54,18 @@ bool qIsAggregateFunction(const char* functionName) {
return !scalarfunc; return !scalarfunc;
} }
bool qIsSelectivityFunction(const char* functionName) {
assert(functionName != NULL);
pthread_once(&functionHashTableInit, doInitFunctionHashTable);
size_t len = strlen(functionName);
SAggFunctionInfo** pInfo = taosHashGet(functionHashTable, functionName, len);
if (pInfo != NULL) {
return ((*pInfo)->status | FUNCSTATE_SELECTIVITY) != 0;
}
return false;
}
SAggFunctionInfo* qGetFunctionInfo(const char* name, int32_t len) { SAggFunctionInfo* qGetFunctionInfo(const char* name, int32_t len) {
pthread_once(&functionHashTableInit, doInitFunctionHashTable); pthread_once(&functionHashTableInit, doInitFunctionHashTable);
...@@ -79,16 +91,17 @@ void qRemoveUdfInfo(uint64_t id, SUdfInfo* pUdfInfo) { ...@@ -79,16 +91,17 @@ void qRemoveUdfInfo(uint64_t id, SUdfInfo* pUdfInfo) {
bool isTagsQuery(SArray* pFunctionIdList) { bool isTagsQuery(SArray* pFunctionIdList) {
int32_t num = (int32_t) taosArrayGetSize(pFunctionIdList); int32_t num = (int32_t) taosArrayGetSize(pFunctionIdList);
for (int32_t i = 0; i < num; ++i) { for (int32_t i = 0; i < num; ++i) {
int16_t f = *(int16_t*) taosArrayGet(pFunctionIdList, i); char* f = *(char**) taosArrayGet(pFunctionIdList, i);
// todo handle count(tbname) query
if (strcmp(f, "project") != 0 && strcmp(f, "count") != 0) {
return false;
}
// "select count(tbname)" query // "select count(tbname)" query
// if (functId == FUNCTION_COUNT && pExpr->base.colpDesc->colId == TSDB_TBNAME_COLUMN_INDEX) { // if (functId == FUNCTION_COUNT && pExpr->base.colpDesc->colId == TSDB_TBNAME_COLUMN_INDEX) {
// continue; // continue;
// } // }
if (f != FUNCTION_TAGPRJ && f != FUNCTION_TID_TAG) {
return false;
}
} }
return true; return true;
...@@ -113,23 +126,13 @@ bool isTagsQuery(SArray* pFunctionIdList) { ...@@ -113,23 +126,13 @@ bool isTagsQuery(SArray* pFunctionIdList) {
bool isProjectionQuery(SArray* pFunctionIdList) { bool isProjectionQuery(SArray* pFunctionIdList) {
int32_t num = (int32_t) taosArrayGetSize(pFunctionIdList); int32_t num = (int32_t) taosArrayGetSize(pFunctionIdList);
for (int32_t i = 0; i < num; ++i) { for (int32_t i = 0; i < num; ++i) {
int32_t f = *(int16_t*) taosArrayGet(pFunctionIdList, i); char* f = *(char**) taosArrayGet(pFunctionIdList, i);
if (f == FUNCTION_TS_DUMMY) { if (strcmp(f, "project") == 0) {
continue; return true;
}
if (f != FUNCTION_PRJ &&
f != FUNCTION_TAGPRJ &&
f != FUNCTION_TAG &&
f != FUNCTION_TS &&
f != FUNCTION_ARITHM &&
f != FUNCTION_DIFF &&
f != FUNCTION_DERIVATIVE) {
return false;
} }
} }
return true; return false;
} }
bool isDiffDerivativeQuery(SArray* pFunctionIdList) { bool isDiffDerivativeQuery(SArray* pFunctionIdList) {
...@@ -182,30 +185,19 @@ bool isArithmeticQueryOnAggResult(SArray* pFunctionIdList) { ...@@ -182,30 +185,19 @@ bool isArithmeticQueryOnAggResult(SArray* pFunctionIdList) {
return false; return false;
} }
bool isGroupbyColumn(SArray* pFunctionIdList) { bool isGroupbyColumn(SGroupbyExpr* pGroupby) {
// STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, 0); return !pGroupby->groupbyTag;
// int32_t numOfCols = getNumOfColumns(pTableMetaInfo->pTableMeta);
//
// SGroupbyExpr* pGroupbyExpr = &pQueryInfo->groupbyExpr;
// for (int32_t k = 0; k < pGroupbyExpr->numOfGroupCols; ++k) {
// SColIndex* pIndex = taosArrayGet(pGroupbyExpr->columnInfo, k);
// if (!TSDB_COL_IS_TAG(pIndex->flag) && pIndex->colIndex < numOfCols) { // group by normal columns
// return true;
// }
// }
return false;
} }
bool isTopBotQuery(SArray* pFunctionIdList) { bool isTopBotQuery(SArray* pFunctionIdList) {
int32_t num = (int32_t) taosArrayGetSize(pFunctionIdList); int32_t num = (int32_t) taosArrayGetSize(pFunctionIdList);
for (int32_t i = 0; i < num; ++i) { for (int32_t i = 0; i < num; ++i) {
int32_t f = *(int16_t*) taosArrayGet(pFunctionIdList, i); char* f = *(char**) taosArrayGet(pFunctionIdList, i);
if (f == FUNCTION_TS) { if (strcmp(f, "project") == 0) {
continue; continue;
} }
if (f == FUNCTION_TOP || f == FUNCTION_BOTTOM) { if (strcmp(f, "top") == 0 || strcmp(f, "bottom") == 0) {
return true; return true;
} }
} }
...@@ -284,49 +276,26 @@ bool needReverseScan(SArray* pFunctionIdList) { ...@@ -284,49 +276,26 @@ bool needReverseScan(SArray* pFunctionIdList) {
return false; return false;
} }
bool isSimpleAggregateRv(SArray* pFunctionIdList) { bool isAgg(SArray* pFunctionIdList) {
// if (pQueryInfo->interval.interval > 0 || pQueryInfo->sessionWindow.gap > 0) { size_t size = taosArrayGetSize(pFunctionIdList);
// return false; for (int32_t i = 0; i < size; ++i) {
// } char* f = *(char**) taosArrayGet(pFunctionIdList, i);
// if (strcmp(f, "project") == 0) {
// if (tscIsDiffDerivQuery(pQueryInfo)) { return false;
// return false; }
// }
// if (qIsAggregateFunction(f)) {
// size_t numOfExprs = getNumOfExprs(pQueryInfo); return true;
// for (int32_t i = 0; i < numOfExprs; ++i) { }
// SExprInfo* pExpr = getExprInfo(pQueryInfo, i); }
// if (pExpr == NULL) {
// continue;
// }
//
// int32_t functionId = pExpr->base.functionId;
// if (functionId < 0) {
// SUdfInfo* pUdfInfo = taosArrayGet(pQueryInfo->pUdfInfo, -1 * functionId - 1);
// if (pUdfInfo->funcType == TSDB_UDF_TYPE_AGGREGATE) {
// return true;
// }
//
// continue;
// }
//
// if (functionId == FUNCTION_TS || functionId == FUNCTION_TS_DUMMY) {
// continue;
// }
//
// if ((!IS_MULTIOUTPUT(aAggs[functionId].status)) ||
// (functionId == FUNCTION_TOP || functionId == FUNCTION_BOTTOM || functionId == FUNCTION_TS_COMP)) {
// return true;
// }
// }
return false; return false;
} }
bool isBlockDistQuery(SArray* pFunctionIdList) { bool isBlockDistQuery(SArray* pFunctionIdList) {
int32_t num = (int32_t) taosArrayGetSize(pFunctionIdList); int32_t num = (int32_t) taosArrayGetSize(pFunctionIdList);
int32_t f = *(int16_t*) taosArrayGet(pFunctionIdList, 0); char* f = *(char**) taosArrayGet(pFunctionIdList, 0);
return (num == 1 && f == FUNCTION_BLKINFO); return (num == 1 && strcmp(f, "block_dist") == 0);
} }
bool isTwoStageSTableQuery(SArray* pFunctionIdList, int32_t tableIndex) { bool isTwoStageSTableQuery(SArray* pFunctionIdList, int32_t tableIndex) {
...@@ -432,13 +401,14 @@ bool hasTagValOutput(SArray* pFunctionIdList) { ...@@ -432,13 +401,14 @@ bool hasTagValOutput(SArray* pFunctionIdList) {
void extractFunctionDesc(SArray* pFunctionIdList, SMultiFunctionsDesc* pDesc) { void extractFunctionDesc(SArray* pFunctionIdList, SMultiFunctionsDesc* pDesc) {
assert(pFunctionIdList != NULL); assert(pFunctionIdList != NULL);
pDesc->blockDistribution = isBlockDistQuery(pFunctionIdList); pDesc->blockDistribution = isBlockDistQuery(pFunctionIdList);
if (pDesc->blockDistribution) { if (pDesc->blockDistribution) {
return; return;
} }
pDesc->projectionQuery = isProjectionQuery(pFunctionIdList); // pDesc->projectionQuery = isProjectionQuery(pFunctionIdList);
pDesc->onlyTagQuery = isTagsQuery(pFunctionIdList); // pDesc->onlyTagQuery = isTagsQuery(pFunctionIdList);
pDesc->interpQuery = isInterpQuery(pFunctionIdList); pDesc->interpQuery = isInterpQuery(pFunctionIdList);
pDesc->topbotQuery = isTopBotQuery(pFunctionIdList);
pDesc->agg = isAgg(pFunctionIdList);
} }
...@@ -294,7 +294,10 @@ SCreateTableSql *tSetCreateTableInfo(SArray *pCols, SArray *pTags, SSqlNode *pSe ...@@ -294,7 +294,10 @@ SCreateTableSql *tSetCreateTableInfo(SArray *pCols, SArray *pTags, SSqlNode *pSe
SAlterTableInfo * tSetAlterTableInfo(SToken *pTableName, SArray *pCols, SArray *pVals, int32_t type, int16_t tableType); SAlterTableInfo * tSetAlterTableInfo(SToken *pTableName, SArray *pCols, SArray *pVals, int32_t type, int16_t tableType);
SCreatedTableInfo createNewChildTableInfo(SToken *pTableName, SArray *pTagNames, SArray *pTagVals, SToken *pToken, SCreatedTableInfo createNewChildTableInfo(SToken *pTableName, SArray *pTagNames, SArray *pTagVals, SToken *pToken,
SToken *igExists); SToken *igExists);
/*!
* test
* @param pSqlNode
*/
void destroyAllSqlNode(struct SSubclause *pSqlNode); void destroyAllSqlNode(struct SSubclause *pSqlNode);
void destroySqlNode(SSqlNode *pSql); void destroySqlNode(SSqlNode *pSql);
void freeCreateTableInfo(void* p); void freeCreateTableInfo(void* p);
......
...@@ -59,8 +59,7 @@ SArray *tListItemAppendToken(SArray *pList, SToken *pAliasToken, uint8_t sortOrd ...@@ -59,8 +59,7 @@ SArray *tListItemAppendToken(SArray *pList, SToken *pAliasToken, uint8_t sortOrd
if (pAliasToken) { if (pAliasToken) {
SListItem item; SListItem item;
assert(0); taosVariantCreate(&item.pVar, pAliasToken->z, pAliasToken->n, pAliasToken->type);
// taosVariantCreate(&item.pVar, pAliasToken);
item.sortOrder = sortOrder; item.sortOrder = sortOrder;
taosArrayPush(pList, &item); taosArrayPush(pList, &item);
......
...@@ -223,7 +223,7 @@ void addExprInfoParam(SSqlExpr* pExpr, char* argument, int32_t type, int32_t byt ...@@ -223,7 +223,7 @@ void addExprInfoParam(SSqlExpr* pExpr, char* argument, int32_t type, int32_t byt
} }
int32_t getExprFunctionId(SExprInfo *pExprInfo) { int32_t getExprFunctionId(SExprInfo *pExprInfo) {
assert(pExprInfo != NULL && pExprInfo->pExpr != NULL && pExprInfo->pExpr->nodeType == TEXPR_UNARYEXPR_NODE); assert(pExprInfo != NULL && pExprInfo->pExpr != NULL && pExprInfo->pExpr->nodeType == TEXPR_FUNCTION_NODE);
return 0; return 0;
} }
...@@ -324,10 +324,17 @@ SArray* extractFunctionList(SArray* pExprInfoList) { ...@@ -324,10 +324,17 @@ SArray* extractFunctionList(SArray* pExprInfoList) {
assert(pExprInfoList != NULL); assert(pExprInfoList != NULL);
size_t len = taosArrayGetSize(pExprInfoList); size_t len = taosArrayGetSize(pExprInfoList);
SArray* p = taosArrayInit(len, sizeof(int32_t)); SArray* p = taosArrayInit(len, POINTER_BYTES);
for(int32_t i = 0; i < len; ++i) { for(int32_t i = 0; i < len; ++i) {
SExprInfo* pExprInfo = taosArrayGetP(pExprInfoList, i); SExprInfo* pExprInfo = taosArrayGetP(pExprInfoList, i);
taosArrayPush(p, &pExprInfo->pExpr->_function.functionName); if (pExprInfo->pExpr->nodeType == TEXPR_FUNCTION_NODE) {
char* name = strdup(pExprInfo->pExpr->_function.functionName);
taosArrayPush(p, &name);
} else {
char* name = strdup("project");
taosArrayPush(p, &name);
}
} }
return p; return p;
...@@ -350,11 +357,16 @@ bool tscHasColumnFilter(SQueryStmtInfo* pQueryInfo) { ...@@ -350,11 +357,16 @@ bool tscHasColumnFilter(SQueryStmtInfo* pQueryInfo) {
return false; return false;
} }
//void tscClearInterpInfo(SQueryStmtInfo* pQueryInfo) { int32_t getExprFunctionLevel(SQueryStmtInfo* pQueryInfo) {
// if (!tscIsPointInterpQuery(pQueryInfo)) { int32_t n = 10;
// return;
// } int32_t level = 0;
// for(int32_t i = 0; i < n; ++i) {
// pQueryInfo->fillType = TSDB_FILL_NONE; SArray* pList = pQueryInfo->exprList[i];
// tfree(pQueryInfo->fillVal); if (taosArrayGetSize(pList) > 0) {
//} level += 1;
\ No newline at end of file }
}
return level;
}
\ No newline at end of file
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <function.h> #include <function.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <iostream> #include <iostream>
#include "tglobal.h"
#pragma GCC diagnostic ignored "-Wwrite-strings" #pragma GCC diagnostic ignored "-Wwrite-strings"
#pragma GCC diagnostic ignored "-Wunused-function" #pragma GCC diagnostic ignored "-Wunused-function"
...@@ -398,6 +399,7 @@ TEST(testCase, function_Test5) { ...@@ -398,6 +399,7 @@ TEST(testCase, function_Test5) {
TEST(testCase, function_Test10) { TEST(testCase, function_Test10) {
sqlCheck("select c from `t.1abc`", true); sqlCheck("select c from `t.1abc`", true);
sqlCheck("select length(c) from `t.1abc`", true); sqlCheck("select length(c) from `t.1abc`", true);
sqlCheck("select length(sum(col)) from `t.1abc`", true);
sqlCheck("select sum(length(a+b)) from `t.1abc`", true); sqlCheck("select sum(length(a+b)) from `t.1abc`", true);
sqlCheck("select sum(sum(a+b)) from `t.1abc`", false); sqlCheck("select sum(sum(a+b)) from `t.1abc`", false);
sqlCheck("select sum(length(a) + length(b)) from `t.1abc`", true); sqlCheck("select sum(length(a) + length(b)) from `t.1abc`", true);
...@@ -406,12 +408,27 @@ TEST(testCase, function_Test10) { ...@@ -406,12 +408,27 @@ TEST(testCase, function_Test10) {
sqlCheck("select cov(a, b) from `t.1abc`", true); sqlCheck("select cov(a, b) from `t.1abc`", true);
sqlCheck("select sum(length(a) + count(b)) from `t.1abc`", false); sqlCheck("select sum(length(a) + count(b)) from `t.1abc`", false);
sqlCheck("select concat(sum(a), count(b)) from `t.1abc`", true);
sqlCheck("select concat(concat(a,b), concat(a,b)) from `t.1abc`", true); sqlCheck("select concat(concat(a,b), concat(a,b)) from `t.1abc`", true);
sqlCheck("select length(length(length(a))) from `t.1abc`", true); sqlCheck("select length(length(length(a))) from `t.1abc`", true);
sqlCheck("select count() from `t.1abc`", false); sqlCheck("select count() from `t.1abc`", false);
sqlCheck("select block_dist() from `t.1abc`", true); sqlCheck("select block_dist() from `t.1abc`", true);
sqlCheck("select block_dist(a) from `t.1abc`", false); sqlCheck("select block_dist(a) from `t.1abc`", false);
sqlCheck("select count(*) from `t.1abc` interval(1s) group by a", false); sqlCheck("select count(*) from `t.1abc` interval(1s) group by a", false);
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////
sqlCheck("select length119(a,b) from `t.1abc`", false);
sqlCheck("select length(a, b) from `t.1abc`", false);
sqlCheck("select block_dist() + 20 from `t.1abc`", true);
sqlCheck("select count(b), c from `t.1abc`", false);
sqlCheck("select top(a, 20), count(b) from `t.1abc`", false);
sqlCheck("select top(a, 20), b from `t.1abc`", false);
sqlCheck("select top(a, 20), a+20 from `t.1abc`", true);
// sqlCheck("select top(a, 20), bottom(a, 10) from `t.1abc`", false);
// sqlCheck("select last_row(*), count(b) from `t.1abc`", false);
// sqlCheck("select last_row(a, b) + 20 from `t.1abc`", false);
// sqlCheck("select last_row(count(*)) from `t.1abc`", false);
} }
TEST(testCase, function_Test6) { TEST(testCase, function_Test6) {
...@@ -441,9 +458,14 @@ TEST(testCase, function_Test6) { ...@@ -441,9 +458,14 @@ TEST(testCase, function_Test6) {
ASSERT_EQ(ret, 0); ASSERT_EQ(ret, 0);
SArray* pExprList = pQueryInfo->exprList[0]; SArray* pExprList = pQueryInfo->exprList[0];
ASSERT_EQ(taosArrayGetSize(pExprList), 5); if (tsCompatibleModel) {
ASSERT_EQ(taosArrayGetSize(pExprList), 6);
} else {
ASSERT_EQ(taosArrayGetSize(pExprList), 5);
}
SExprInfo* p1 = (SExprInfo*)taosArrayGetP(pExprList, 0); int32_t index = tsCompatibleModel? 1:0;
SExprInfo* p1 = (SExprInfo*)taosArrayGetP(pExprList, index);
ASSERT_EQ(p1->base.pColumns->uid, 110); ASSERT_EQ(p1->base.pColumns->uid, 110);
ASSERT_EQ(p1->base.numOfParams, 0); ASSERT_EQ(p1->base.numOfParams, 0);
ASSERT_EQ(p1->base.resSchema.type, TSDB_DATA_TYPE_DOUBLE); ASSERT_EQ(p1->base.resSchema.type, TSDB_DATA_TYPE_DOUBLE);
...@@ -461,9 +483,12 @@ TEST(testCase, function_Test6) { ...@@ -461,9 +483,12 @@ TEST(testCase, function_Test6) {
ASSERT_STREQ(pParam->pSchema->name, "t.1abc.a+b"); ASSERT_STREQ(pParam->pSchema->name, "t.1abc.a+b");
ASSERT_EQ(taosArrayGetSize(pQueryInfo->colList), 3); ASSERT_EQ(taosArrayGetSize(pQueryInfo->colList), 3);
ASSERT_EQ(pQueryInfo->fieldsInfo.numOfOutput, 5);
SExprInfo* p2 = (SExprInfo*)taosArrayGetP(pExprList, 1); int32_t numOfResCol = tsCompatibleModel? 6:5;
ASSERT_EQ(pQueryInfo->fieldsInfo.numOfOutput, numOfResCol);
index = tsCompatibleModel? 2:1;
SExprInfo* p2 = (SExprInfo*)taosArrayGetP(pExprList, index);
ASSERT_EQ(p2->base.pColumns->uid, 110); ASSERT_EQ(p2->base.pColumns->uid, 110);
ASSERT_EQ(p2->base.numOfParams, 0); ASSERT_EQ(p2->base.numOfParams, 0);
ASSERT_EQ(p2->base.resSchema.type, TSDB_DATA_TYPE_DOUBLE); ASSERT_EQ(p2->base.resSchema.type, TSDB_DATA_TYPE_DOUBLE);
...@@ -511,9 +536,10 @@ TEST(testCase, function_Test6) { ...@@ -511,9 +536,10 @@ TEST(testCase, function_Test6) {
ASSERT_EQ(ret, 0); ASSERT_EQ(ret, 0);
SArray* pExprList = pQueryInfo->exprList[0]; SArray* pExprList = pQueryInfo->exprList[0];
ASSERT_EQ(taosArrayGetSize(pExprList), 2); ASSERT_EQ(taosArrayGetSize(pExprList), 3);
SExprInfo* p1 = (SExprInfo*) taosArrayGetP(pExprList, 0); int32_t index = tsCompatibleModel? 1:0;
SExprInfo* p1 = (SExprInfo*) taosArrayGetP(pExprList, index);
ASSERT_EQ(p1->base.pColumns->uid, 110); ASSERT_EQ(p1->base.pColumns->uid, 110);
ASSERT_EQ(p1->base.numOfParams, 0); ASSERT_EQ(p1->base.numOfParams, 0);
ASSERT_EQ(p1->base.resSchema.type, TSDB_DATA_TYPE_BIGINT); ASSERT_EQ(p1->base.resSchema.type, TSDB_DATA_TYPE_BIGINT);
...@@ -537,7 +563,9 @@ TEST(testCase, function_Test6) { ...@@ -537,7 +563,9 @@ TEST(testCase, function_Test6) {
ASSERT_EQ(pParam->pSchema->colId, p2->base.resSchema.colId); ASSERT_EQ(pParam->pSchema->colId, p2->base.resSchema.colId);
ASSERT_EQ(taosArrayGetSize(pQueryInfo->colList), 3); ASSERT_EQ(taosArrayGetSize(pQueryInfo->colList), 3);
ASSERT_EQ(pQueryInfo->fieldsInfo.numOfOutput, 2);
int32_t numOfCols = tsCompatibleModel? 3:2;
ASSERT_EQ(pQueryInfo->fieldsInfo.numOfOutput, numOfCols);
destroyQueryInfo(pQueryInfo); destroyQueryInfo(pQueryInfo);
qParserClearupMetaRequestInfo(&req); qParserClearupMetaRequestInfo(&req);
......
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <function.h> #include <function.h>
#include <gtest/gtest.h> #include <gtest/gtest.h>
#include <tglobal.h>
#include <iostream> #include <iostream>
#pragma GCC diagnostic ignored "-Wwrite-strings" #pragma GCC diagnostic ignored "-Wwrite-strings"
...@@ -63,7 +64,6 @@ void setTableMetaInfo(SQueryStmtInfo* pQueryInfo, SMetaReq *req) { ...@@ -63,7 +64,6 @@ void setTableMetaInfo(SQueryStmtInfo* pQueryInfo, SMetaReq *req) {
setSchema(&pSchema[1], TSDB_DATA_TYPE_INT, 4, "a", 1); setSchema(&pSchema[1], TSDB_DATA_TYPE_INT, 4, "a", 1);
setSchema(&pSchema[2], TSDB_DATA_TYPE_DOUBLE, 8, "b", 2); setSchema(&pSchema[2], TSDB_DATA_TYPE_DOUBLE, 8, "b", 2);
setSchema(&pSchema[3], TSDB_DATA_TYPE_DOUBLE, 8, "col", 3); setSchema(&pSchema[3], TSDB_DATA_TYPE_DOUBLE, 8, "col", 3);
} }
void generateLogicplan(const char* sql) { void generateLogicplan(const char* sql) {
...@@ -132,7 +132,9 @@ TEST(testCase, planner_test) { ...@@ -132,7 +132,9 @@ TEST(testCase, planner_test) {
ASSERT_EQ(ret, 0); ASSERT_EQ(ret, 0);
SArray* pExprList = pQueryInfo->exprList[0]; SArray* pExprList = pQueryInfo->exprList[0];
ASSERT_EQ(taosArrayGetSize(pExprList), 2);
int32_t num = tsCompatibleModel? 2:1;
ASSERT_EQ(taosArrayGetSize(pExprList), num);
SExprInfo* p1 = (SExprInfo*) taosArrayGetP(pExprList, 1); SExprInfo* p1 = (SExprInfo*) taosArrayGetP(pExprList, 1);
ASSERT_EQ(p1->base.pColumns->uid, 110); ASSERT_EQ(p1->base.pColumns->uid, 110);
...@@ -172,6 +174,7 @@ TEST(testCase, displayPlan) { ...@@ -172,6 +174,7 @@ TEST(testCase, displayPlan) {
generateLogicplan("select count(A+B) from `t.1abc` group by a"); generateLogicplan("select count(A+B) from `t.1abc` group by a");
generateLogicplan("select count(length(a)+b) from `t.1abc` group by a"); generateLogicplan("select count(length(a)+b) from `t.1abc` group by a");
generateLogicplan("select count(*) from `t.1abc` interval(10s, 5s) sliding(7s)"); generateLogicplan("select count(*) from `t.1abc` interval(10s, 5s) sliding(7s)");
generateLogicplan("select count(*) from `t.1abc` interval(10s, 5s) sliding(7s) order by 1 desc ");
generateLogicplan("select count(*),sum(a),avg(b),min(a+b)+99 from `t.1abc`"); generateLogicplan("select count(*),sum(a),avg(b),min(a+b)+99 from `t.1abc`");
generateLogicplan("select count(*), min(a) + 99 from `t.1abc`"); generateLogicplan("select count(*), min(a) + 99 from `t.1abc`");
generateLogicplan("select count(length(count(*) + 22)) from `t.1abc`"); generateLogicplan("select count(length(count(*) + 22)) from `t.1abc`");
...@@ -179,14 +182,17 @@ TEST(testCase, displayPlan) { ...@@ -179,14 +182,17 @@ TEST(testCase, displayPlan) {
generateLogicplan("select count(*), first(a), last(b) from `t.1abc` state_window(a)"); generateLogicplan("select count(*), first(a), last(b) from `t.1abc` state_window(a)");
generateLogicplan("select count(*), first(a), last(b) from `t.1abc` session(ts, 20s)"); generateLogicplan("select count(*), first(a), last(b) from `t.1abc` session(ts, 20s)");
// order by + group by column + limit offset + fill // order by + group by column + limit offset
generateLogicplan("select top(a, 20) k from `t.1abc` order by k asc limit 3 offset 1");
// fill
generateLogicplan("select min(a) from `t.1abc` where ts>now and ts<now+2h interval(1s) fill(linear)");
// join // union + union all
// union
// join
// Aggregate(count(*) [count(*) #5056], sum(a) [sum(a) #5057], avg(b) [avg(b) #5058], min(a+b) [min(a+b) #5060]) // Aggregate(count(*) [count(*) #5056], sum(a) [sum(a) #5057], avg(b) [avg(b) #5058], min(a+b) [min(a+b) #5060])
// Projection(cols: [a+b #5059]) filters:(nil) // Projection(cols: [a+b #5059]) filters:(nil)
......
...@@ -26,18 +26,26 @@ extern "C" { ...@@ -26,18 +26,26 @@ extern "C" {
#include "taosmsg.h" #include "taosmsg.h"
typedef struct SQueryNodeBasicInfo { typedef struct SQueryNodeBasicInfo {
int32_t type; int32_t type; // operator type
char *name; char *name; // operator name
} SQueryNodeBasicInfo; } SQueryNodeBasicInfo;
typedef struct SQueryDistPlanNodeInfo {
bool stableQuery; // super table query or not
int32_t phase; // merge|partial
int32_t type; // operator type
char *name; // operator name
SEpSet *sourceEp; // data source epset
} SQueryDistPlanNodeInfo;
typedef struct SQueryTableInfo { typedef struct SQueryTableInfo {
char *tableName; char *tableName;
uint64_t uid; uint64_t uid;
STimeWindow window;
} SQueryTableInfo; } SQueryTableInfo;
typedef struct SQueryPlanNode { typedef struct SQueryPlanNode {
SQueryNodeBasicInfo info; SQueryNodeBasicInfo info;
SQueryTableInfo tableInfo;
SSchema *pSchema; // the schema of the input SSDatablock SSchema *pSchema; // the schema of the input SSDatablock
int32_t numOfCols; // number of input columns int32_t numOfCols; // number of input columns
SArray *pExpr; // the query functions or sql aggregations SArray *pExpr; // the query functions or sql aggregations
...@@ -51,9 +59,49 @@ typedef struct SQueryPlanNode { ...@@ -51,9 +59,49 @@ typedef struct SQueryPlanNode {
typedef struct SQueryDistPlanNode { typedef struct SQueryDistPlanNode {
SQueryNodeBasicInfo info; SQueryNodeBasicInfo info;
SSchema *pSchema; // the schema of the input SSDatablock
int32_t numOfCols; // number of input columns
SArray *pExpr; // the query functions or sql aggregations
int32_t numOfExpr; // number of result columns, which is also the number of pExprs
void *pExtInfo; // additional information
// previous operator to generated result for current node to process
// in case of join, multiple prev nodes exist.
SArray *pPrevNodes; // upstream nodes, or exchange operator to load data from multiple sources.
} SQueryDistPlanNode; } SQueryDistPlanNode;
typedef struct SQueryCostSummary {
int64_t startTs; // Object created and added into the message queue
int64_t endTs; // the timestamp when the task is completed
int64_t cputime; // total cpu cost, not execute elapsed time
int64_t loadRemoteDataDuration; // remote io time
int64_t loadNativeDataDuration; // native disk io time
uint64_t loadNativeData; // blocks + SMA + header files
uint64_t loadRemoteData; // remote data acquired by exchange operator.
uint64_t waitDuration; // the time to waiting to be scheduled in queue does matter, so we need to record it
int64_t addQTs; // the time to be added into the message queue, used to calculate the waiting duration in queue.
uint64_t totalRows;
uint64_t loadRows;
uint32_t totalBlocks;
uint32_t loadBlocks;
uint32_t loadBlockAgg;
uint32_t skipBlocks;
uint64_t resultSize; // generated result size in Kb.
} SQueryCostSummary;
typedef struct SQueryTask {
uint64_t queryId; // query id
uint64_t taskId; // task id
SQueryDistPlanNode *pNode; // operator tree
uint64_t status; // task status
SQueryCostSummary summary; // task execution summary
void *pOutputHandle; // result buffer handle, to temporarily keep the output result for next stage
} SQueryTask;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif
......
此差异已折叠。
...@@ -63,7 +63,7 @@ typedef struct SConvertFunc { ...@@ -63,7 +63,7 @@ typedef struct SConvertFunc {
int32_t execFuncId; int32_t execFuncId;
} SConvertFunc; } SConvertFunc;
static SExprInfo* doAddProjectCol(SQueryInfo* pQueryInfo, int32_t colIndex, int32_t tableIndex, int32_t colId); static SExprInfo* doAddOneProjectCol(SQueryInfo* pQueryInfo, int32_t colIndex, int32_t tableIndex, int32_t colId);
static int32_t setShowInfo(SSqlObj* pSql, SSqlInfo* pInfo); static int32_t setShowInfo(SSqlObj* pSql, SSqlInfo* pInfo);
static char* getAccountId(SSqlObj* pSql); static char* getAccountId(SSqlObj* pSql);
...@@ -1890,7 +1890,7 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32 ...@@ -1890,7 +1890,7 @@ static int32_t handleArithmeticExpr(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, int32
} }
static void addProjectQueryCol(SQueryInfo* pQueryInfo, int32_t startPos, SColumnIndex* pIndex, tSqlExprItem* pItem, int32_t colId) { static void addProjectQueryCol(SQueryInfo* pQueryInfo, int32_t startPos, SColumnIndex* pIndex, tSqlExprItem* pItem, int32_t colId) {
SExprInfo* pExpr = doAddProjectCol(pQueryInfo, pIndex->columnIndex, pIndex->tableIndex, colId); SExprInfo* pExpr = doAddOneProjectCol(pQueryInfo, pIndex->columnIndex, pIndex->tableIndex, colId);
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, pIndex->tableIndex); STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, pIndex->tableIndex);
STableMeta* pTableMeta = pTableMetaInfo->pTableMeta; STableMeta* pTableMeta = pTableMetaInfo->pTableMeta;
...@@ -2157,7 +2157,7 @@ int32_t insertResultField(SQueryInfo* pQueryInfo, int32_t outputIndex, SColumnLi ...@@ -2157,7 +2157,7 @@ int32_t insertResultField(SQueryInfo* pQueryInfo, int32_t outputIndex, SColumnLi
return TSDB_CODE_SUCCESS; return TSDB_CODE_SUCCESS;
} }
SExprInfo* doAddProjectCol(SQueryInfo* pQueryInfo, int32_t colIndex, int32_t tableIndex, int32_t colId) { SExprInfo* doAddOneProjectCol(SQueryInfo* pQueryInfo, int32_t colIndex, int32_t tableIndex, int32_t colId) {
STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, tableIndex); STableMetaInfo* pTableMetaInfo = tscGetMetaInfo(pQueryInfo, tableIndex);
STableMeta* pTableMeta = pTableMetaInfo->pTableMeta; STableMeta* pTableMeta = pTableMetaInfo->pTableMeta;
int32_t numOfCols = tscGetNumOfColumns(pTableMeta); int32_t numOfCols = tscGetNumOfColumns(pTableMeta);
...@@ -2218,7 +2218,7 @@ static int32_t doAddProjectionExprAndResultFields(SQueryInfo* pQueryInfo, SColum ...@@ -2218,7 +2218,7 @@ static int32_t doAddProjectionExprAndResultFields(SQueryInfo* pQueryInfo, SColum
} }
for (int32_t j = 0; j < numOfTotalColumns; ++j) { for (int32_t j = 0; j < numOfTotalColumns; ++j) {
SExprInfo* pExpr = doAddProjectCol(pQueryInfo, j, pIndex->tableIndex, getNewResColId(pCmd)); SExprInfo* pExpr = doAddOneProjectCol(pQueryInfo, j, pIndex->tableIndex, getNewResColId(pCmd));
tstrncpy(pExpr->base.aliasName, pSchema[j].name, sizeof(pExpr->base.aliasName)); tstrncpy(pExpr->base.aliasName, pSchema[j].name, sizeof(pExpr->base.aliasName));
pIndex->columnIndex = j; pIndex->columnIndex = j;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册