fix: execution plan problem in the mode of using qnode as much as possible
This commit is contained in:
parent
f3bf757282
commit
d223a6624b
|
@ -1333,6 +1333,9 @@ static int32_t rewriteSystemInfoFuncImpl(STranslateContext* pCxt, char* pLiteral
|
||||||
pVal->isNull = true;
|
pVal->isNull = true;
|
||||||
} else {
|
} else {
|
||||||
pVal->literal = pLiteral;
|
pVal->literal = pLiteral;
|
||||||
|
if (IS_VAR_DATA_TYPE(pVal->node.resType.type)) {
|
||||||
|
pVal->node.resType.bytes = strlen(pLiteral);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (DEAL_RES_ERROR != translateValue(pCxt, pVal)) {
|
if (DEAL_RES_ERROR != translateValue(pCxt, pVal)) {
|
||||||
*pNode = (SNode*)pVal;
|
*pNode = (SNode*)pVal;
|
||||||
|
|
|
@ -236,7 +236,6 @@ int32_t buildSyntaxErrMsg(SMsgBuf* pBuf, const char* additionalInfo, const char*
|
||||||
|
|
||||||
const char* prefix = "syntax error";
|
const char* prefix = "syntax error";
|
||||||
if (sourceStr == NULL) {
|
if (sourceStr == NULL) {
|
||||||
assert(additionalInfo != NULL);
|
|
||||||
snprintf(pBuf->buf, pBuf->len, msgFormat1, additionalInfo);
|
snprintf(pBuf->buf, pBuf->len, msgFormat1, additionalInfo);
|
||||||
return TSDB_CODE_TSC_SQL_SYNTAX_ERROR;
|
return TSDB_CODE_TSC_SQL_SYNTAX_ERROR;
|
||||||
}
|
}
|
||||||
|
@ -254,40 +253,25 @@ int32_t buildSyntaxErrMsg(SMsgBuf* pBuf, const char* additionalInfo, const char*
|
||||||
return TSDB_CODE_TSC_SQL_SYNTAX_ERROR;
|
return TSDB_CODE_TSC_SQL_SYNTAX_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
SSchema* getTableColumnSchema(const STableMeta* pTableMeta) {
|
SSchema* getTableColumnSchema(const STableMeta* pTableMeta) { return (SSchema*)pTableMeta->schema; }
|
||||||
assert(pTableMeta != NULL);
|
|
||||||
return (SSchema*)pTableMeta->schema;
|
|
||||||
}
|
|
||||||
|
|
||||||
static SSchema* getOneColumnSchema(const STableMeta* pTableMeta, int32_t colIndex) {
|
static SSchema* getOneColumnSchema(const STableMeta* pTableMeta, int32_t colIndex) {
|
||||||
assert(pTableMeta != NULL && pTableMeta->schema != NULL && colIndex >= 0 &&
|
|
||||||
colIndex < (getNumOfColumns(pTableMeta) + getNumOfTags(pTableMeta)));
|
|
||||||
|
|
||||||
SSchema* pSchema = (SSchema*)pTableMeta->schema;
|
SSchema* pSchema = (SSchema*)pTableMeta->schema;
|
||||||
return &pSchema[colIndex];
|
return &pSchema[colIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
SSchema* getTableTagSchema(const STableMeta* pTableMeta) {
|
SSchema* getTableTagSchema(const STableMeta* pTableMeta) {
|
||||||
assert(pTableMeta != NULL &&
|
|
||||||
(pTableMeta->tableType == TSDB_SUPER_TABLE || pTableMeta->tableType == TSDB_CHILD_TABLE));
|
|
||||||
return getOneColumnSchema(pTableMeta, getTableInfo(pTableMeta).numOfColumns);
|
return getOneColumnSchema(pTableMeta, getTableInfo(pTableMeta).numOfColumns);
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t getNumOfColumns(const STableMeta* pTableMeta) {
|
int32_t getNumOfColumns(const STableMeta* pTableMeta) {
|
||||||
assert(pTableMeta != NULL);
|
|
||||||
// table created according to super table, use data from super table
|
// table created according to super table, use data from super table
|
||||||
return getTableInfo(pTableMeta).numOfColumns;
|
return getTableInfo(pTableMeta).numOfColumns;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t getNumOfTags(const STableMeta* pTableMeta) {
|
int32_t getNumOfTags(const STableMeta* pTableMeta) { return getTableInfo(pTableMeta).numOfTags; }
|
||||||
assert(pTableMeta != NULL);
|
|
||||||
return getTableInfo(pTableMeta).numOfTags;
|
|
||||||
}
|
|
||||||
|
|
||||||
STableComInfo getTableInfo(const STableMeta* pTableMeta) {
|
STableComInfo getTableInfo(const STableMeta* pTableMeta) { return pTableMeta->tableInfo; }
|
||||||
assert(pTableMeta != NULL);
|
|
||||||
return pTableMeta->tableInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
STableMeta* tableMetaDup(const STableMeta* pTableMeta) {
|
STableMeta* tableMetaDup(const STableMeta* pTableMeta) {
|
||||||
size_t size = TABLE_META_SIZE(pTableMeta);
|
size_t size = TABLE_META_SIZE(pTableMeta);
|
||||||
|
|
|
@ -75,6 +75,11 @@ static SLogicNode* optFindPossibleNode(SLogicNode* pNode, FMayBeOptimized func)
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void optResetParent(SLogicNode* pNode) {
|
||||||
|
SNode* pChild = NULL;
|
||||||
|
FOREACH(pChild, pNode->pChildren) { ((SLogicNode*)pChild)->pParent = pNode; }
|
||||||
|
}
|
||||||
|
|
||||||
EDealRes scanPathOptHaveNormalColImpl(SNode* pNode, void* pContext) {
|
EDealRes scanPathOptHaveNormalColImpl(SNode* pNode, void* pContext) {
|
||||||
if (QUERY_NODE_COLUMN == nodeType(pNode)) {
|
if (QUERY_NODE_COLUMN == nodeType(pNode)) {
|
||||||
// *((bool*)pContext) = (COLUMN_TYPE_TAG != ((SColumnNode*)pNode)->colType);
|
// *((bool*)pContext) = (COLUMN_TYPE_TAG != ((SColumnNode*)pNode)->colType);
|
||||||
|
@ -1460,6 +1465,7 @@ static int32_t rewriteTailOptCreateSort(SIndefRowsFuncLogicNode* pIndef, SLogicN
|
||||||
|
|
||||||
pSort->groupSort = rewriteTailOptNeedGroupSort(pIndef);
|
pSort->groupSort = rewriteTailOptNeedGroupSort(pIndef);
|
||||||
TSWAP(pSort->node.pChildren, pIndef->node.pChildren);
|
TSWAP(pSort->node.pChildren, pIndef->node.pChildren);
|
||||||
|
optResetParent((SLogicNode*)pSort);
|
||||||
pSort->node.precision = pIndef->node.precision;
|
pSort->node.precision = pIndef->node.precision;
|
||||||
|
|
||||||
SFunctionNode* pTail = NULL;
|
SFunctionNode* pTail = NULL;
|
||||||
|
@ -1667,6 +1673,7 @@ static int32_t rewriteUniqueOptCreateAgg(SIndefRowsFuncLogicNode* pIndef, SLogic
|
||||||
}
|
}
|
||||||
|
|
||||||
TSWAP(pAgg->node.pChildren, pIndef->node.pChildren);
|
TSWAP(pAgg->node.pChildren, pIndef->node.pChildren);
|
||||||
|
optResetParent((SLogicNode*)pAgg);
|
||||||
pAgg->node.precision = pIndef->node.precision;
|
pAgg->node.precision = pIndef->node.precision;
|
||||||
|
|
||||||
int32_t code = TSDB_CODE_SUCCESS;
|
int32_t code = TSDB_CODE_SUCCESS;
|
||||||
|
|
|
@ -1203,7 +1203,8 @@ typedef struct SQnodeSplitInfo {
|
||||||
|
|
||||||
static bool qndSplFindSplitNode(SSplitContext* pCxt, SLogicSubplan* pSubplan, SLogicNode* pNode,
|
static bool qndSplFindSplitNode(SSplitContext* pCxt, SLogicSubplan* pSubplan, SLogicNode* pNode,
|
||||||
SQnodeSplitInfo* pInfo) {
|
SQnodeSplitInfo* pInfo) {
|
||||||
if (QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pNode) && NULL != pNode->pParent) {
|
if (QUERY_NODE_LOGIC_PLAN_SCAN == nodeType(pNode) && NULL != pNode->pParent &&
|
||||||
|
((SScanLogicNode*)pNode)->scanSeq[0] < 1 && ((SScanLogicNode*)pNode)->scanSeq[1] < 1) {
|
||||||
pInfo->pSplitNode = pNode;
|
pInfo->pSplitNode = pNode;
|
||||||
pInfo->pSubplan = pSubplan;
|
pInfo->pSubplan = pSubplan;
|
||||||
return true;
|
return true;
|
||||||
|
|
|
@ -81,6 +81,8 @@ TEST_F(PlanBasicTest, tailFunc) {
|
||||||
run("SELECT TAIL(c2 + 10, 10, 80) FROM t1 WHERE c1 > 10 PARTITION BY c1 LIMIT 5");
|
run("SELECT TAIL(c2 + 10, 10, 80) FROM t1 WHERE c1 > 10 PARTITION BY c1 LIMIT 5");
|
||||||
|
|
||||||
run("SELECT TAIL(c1, 2, 1) FROM st1s1 UNION ALL SELECT c1 FROM st1s2");
|
run("SELECT TAIL(c1, 2, 1) FROM st1s1 UNION ALL SELECT c1 FROM st1s2");
|
||||||
|
|
||||||
|
run("SELECT TAIL(c1, 1) FROM st2 WHERE jtag->'tag1' > 10");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(PlanBasicTest, interpFunc) {
|
TEST_F(PlanBasicTest, interpFunc) {
|
||||||
|
|
|
@ -91,10 +91,3 @@ TEST_F(PlanOtherTest, delete) {
|
||||||
|
|
||||||
run("DELETE FROM st1 WHERE ts > now - 2d and ts < now - 1d AND tag1 = 10");
|
run("DELETE FROM st1 WHERE ts > now - 2d and ts < now - 1d AND tag1 = 10");
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(PlanOtherTest, queryPolicy) {
|
|
||||||
useDb("root", "test");
|
|
||||||
|
|
||||||
tsQueryPolicy = QUERY_POLICY_QNODE;
|
|
||||||
run("SELECT COUNT(*) FROM st1");
|
|
||||||
}
|
|
||||||
|
|
|
@ -78,6 +78,7 @@ static void parseArg(int argc, char* argv[]) {
|
||||||
{"skipSql", required_argument, NULL, 's'},
|
{"skipSql", required_argument, NULL, 's'},
|
||||||
{"limitSql", required_argument, NULL, 'i'},
|
{"limitSql", required_argument, NULL, 'i'},
|
||||||
{"log", required_argument, NULL, 'l'},
|
{"log", required_argument, NULL, 'l'},
|
||||||
|
{"queryPolicy", required_argument, NULL, 'q'},
|
||||||
{0, 0, 0, 0}
|
{0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
@ -95,6 +96,9 @@ static void parseArg(int argc, char* argv[]) {
|
||||||
case 'l':
|
case 'l':
|
||||||
setLogLevel(optarg);
|
setLogLevel(optarg);
|
||||||
break;
|
break;
|
||||||
|
case 'q':
|
||||||
|
setQueryPolicy(optarg);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#include "mockCatalogService.h"
|
#include "mockCatalogService.h"
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
#include "planInt.h"
|
#include "planInt.h"
|
||||||
|
#include "tglobal.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace testing;
|
using namespace testing;
|
||||||
|
@ -53,6 +54,7 @@ DumpModule g_dumpModule = DUMP_MODULE_NOTHING;
|
||||||
int32_t g_skipSql = 0;
|
int32_t g_skipSql = 0;
|
||||||
int32_t g_limitSql = 0;
|
int32_t g_limitSql = 0;
|
||||||
int32_t g_logLevel = 131;
|
int32_t g_logLevel = 131;
|
||||||
|
int32_t g_queryPolicy = QUERY_POLICY_VNODE;
|
||||||
|
|
||||||
void setDumpModule(const char* pModule) {
|
void setDumpModule(const char* pModule) {
|
||||||
if (NULL == pModule) {
|
if (NULL == pModule) {
|
||||||
|
@ -79,6 +81,7 @@ void setDumpModule(const char* pModule) {
|
||||||
void setSkipSqlNum(const char* pNum) { g_skipSql = stoi(pNum); }
|
void setSkipSqlNum(const char* pNum) { g_skipSql = stoi(pNum); }
|
||||||
void setLimitSqlNum(const char* pNum) { g_limitSql = stoi(pNum); }
|
void setLimitSqlNum(const char* pNum) { g_limitSql = stoi(pNum); }
|
||||||
void setLogLevel(const char* pLogLevel) { g_logLevel = stoi(pLogLevel); }
|
void setLogLevel(const char* pLogLevel) { g_logLevel = stoi(pLogLevel); }
|
||||||
|
void setQueryPolicy(const char* pQueryPolicy) { g_queryPolicy = stoi(pQueryPolicy); }
|
||||||
|
|
||||||
int32_t getLogLevel() { return g_logLevel; }
|
int32_t getLogLevel() { return g_logLevel; }
|
||||||
|
|
||||||
|
@ -105,7 +108,23 @@ class PlannerTestBaseImpl {
|
||||||
}
|
}
|
||||||
++sqlNum_;
|
++sqlNum_;
|
||||||
|
|
||||||
|
switch (g_queryPolicy) {
|
||||||
|
case QUERY_POLICY_VNODE:
|
||||||
|
case QUERY_POLICY_HYBRID:
|
||||||
|
case QUERY_POLICY_QNODE:
|
||||||
|
runImpl(sql, g_queryPolicy);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
runImpl(sql, QUERY_POLICY_VNODE);
|
||||||
|
runImpl(sql, QUERY_POLICY_HYBRID);
|
||||||
|
runImpl(sql, QUERY_POLICY_QNODE);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void runImpl(const string& sql, int32_t queryPolicy) {
|
||||||
reset();
|
reset();
|
||||||
|
tsQueryPolicy = queryPolicy;
|
||||||
try {
|
try {
|
||||||
SQuery* pQuery = nullptr;
|
SQuery* pQuery = nullptr;
|
||||||
doParseSql(sql, &pQuery);
|
doParseSql(sql, &pQuery);
|
||||||
|
|
|
@ -45,6 +45,7 @@ extern void setDumpModule(const char* pModule);
|
||||||
extern void setSkipSqlNum(const char* pNum);
|
extern void setSkipSqlNum(const char* pNum);
|
||||||
extern void setLimitSqlNum(const char* pNum);
|
extern void setLimitSqlNum(const char* pNum);
|
||||||
extern void setLogLevel(const char* pLogLevel);
|
extern void setLogLevel(const char* pLogLevel);
|
||||||
|
extern void setQueryPolicy(const char* pQueryPolicy);
|
||||||
extern int32_t getLogLevel();
|
extern int32_t getLogLevel();
|
||||||
|
|
||||||
#endif // PLAN_TEST_UTIL_H
|
#endif // PLAN_TEST_UTIL_H
|
||||||
|
|
Loading…
Reference in New Issue