Merge pull request #11296 from taosdata/feature/3.0_wxy
sort plan bugfix
This commit is contained in:
commit
9ef7db3964
|
@ -173,50 +173,50 @@
|
||||||
#define TK_SPLIT 155
|
#define TK_SPLIT 155
|
||||||
#define TK_SYNCDB 156
|
#define TK_SYNCDB 156
|
||||||
#define TK_NULL 157
|
#define TK_NULL 157
|
||||||
#define TK_NOW 158
|
#define TK_FIRST 158
|
||||||
#define TK_ROWTS 159
|
#define TK_LAST 159
|
||||||
#define TK_TBNAME 160
|
#define TK_NOW 160
|
||||||
#define TK_QSTARTTS 161
|
#define TK_ROWTS 161
|
||||||
#define TK_QENDTS 162
|
#define TK_TBNAME 162
|
||||||
#define TK_WSTARTTS 163
|
#define TK_QSTARTTS 163
|
||||||
#define TK_WENDTS 164
|
#define TK_QENDTS 164
|
||||||
#define TK_WDURATION 165
|
#define TK_WSTARTTS 165
|
||||||
#define TK_BETWEEN 166
|
#define TK_WENDTS 166
|
||||||
#define TK_IS 167
|
#define TK_WDURATION 167
|
||||||
#define TK_NK_LT 168
|
#define TK_BETWEEN 168
|
||||||
#define TK_NK_GT 169
|
#define TK_IS 169
|
||||||
#define TK_NK_LE 170
|
#define TK_NK_LT 170
|
||||||
#define TK_NK_GE 171
|
#define TK_NK_GT 171
|
||||||
#define TK_NK_NE 172
|
#define TK_NK_LE 172
|
||||||
#define TK_MATCH 173
|
#define TK_NK_GE 173
|
||||||
#define TK_NMATCH 174
|
#define TK_NK_NE 174
|
||||||
#define TK_JOIN 175
|
#define TK_MATCH 175
|
||||||
#define TK_INNER 176
|
#define TK_NMATCH 176
|
||||||
#define TK_SELECT 177
|
#define TK_JOIN 177
|
||||||
#define TK_DISTINCT 178
|
#define TK_INNER 178
|
||||||
#define TK_WHERE 179
|
#define TK_SELECT 179
|
||||||
#define TK_PARTITION 180
|
#define TK_DISTINCT 180
|
||||||
#define TK_BY 181
|
#define TK_WHERE 181
|
||||||
#define TK_SESSION 182
|
#define TK_PARTITION 182
|
||||||
#define TK_STATE_WINDOW 183
|
#define TK_BY 183
|
||||||
#define TK_SLIDING 184
|
#define TK_SESSION 184
|
||||||
#define TK_FILL 185
|
#define TK_STATE_WINDOW 185
|
||||||
#define TK_VALUE 186
|
#define TK_SLIDING 186
|
||||||
#define TK_NONE 187
|
#define TK_FILL 187
|
||||||
#define TK_PREV 188
|
#define TK_VALUE 188
|
||||||
#define TK_LINEAR 189
|
#define TK_NONE 189
|
||||||
#define TK_NEXT 190
|
#define TK_PREV 190
|
||||||
#define TK_GROUP 191
|
#define TK_LINEAR 191
|
||||||
#define TK_HAVING 192
|
#define TK_NEXT 192
|
||||||
#define TK_ORDER 193
|
#define TK_GROUP 193
|
||||||
#define TK_SLIMIT 194
|
#define TK_HAVING 194
|
||||||
#define TK_SOFFSET 195
|
#define TK_ORDER 195
|
||||||
#define TK_LIMIT 196
|
#define TK_SLIMIT 196
|
||||||
#define TK_OFFSET 197
|
#define TK_SOFFSET 197
|
||||||
#define TK_ASC 198
|
#define TK_LIMIT 198
|
||||||
#define TK_NULLS 199
|
#define TK_OFFSET 199
|
||||||
#define TK_FIRST 200
|
#define TK_ASC 200
|
||||||
#define TK_LAST 201
|
#define TK_NULLS 201
|
||||||
|
|
||||||
#define TK_NK_SPACE 300
|
#define TK_NK_SPACE 300
|
||||||
#define TK_NK_COMMENT 301
|
#define TK_NK_COMMENT 301
|
||||||
|
|
|
@ -286,12 +286,14 @@ typedef struct SSortPhysiNode {
|
||||||
SPhysiNode node;
|
SPhysiNode node;
|
||||||
SNodeList* pExprs; // these are expression list of order_by_clause and parameter expression of aggregate function
|
SNodeList* pExprs; // these are expression list of order_by_clause and parameter expression of aggregate function
|
||||||
SNodeList* pSortKeys; // element is SOrderByExprNode, and SOrderByExprNode::pExpr is SColumnNode
|
SNodeList* pSortKeys; // element is SOrderByExprNode, and SOrderByExprNode::pExpr is SColumnNode
|
||||||
|
SNodeList* pTargets;
|
||||||
} SSortPhysiNode;
|
} SSortPhysiNode;
|
||||||
|
|
||||||
typedef struct SPartitionPhysiNode {
|
typedef struct SPartitionPhysiNode {
|
||||||
SPhysiNode node;
|
SPhysiNode node;
|
||||||
SNodeList* pExprs; // these are expression list of partition_by_clause
|
SNodeList* pExprs; // these are expression list of partition_by_clause
|
||||||
SNodeList* pPartitionKeys;
|
SNodeList* pPartitionKeys;
|
||||||
|
SNodeList* pTargets;
|
||||||
} SPartitionPhysiNode;
|
} SPartitionPhysiNode;
|
||||||
|
|
||||||
typedef struct SDataSinkNode {
|
typedef struct SDataSinkNode {
|
||||||
|
|
|
@ -258,6 +258,7 @@ typedef enum ESqlClause {
|
||||||
SQL_CLAUSE_WINDOW,
|
SQL_CLAUSE_WINDOW,
|
||||||
SQL_CLAUSE_GROUP_BY,
|
SQL_CLAUSE_GROUP_BY,
|
||||||
SQL_CLAUSE_HAVING,
|
SQL_CLAUSE_HAVING,
|
||||||
|
SQL_CLAUSE_DISTINCT,
|
||||||
SQL_CLAUSE_SELECT,
|
SQL_CLAUSE_SELECT,
|
||||||
SQL_CLAUSE_ORDER_BY
|
SQL_CLAUSE_ORDER_BY
|
||||||
} ESqlClause;
|
} ESqlClause;
|
||||||
|
|
|
@ -994,6 +994,7 @@ static int32_t jsonToPhysiExchangeNode(const SJson* pJson, void* pObj) {
|
||||||
|
|
||||||
static const char* jkSortPhysiPlanExprs = "Exprs";
|
static const char* jkSortPhysiPlanExprs = "Exprs";
|
||||||
static const char* jkSortPhysiPlanSortKeys = "SortKeys";
|
static const char* jkSortPhysiPlanSortKeys = "SortKeys";
|
||||||
|
static const char* jkSortPhysiPlanTargets = "Targets";
|
||||||
|
|
||||||
static int32_t physiSortNodeToJson(const void* pObj, SJson* pJson) {
|
static int32_t physiSortNodeToJson(const void* pObj, SJson* pJson) {
|
||||||
const SSortPhysiNode* pNode = (const SSortPhysiNode*)pObj;
|
const SSortPhysiNode* pNode = (const SSortPhysiNode*)pObj;
|
||||||
|
@ -1005,6 +1006,9 @@ static int32_t physiSortNodeToJson(const void* pObj, SJson* pJson) {
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = nodeListToJson(pJson, jkSortPhysiPlanSortKeys, pNode->pSortKeys);
|
code = nodeListToJson(pJson, jkSortPhysiPlanSortKeys, pNode->pSortKeys);
|
||||||
}
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = nodeListToJson(pJson, jkSortPhysiPlanTargets, pNode->pTargets);
|
||||||
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -1019,6 +1023,9 @@ static int32_t jsonToPhysiSortNode(const SJson* pJson, void* pObj) {
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = jsonToNodeList(pJson, jkSortPhysiPlanSortKeys, &pNode->pSortKeys);
|
code = jsonToNodeList(pJson, jkSortPhysiPlanSortKeys, &pNode->pSortKeys);
|
||||||
}
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = jsonToNodeList(pJson, jkSortPhysiPlanTargets, &pNode->pTargets);
|
||||||
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -1177,6 +1184,7 @@ static int32_t jsonToPhysiStateWindowNode(const SJson* pJson, void* pObj) {
|
||||||
|
|
||||||
static const char* jkPartitionPhysiPlanExprs = "Exprs";
|
static const char* jkPartitionPhysiPlanExprs = "Exprs";
|
||||||
static const char* jkPartitionPhysiPlanPartitionKeys = "PartitionKeys";
|
static const char* jkPartitionPhysiPlanPartitionKeys = "PartitionKeys";
|
||||||
|
static const char* jkPartitionPhysiPlanTargets = "Targets";
|
||||||
|
|
||||||
static int32_t physiPartitionNodeToJson(const void* pObj, SJson* pJson) {
|
static int32_t physiPartitionNodeToJson(const void* pObj, SJson* pJson) {
|
||||||
const SPartitionPhysiNode* pNode = (const SPartitionPhysiNode*)pObj;
|
const SPartitionPhysiNode* pNode = (const SPartitionPhysiNode*)pObj;
|
||||||
|
@ -1188,6 +1196,9 @@ static int32_t physiPartitionNodeToJson(const void* pObj, SJson* pJson) {
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = nodeListToJson(pJson, jkPartitionPhysiPlanPartitionKeys, pNode->pPartitionKeys);
|
code = nodeListToJson(pJson, jkPartitionPhysiPlanPartitionKeys, pNode->pPartitionKeys);
|
||||||
}
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = nodeListToJson(pJson, jkPartitionPhysiPlanTargets, pNode->pTargets);
|
||||||
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
@ -1202,6 +1213,9 @@ static int32_t jsonToPhysiPartitionNode(const SJson* pJson, void* pObj) {
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = jsonToNodeList(pJson, jkPartitionPhysiPlanPartitionKeys, &pNode->pPartitionKeys);
|
code = jsonToNodeList(pJson, jkPartitionPhysiPlanPartitionKeys, &pNode->pPartitionKeys);
|
||||||
}
|
}
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = jsonToNodeList(pJson, jkPartitionPhysiPlanTargets, &pNode->pTargets);
|
||||||
|
}
|
||||||
|
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
|
|
|
@ -301,9 +301,10 @@ void nodesWalkSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeWalker wa
|
||||||
case SQL_CLAUSE_GROUP_BY:
|
case SQL_CLAUSE_GROUP_BY:
|
||||||
nodesWalkExpr(pSelect->pHaving, walker, pContext);
|
nodesWalkExpr(pSelect->pHaving, walker, pContext);
|
||||||
case SQL_CLAUSE_HAVING:
|
case SQL_CLAUSE_HAVING:
|
||||||
nodesWalkExprs(pSelect->pProjectionList, walker, pContext);
|
case SQL_CLAUSE_DISTINCT:
|
||||||
case SQL_CLAUSE_SELECT:
|
|
||||||
nodesWalkExprs(pSelect->pOrderByList, walker, pContext);
|
nodesWalkExprs(pSelect->pOrderByList, walker, pContext);
|
||||||
|
case SQL_CLAUSE_ORDER_BY:
|
||||||
|
nodesWalkExprs(pSelect->pProjectionList, walker, pContext);
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -329,9 +330,10 @@ void nodesRewriteSelectStmt(SSelectStmt* pSelect, ESqlClause clause, FNodeRewrit
|
||||||
case SQL_CLAUSE_GROUP_BY:
|
case SQL_CLAUSE_GROUP_BY:
|
||||||
nodesRewriteExpr(&(pSelect->pHaving), rewriter, pContext);
|
nodesRewriteExpr(&(pSelect->pHaving), rewriter, pContext);
|
||||||
case SQL_CLAUSE_HAVING:
|
case SQL_CLAUSE_HAVING:
|
||||||
nodesRewriteExprs(pSelect->pProjectionList, rewriter, pContext);
|
case SQL_CLAUSE_DISTINCT:
|
||||||
case SQL_CLAUSE_SELECT:
|
|
||||||
nodesRewriteExprs(pSelect->pOrderByList, rewriter, pContext);
|
nodesRewriteExprs(pSelect->pOrderByList, rewriter, pContext);
|
||||||
|
case SQL_CLAUSE_ORDER_BY:
|
||||||
|
nodesRewriteExprs(pSelect->pProjectionList, rewriter, pContext);
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -486,6 +486,8 @@ column_name(A) ::= NK_ID(B).
|
||||||
%type function_name { SToken }
|
%type function_name { SToken }
|
||||||
%destructor function_name { }
|
%destructor function_name { }
|
||||||
function_name(A) ::= NK_ID(B). { A = B; }
|
function_name(A) ::= NK_ID(B). { A = B; }
|
||||||
|
function_name(A) ::= FIRST(B). { A = B; }
|
||||||
|
function_name(A) ::= LAST(B). { A = B; }
|
||||||
|
|
||||||
%type table_alias { SToken }
|
%type table_alias { SToken }
|
||||||
%destructor table_alias { }
|
%destructor table_alias { }
|
||||||
|
|
|
@ -72,6 +72,7 @@ static SKeyword keywordTable[] = {
|
||||||
{"EXPLAIN", TK_EXPLAIN},
|
{"EXPLAIN", TK_EXPLAIN},
|
||||||
{"FILE_FACTOR", TK_FILE_FACTOR},
|
{"FILE_FACTOR", TK_FILE_FACTOR},
|
||||||
{"FILL", TK_FILL},
|
{"FILL", TK_FILL},
|
||||||
|
{"FIRST", TK_FIRST},
|
||||||
{"FLOAT", TK_FLOAT},
|
{"FLOAT", TK_FLOAT},
|
||||||
{"FROM", TK_FROM},
|
{"FROM", TK_FROM},
|
||||||
{"FSYNC", TK_FSYNC},
|
{"FSYNC", TK_FSYNC},
|
||||||
|
@ -95,6 +96,7 @@ static SKeyword keywordTable[] = {
|
||||||
{"JSON", TK_JSON},
|
{"JSON", TK_JSON},
|
||||||
{"KEEP", TK_KEEP},
|
{"KEEP", TK_KEEP},
|
||||||
{"KILL", TK_KILL},
|
{"KILL", TK_KILL},
|
||||||
|
{"LAST", TK_LAST},
|
||||||
{"LICENCE", TK_LICENCE},
|
{"LICENCE", TK_LICENCE},
|
||||||
{"LIKE", TK_LIKE},
|
{"LIKE", TK_LIKE},
|
||||||
{"LIMIT", TK_LIMIT},
|
{"LIMIT", TK_LIMIT},
|
||||||
|
@ -113,6 +115,7 @@ static SKeyword keywordTable[] = {
|
||||||
{"NOT", TK_NOT},
|
{"NOT", TK_NOT},
|
||||||
{"NOW", TK_NOW},
|
{"NOW", TK_NOW},
|
||||||
{"NULL", TK_NULL},
|
{"NULL", TK_NULL},
|
||||||
|
{"NULLS", TK_NULLS},
|
||||||
{"OFFSET", TK_OFFSET},
|
{"OFFSET", TK_OFFSET},
|
||||||
{"ON", TK_ON},
|
{"ON", TK_ON},
|
||||||
{"OR", TK_OR},
|
{"OR", TK_OR},
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -701,7 +701,7 @@ static int32_t createDistinctLogicNode(SLogicPlanContext* pCxt, SSelectStmt* pSe
|
||||||
|
|
||||||
// rewrite the expression in subsequent clauses
|
// rewrite the expression in subsequent clauses
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = rewriteExpr(pAgg->pGroupKeys, pSelect, SQL_CLAUSE_SELECT);
|
code = rewriteExpr(pAgg->pGroupKeys, pSelect, SQL_CLAUSE_DISTINCT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the output
|
// set the output
|
||||||
|
|
|
@ -928,8 +928,12 @@ static int32_t createSortPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChildren
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pSortKeys, &pSort->pSortKeys);
|
code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pSortKeys, &pSort->pSortKeys);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pSortLogicNode->node.pTargets, &pSort->pTargets);
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = addDataBlockSlots(pCxt, pSort->pSortKeys, pSort->node.pOutputDataBlockDesc);
|
code = addDataBlockSlots(pCxt, pSort->pTargets, pSort->node.pOutputDataBlockDesc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -963,8 +967,12 @@ static int32_t createPartitionPhysiNode(SPhysiPlanContext* pCxt, SNodeList* pChi
|
||||||
|
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pPartitionKeys, &pPart->pPartitionKeys);
|
code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pPartitionKeys, &pPart->pPartitionKeys);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
|
code = setListSlotId(pCxt, pChildTupe->dataBlockId, -1, pPartLogicNode->node.pTargets, &pPart->pTargets);
|
||||||
if (TSDB_CODE_SUCCESS == code) {
|
if (TSDB_CODE_SUCCESS == code) {
|
||||||
code = addDataBlockSlots(pCxt, pPart->pPartitionKeys, pPart->node.pOutputDataBlockDesc);
|
code = addDataBlockSlots(pCxt, pPart->pTargets, pPart->node.pOutputDataBlockDesc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -254,6 +254,9 @@ TEST_F(PlannerTest, orderBy) {
|
||||||
|
|
||||||
bind("SELECT * FROM t1 order by c1 + 10, c2");
|
bind("SELECT * FROM t1 order by c1 + 10, c2");
|
||||||
ASSERT_TRUE(run());
|
ASSERT_TRUE(run());
|
||||||
|
|
||||||
|
bind("SELECT * FROM t1 order by c1 desc nulls first");
|
||||||
|
ASSERT_TRUE(run());
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(PlannerTest, distinct) {
|
TEST_F(PlannerTest, distinct) {
|
||||||
|
|
Loading…
Reference in New Issue