TD-12034 Physical plan code.

This commit is contained in:
Xiaoyu Wang 2021-12-14 07:37:54 -05:00
parent 33a13ff54c
commit 3936128742
4 changed files with 101 additions and 49 deletions

View File

@ -54,7 +54,6 @@ enum OPERATOR_TYPE_E {
};
struct SEpSet;
struct SQueryPlanNode;
struct SPhyNode;
struct SQueryStmtInfo;

View File

@ -25,18 +25,20 @@ extern "C" {
#include "planner.h"
#include "taosmsg.h"
enum LOGIC_PLAN_E {
LP_SCAN = 1,
LP_SESSION = 2,
LP_STATE = 3,
LP_INTERVAL = 4,
LP_FILL = 5,
LP_AGG = 6,
LP_JOIN = 7,
LP_PROJECT = 8,
LP_DISTINCT = 9,
LP_ORDER = 10
};
#define QNODE_TAGSCAN 1
#define QNODE_TABLESCAN 2
#define QNODE_PROJECT 3
#define QNODE_AGGREGATE 4
#define QNODE_GROUPBY 5
#define QNODE_LIMIT 6
#define QNODE_JOIN 7
#define QNODE_DISTINCT 8
#define QNODE_SORT 9
#define QNODE_UNION 10
#define QNODE_TIMEWINDOW 11
#define QNODE_SESSIONWINDOW 12
#define QNODE_STATEWINDOW 13
#define QNODE_FILL 14
typedef struct SQueryNodeBasicInfo {
int32_t type; // operator type
@ -64,10 +66,10 @@ typedef struct SQueryPlanNode {
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
// children operator to generated result for current node to process
// in case of join, multiple prev nodes exist.
SArray *pPrevNodes; // upstream nodes
struct SQueryPlanNode *nextNode;
SArray *pChildren; // upstream nodes
struct SQueryPlanNode *pParent;
} SQueryPlanNode;
typedef SSchema SSlotSchema;
@ -86,11 +88,13 @@ typedef struct SPhyNode {
// children plan to generated result for current node to process
// in case of join, multiple plan nodes exist.
SArray *pChildren;
struct SPhyNode *pParent;
} SPhyNode;
typedef struct SScanPhyNode {
SPhyNode node;
uint64_t uid; // unique id of the table
SPhyNode node;
STimeWindow window;
uint64_t uid; // unique id of the table
} SScanPhyNode;
typedef SScanPhyNode STagScanPhyNode;

View File

@ -15,20 +15,84 @@
#include "plannerInt.h"
// typedef struct SQueryPlanNode {
// void *pExtInfo; // additional information
// SArray *pPrevNodes; // children
// struct SQueryPlanNode *nextNode; // parent
// } SQueryPlanNode;
// typedef struct SSubplan {
// int32_t type; // QUERY_TYPE_MERGE|QUERY_TYPE_PARTIAL|QUERY_TYPE_SCAN
// SArray *pDatasource; // the datasource subplan,from which to fetch the result
// struct SPhyNode *pNode; // physical plan of current subplan
// } SSubplan;
// typedef struct SQueryDag {
// SArray **pSubplans;
// } SQueryDag;
// typedef struct SScanPhyNode {
// SPhyNode node;
// STimeWindow window;
// uint64_t uid; // unique id of the table
// } SScanPhyNode;
// typedef SScanPhyNode STagScanPhyNode;
void fillDataBlockSchema(SQueryPlanNode* pPlanNode, SDataBlockSchema* dataBlockSchema) {
dataBlockSchema->index = 0; // todo
SWAP(dataBlockSchema->pSchema, pPlanNode->pSchema, SSchema*);
dataBlockSchema->numOfCols = pPlanNode->numOfCols;
}
void fillPhyNode(SQueryPlanNode* pPlanNode, int32_t type, const char* name, SPhyNode* node) {
node->info.type = type;
node->info.name = name;
SWAP(node->pTargets, pPlanNode->pExpr, SArray*);
fillDataBlockSchema(pPlanNode, &(node->targetSchema));
}
SPhyNode* createTagScanNode(SQueryPlanNode* pPlanNode) {
STagScanPhyNode* node = calloc(1, sizeof(STagScanPhyNode));
fillPhyNode(pPlanNode, OP_TagScan, "TagScan", (SPhyNode*)node);
return (SPhyNode*)node;
}
SPhyNode* createScanNode(SQueryPlanNode* pPlanNode) {
return NULL;
STagScanPhyNode* node = calloc(1, sizeof(STagScanPhyNode));
fillPhyNode(pPlanNode, OP_TableScan, "SingleTableScan", (SPhyNode*)node);
return (SPhyNode*)node;
}
SPhyNode* createPhyNode(SQueryPlanNode* node) {
switch (node->info.type) {
case LP_SCAN:
return createScanNode(node);
SPhyNode* createPhyNode(SQueryPlanNode* pPlanNode) {
SPhyNode* node = NULL;
switch (pPlanNode->info.type) {
case QNODE_TAGSCAN:
node = createTagScanNode(pPlanNode);
break;
case QNODE_TABLESCAN:
node = createScanNode(pPlanNode);
break;
default:
assert(false);
}
return NULL;
if (pPlanNode->pChildren != NULL && taosArrayGetSize(pPlanNode->pChildren) > 0) {
node->pChildren = taosArrayInit(4, POINTER_BYTES);
size_t size = taosArrayGetSize(pPlanNode->pChildren);
for(int32_t i = 0; i < size; ++i) {
SPhyNode* child = createPhyNode(taosArrayGet(pPlanNode->pChildren, i));
child->pParent = node;
taosArrayPush(node->pChildren, &child);
}
}
return node;
}
SPhyNode* createSubplan(SQueryPlanNode* pSubquery) {
return NULL;
SSubplan* createSubplan(SQueryPlanNode* pSubquery) {
SSubplan* subplan = calloc(1, sizeof(SSubplan));
subplan->pNode = createPhyNode(pSubquery);
// todo
return subplan;
}
int32_t createDag(struct SQueryPlanNode* pQueryNode, struct SEpSet* pQnode, struct SQueryDag** pDag) {

View File

@ -18,21 +18,6 @@
#include "parser.h"
#include "plannerInt.h"
#define QNODE_TAGSCAN 1
#define QNODE_TABLESCAN 2
#define QNODE_PROJECT 3
#define QNODE_AGGREGATE 4
#define QNODE_GROUPBY 5
#define QNODE_LIMIT 6
#define QNODE_JOIN 7
#define QNODE_DISTINCT 8
#define QNODE_SORT 9
#define QNODE_UNION 10
#define QNODE_TIMEWINDOW 11
#define QNODE_SESSIONWINDOW 12
#define QNODE_STATEWINDOW 13
#define QNODE_FILL 14
typedef struct SFillEssInfo {
int32_t fillType; // fill type
int64_t *val; // fill value
@ -104,9 +89,9 @@ static SQueryPlanNode* createQueryNode(int32_t type, const char* name, SQueryPla
taosArrayPush(pNode->pExpr, &pExpr[i]);
}
pNode->pPrevNodes = taosArrayInit(4, POINTER_BYTES);
pNode->pChildren = taosArrayInit(4, POINTER_BYTES);
for(int32_t i = 0; i < numOfPrev; ++i) {
taosArrayPush(pNode->pPrevNodes, &prev[i]);
taosArrayPush(pNode->pChildren, &prev[i]);
}
switch(type) {
@ -386,14 +371,14 @@ static void doDestroyQueryNode(SQueryPlanNode* pQueryNode) {
tfree(pQueryNode->info.name);
// dropAllExprInfo(pQueryNode->pExpr);
if (pQueryNode->pPrevNodes != NULL) {
int32_t size = (int32_t) taosArrayGetSize(pQueryNode->pPrevNodes);
if (pQueryNode->pChildren != NULL) {
int32_t size = (int32_t) taosArrayGetSize(pQueryNode->pChildren);
for(int32_t i = 0; i < size; ++i) {
SQueryPlanNode* p = taosArrayGetP(pQueryNode->pPrevNodes, i);
SQueryPlanNode* p = taosArrayGetP(pQueryNode->pChildren, i);
doDestroyQueryNode(p);
}
taosArrayDestroy(pQueryNode->pPrevNodes);
taosArrayDestroy(pQueryNode->pChildren);
}
tfree(pQueryNode);
@ -607,8 +592,8 @@ int32_t printExprInfo(const char* buf, const SQueryPlanNode* pQueryNode, int32_t
int32_t queryPlanToStringImpl(char* buf, SQueryPlanNode* pQueryNode, int32_t level, int32_t totalLen) {
int32_t len = doPrintPlan(buf, pQueryNode, level, totalLen);
for(int32_t i = 0; i < taosArrayGetSize(pQueryNode->pPrevNodes); ++i) {
SQueryPlanNode* p1 = taosArrayGetP(pQueryNode->pPrevNodes, i);
for(int32_t i = 0; i < taosArrayGetSize(pQueryNode->pChildren); ++i) {
SQueryPlanNode* p1 = taosArrayGetP(pQueryNode->pChildren, i);
int32_t len1 = queryPlanToStringImpl(buf, p1, level + 1, len);
len = len1;
}