[td-3299]
This commit is contained in:
parent
dbe026a8ef
commit
d57b94599f
|
@ -135,7 +135,7 @@ typedef struct SJoinNode {
|
||||||
|
|
||||||
typedef struct SJoinInfo {
|
typedef struct SJoinInfo {
|
||||||
bool hasJoin;
|
bool hasJoin;
|
||||||
SJoinNode* joinTables[TSDB_MAX_JOIN_TABLE_NUM];
|
SJoinNode *joinTables[TSDB_MAX_JOIN_TABLE_NUM];
|
||||||
} SJoinInfo;
|
} SJoinInfo;
|
||||||
|
|
||||||
typedef struct STagCond {
|
typedef struct STagCond {
|
||||||
|
|
|
@ -3678,10 +3678,14 @@ static bool validateJoinExprNode(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSqlExpr
|
||||||
SSchema* pLeftSchema = tscGetTableSchema(pLeftMeterMeta->pTableMeta);
|
SSchema* pLeftSchema = tscGetTableSchema(pLeftMeterMeta->pTableMeta);
|
||||||
int16_t leftType = pLeftSchema[pLeftIndex->columnIndex].type;
|
int16_t leftType = pLeftSchema[pLeftIndex->columnIndex].type;
|
||||||
|
|
||||||
|
tscColumnListInsert(pQueryInfo->colList, pLeftIndex->columnIndex, pLeftMeterMeta->pTableMeta->id.uid, &pLeftSchema[pLeftIndex->columnIndex]);
|
||||||
|
|
||||||
STableMetaInfo* pRightMeterMeta = tscGetMetaInfo(pQueryInfo, rightIndex.tableIndex);
|
STableMetaInfo* pRightMeterMeta = tscGetMetaInfo(pQueryInfo, rightIndex.tableIndex);
|
||||||
SSchema* pRightSchema = tscGetTableSchema(pRightMeterMeta->pTableMeta);
|
SSchema* pRightSchema = tscGetTableSchema(pRightMeterMeta->pTableMeta);
|
||||||
int16_t rightType = pRightSchema[rightIndex.columnIndex].type;
|
int16_t rightType = pRightSchema[rightIndex.columnIndex].type;
|
||||||
|
|
||||||
|
tscColumnListInsert(pQueryInfo->colList, rightIndex.columnIndex, pRightMeterMeta->pTableMeta->id.uid, &pRightSchema[rightIndex.columnIndex]);
|
||||||
|
|
||||||
if (leftType != rightType) {
|
if (leftType != rightType) {
|
||||||
invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
|
invalidSqlErrMsg(tscGetErrorMsgPayload(pCmd), msg3);
|
||||||
return false;
|
return false;
|
||||||
|
@ -3846,7 +3850,7 @@ static int32_t handleExprInQueryCond(SSqlCmd* pCmd, SQueryInfo* pQueryInfo, tSql
|
||||||
taosArrayPush((*rightNode)->tsJoin, &leftIdx);
|
taosArrayPush((*rightNode)->tsJoin, &leftIdx);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* to release expression, e.g., m1.ts = m2.ts,
|
* To release expression, e.g., m1.ts = m2.ts,
|
||||||
* since this expression is used to set the join query type
|
* since this expression is used to set the join query type
|
||||||
*/
|
*/
|
||||||
tSqlExprDestroy(*pExpr);
|
tSqlExprDestroy(*pExpr);
|
||||||
|
|
|
@ -26,6 +26,12 @@ typedef struct SFillEssInfo {
|
||||||
int64_t *val; // fill value
|
int64_t *val; // fill value
|
||||||
} SFillEssInfo;
|
} SFillEssInfo;
|
||||||
|
|
||||||
|
typedef struct SJoinCond {
|
||||||
|
bool tagExists; // denote if tag condition exists or not
|
||||||
|
SColumn *tagCond[2];
|
||||||
|
SColumn *colCond[2];
|
||||||
|
} SJoinCond;
|
||||||
|
|
||||||
static SQueryNode* createQueryNode(int32_t type, const char* name, SQueryNode** prev,
|
static SQueryNode* createQueryNode(int32_t type, const char* name, SQueryNode** prev,
|
||||||
int32_t numOfPrev, SExprInfo** pExpr, int32_t numOfOutput, SQueryTableInfo* pTableInfo,
|
int32_t numOfPrev, SExprInfo** pExpr, int32_t numOfOutput, SQueryTableInfo* pTableInfo,
|
||||||
void* pExtInfo) {
|
void* pExtInfo) {
|
||||||
|
@ -92,8 +98,8 @@ static SQueryNode* createQueryNode(int32_t type, const char* name, SQueryNode**
|
||||||
return pNode;
|
return pNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SQueryNode* doAddTableColumnNode(SQueryInfo* pQueryInfo, STableMetaInfo* pTableMetaInfo,
|
static SQueryNode* doAddTableColumnNode(SQueryInfo* pQueryInfo, STableMetaInfo* pTableMetaInfo, SQueryTableInfo* info,
|
||||||
SQueryTableInfo* info, SArray* pExprs, SArray* tableCols) {
|
SArray* pExprs, SArray* tableCols) {
|
||||||
if (pQueryInfo->onlyTagQuery) {
|
if (pQueryInfo->onlyTagQuery) {
|
||||||
int32_t num = taosArrayGetSize(pExprs);
|
int32_t num = taosArrayGetSize(pExprs);
|
||||||
SQueryNode* pNode = createQueryNode(QNODE_TAGSCAN, "TableTagScan", NULL, 0, pExprs->pData, num, info, NULL);
|
SQueryNode* pNode = createQueryNode(QNODE_TAGSCAN, "TableTagScan", NULL, 0, pExprs->pData, num, info, NULL);
|
||||||
|
@ -232,28 +238,12 @@ SArray* createQueryPlanImpl(SQueryInfo* pQueryInfo) {
|
||||||
tNameExtractFullName(&pTableMetaInfo->name, name);
|
tNameExtractFullName(&pTableMetaInfo->name, name);
|
||||||
SQueryTableInfo info = {.tableName = strdup(name), .id = pTableMetaInfo->pTableMeta->id,};
|
SQueryTableInfo info = {.tableName = strdup(name), .id = pTableMetaInfo->pTableMeta->id,};
|
||||||
|
|
||||||
// 3. add the join columns (the tags and the primary timestamp column)
|
// 3. get the required table column list
|
||||||
tscInsertPrimaryTsSourceColumn(pQueryInfo, info.id.uid);
|
|
||||||
|
|
||||||
SArray* tableColumnList = taosArrayInit(4, sizeof(SColumn));
|
SArray* tableColumnList = taosArrayInit(4, sizeof(SColumn));
|
||||||
tscColumnListCopy(tableColumnList, pQueryInfo->colList, uid);
|
tscColumnListCopy(tableColumnList, pQueryInfo->colList, uid);
|
||||||
|
|
||||||
// TODO add the tag column into the required column list
|
|
||||||
if (UTIL_TABLE_IS_SUPER_TABLE(pTableMetaInfo)) {
|
|
||||||
int16_t tagColId = tscGetJoinTagColIdByUid(&pQueryInfo->tagCond, info.id.uid);
|
|
||||||
SSchema* s = tscGetColumnSchemaById(pTableMetaInfo->pTableMeta, tagColId);
|
|
||||||
|
|
||||||
SColumn* col = calloc(1, sizeof(SColumn));
|
|
||||||
col->tableUid = info.id.uid;
|
|
||||||
col->info.colId = tagColId;
|
|
||||||
col->info.type = s->type;
|
|
||||||
col->info.bytes = s->bytes;
|
|
||||||
taosArrayPush(pQueryInfo->colList, &col);
|
|
||||||
}
|
|
||||||
|
|
||||||
// 4. add the projection query node
|
// 4. add the projection query node
|
||||||
SQueryNode* pNode = doAddTableColumnNode(pQueryInfo, pTableMetaInfo, &info, exprList, tableColumnList);
|
SQueryNode* pNode = doAddTableColumnNode(pQueryInfo, pTableMetaInfo, &info, exprList, tableColumnList);
|
||||||
|
|
||||||
taosArrayPush(upstream, &pNode);
|
taosArrayPush(upstream, &pNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -497,7 +487,7 @@ static int32_t doPrintPlan(char* buf, SQueryNode* pQueryNode, int32_t level, int
|
||||||
|
|
||||||
case QNODE_JOIN: {
|
case QNODE_JOIN: {
|
||||||
// print join condition
|
// print join condition
|
||||||
len1 = sprintf(buf + len, "\n");
|
len1 = sprintf(buf + len, ")\n");
|
||||||
len += len1;
|
len += len1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -229,7 +229,6 @@ tSqlExpr *tSqlExprCreate(tSqlExpr *pLeft, tSqlExpr *pRight, int32_t optrType) {
|
||||||
pExpr->flags &= ~(1 << EXPR_FLAG_TS_ERROR);
|
pExpr->flags &= ~(1 << EXPR_FLAG_TS_ERROR);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
switch (optrType) {
|
switch (optrType) {
|
||||||
case TK_PLUS: {
|
case TK_PLUS: {
|
||||||
pExpr->value.i64 = pLeft->value.i64 + pRight->value.i64;
|
pExpr->value.i64 = pLeft->value.i64 + pRight->value.i64;
|
||||||
|
|
Loading…
Reference in New Issue