/* * _readArrayCoerceExpr */ static ArrayCoerceExpr * _readArrayCoerceExpr(void) { READ_LOCALS(ArrayCoerceExpr); READ_NODE_FIELD(arg); READ_OID_FIELD(elemfuncid); READ_OID_FIELD(resulttype); READ_INT_FIELD(resulttypmod); READ_BOOL_FIELD(isExplicit); READ_ENUM_FIELD(coerceformat, CoercionForm); READ_LOCATION_FIELD(location); READ_DONE(); }
/* * _readWindowFunc */ static WindowFunc * _readWindowFunc(void) { READ_LOCALS(WindowFunc); READ_OID_FIELD(winfnoid); READ_OID_FIELD(wintype); READ_NODE_FIELD(args); READ_UINT_FIELD(winref); READ_BOOL_FIELD(winstar); READ_BOOL_FIELD(winagg); READ_LOCATION_FIELD(location); READ_DONE(); }
/* * _readArrayRef */ static ArrayRef * _readArrayRef(void) { READ_LOCALS(ArrayRef); READ_OID_FIELD(refarraytype); READ_OID_FIELD(refelemtype); READ_INT_FIELD(reftypmod); READ_NODE_FIELD(refupperindexpr); READ_NODE_FIELD(reflowerindexpr); READ_NODE_FIELD(refexpr); READ_NODE_FIELD(refassgnexpr); READ_DONE(); }
/* * _readSetOperationStmt */ static SetOperationStmt * _readSetOperationStmt(void) { READ_LOCALS(SetOperationStmt); READ_ENUM_FIELD(op, SetOperation); READ_BOOL_FIELD(all); READ_NODE_FIELD(larg); READ_NODE_FIELD(rarg); READ_NODE_FIELD(colTypes); READ_NODE_FIELD(colTypmods); READ_NODE_FIELD(groupClauses); READ_DONE(); }
/* * _readAggref */ static Aggref * _readAggref(void) { READ_LOCALS(Aggref); READ_OID_FIELD(aggfnoid); READ_OID_FIELD(aggtype); READ_NODE_FIELD(args); READ_UINT_FIELD(agglevelsup); READ_BOOL_FIELD(aggstar); READ_BOOL_FIELD(aggdistinct); READ_LOCATION_FIELD(location); READ_DONE(); }
/* * _readWindowClause */ static WindowClause * _readWindowClause(void) { READ_LOCALS(WindowClause); READ_STRING_FIELD(name); READ_STRING_FIELD(refname); READ_NODE_FIELD(partitionClause); READ_NODE_FIELD(orderClause); READ_INT_FIELD(frameOptions); READ_UINT_FIELD(winref); READ_BOOL_FIELD(copiedOrder); READ_DONE(); }
static IntoClause * _readIntoClause(void) { READ_LOCALS(IntoClause); READ_NODE_FIELD(rel); READ_NODE_FIELD(colNames); READ_NODE_FIELD(options); READ_ENUM_FIELD(onCommit, OnCommitAction); READ_STRING_FIELD(tableSpaceName); READ_BOOL_FIELD(skipData); READ_CHAR_FIELD(relkind); READ_DONE(); }
/* * _readRangeTblFunction */ static RangeTblFunction * _readRangeTblFunction(void) { READ_LOCALS(RangeTblFunction); READ_NODE_FIELD(funcexpr); READ_INT_FIELD(funccolcount); READ_NODE_FIELD(funccolnames); READ_NODE_FIELD(funccoltypes); READ_NODE_FIELD(funccoltypmods); READ_NODE_FIELD(funccolcollations); READ_BITMAPSET_FIELD(funcparams); READ_DONE(); }
/* * _readTargetEntry */ static TargetEntry * _readTargetEntry(void) { READ_LOCALS(TargetEntry); READ_NODE_FIELD(expr); READ_INT_FIELD(resno); READ_STRING_FIELD(resname); READ_UINT_FIELD(ressortgroupref); READ_OID_FIELD(resorigtbl); READ_INT_FIELD(resorigcol); READ_BOOL_FIELD(resjunk); READ_DONE(); }
/* * _readVar */ static Var * _readVar(void) { READ_LOCALS(Var); READ_UINT_FIELD(varno); READ_INT_FIELD(varattno); READ_OID_FIELD(vartype); READ_INT_FIELD(vartypmod); READ_UINT_FIELD(varlevelsup); READ_UINT_FIELD(varnoold); READ_INT_FIELD(varoattno); READ_LOCATION_FIELD(location); READ_DONE(); }
/* * _readXmlExpr */ static XmlExpr * _readXmlExpr(void) { READ_LOCALS(XmlExpr); READ_ENUM_FIELD(op, XmlExprOp); READ_STRING_FIELD(name); READ_NODE_FIELD(named_args); READ_NODE_FIELD(arg_names); READ_NODE_FIELD(args); READ_ENUM_FIELD(xmloption, XmlOptionType); READ_OID_FIELD(type); READ_INT_FIELD(typmod); READ_DONE(); }
static RangeVar * _readRangeVar(void) { READ_LOCALS(RangeVar); local_node->catalogname = NULL; /* not currently saved in output * format */ READ_STRING_FIELD(schemaname); READ_STRING_FIELD(relname); READ_ENUM_FIELD(inhOpt, InhOption); READ_BOOL_FIELD(istemp); READ_NODE_FIELD(alias); READ_DONE(); }
/* * _readFuncExpr */ static FuncExpr * _readFuncExpr(void) { READ_LOCALS(FuncExpr); READ_OID_FIELD(funcid); READ_OID_FIELD(funcresulttype); READ_BOOL_FIELD(funcretset); READ_ENUM_FIELD(funcformat, CoercionForm); READ_OID_FIELD(funccollid); READ_OID_FIELD(inputcollid); READ_NODE_FIELD(args); READ_LOCATION_FIELD(location); READ_DONE(); }
/* * _readOnConflictExpr */ static OnConflictExpr * _readOnConflictExpr(void) { READ_LOCALS(OnConflictExpr); READ_ENUM_FIELD(action, OnConflictAction); READ_NODE_FIELD(arbiterElems); READ_NODE_FIELD(arbiterWhere); READ_NODE_FIELD(onConflictSet); READ_NODE_FIELD(onConflictWhere); READ_OID_FIELD(constraint); READ_INT_FIELD(exclRelIndex); READ_NODE_FIELD(exclRelTlist); READ_DONE(); }
/* * _readJoinExpr */ static JoinExpr * _readJoinExpr(void) { READ_LOCALS(JoinExpr); READ_ENUM_FIELD(jointype, JoinType); READ_BOOL_FIELD(isNatural); READ_NODE_FIELD(larg); READ_NODE_FIELD(rarg); READ_NODE_FIELD(using); READ_NODE_FIELD(quals); READ_NODE_FIELD(alias); READ_INT_FIELD(rtindex); READ_DONE(); }
/* * _readCommonTableExpr */ static CommonTableExpr * _readCommonTableExpr(void) { READ_LOCALS(CommonTableExpr); READ_STRING_FIELD(ctename); READ_NODE_FIELD(aliascolnames); READ_NODE_FIELD(ctequery); READ_LOCATION_FIELD(location); READ_BOOL_FIELD(cterecursive); READ_INT_FIELD(cterefcount); READ_NODE_FIELD(ctecolnames); READ_NODE_FIELD(ctecoltypes); READ_NODE_FIELD(ctecoltypmods); READ_DONE(); }
/* * _readRangeTblEntry */ static RangeTblEntry * _readRangeTblEntry(void) { READ_LOCALS(RangeTblEntry); /* put alias + eref first to make dump more legible */ READ_NODE_FIELD(alias); READ_NODE_FIELD(eref); READ_ENUM_FIELD(rtekind, RTEKind); switch (local_node->rtekind) { case RTE_RELATION: case RTE_SPECIAL: READ_OID_FIELD(relid); break; case RTE_SUBQUERY: READ_NODE_FIELD(subquery); break; case RTE_FUNCTION: READ_NODE_FIELD(funcexpr); READ_NODE_FIELD(funccoltypes); READ_NODE_FIELD(funccoltypmods); break; case RTE_VALUES: READ_NODE_FIELD(values_lists); break; case RTE_JOIN: READ_ENUM_FIELD(jointype, JoinType); READ_NODE_FIELD(joinaliasvars); break; default: elog(ERROR, "unrecognized RTE kind: %d", (int) local_node->rtekind); break; } READ_BOOL_FIELD(inh); READ_BOOL_FIELD(inFromCl); READ_UINT_FIELD(requiredPerms); READ_OID_FIELD(checkAsUser); READ_DONE(); }
/* * _readConst */ static Const * _readConst(void) { READ_LOCALS(Const); READ_OID_FIELD(consttype); READ_INT_FIELD(consttypmod); READ_INT_FIELD(constlen); READ_BOOL_FIELD(constbyval); READ_BOOL_FIELD(constisnull); token = pg_strtok(&length); /* skip :constvalue */ if (local_node->constisnull) token = pg_strtok(&length); /* skip "<>" */ else local_node->constvalue = readDatum(local_node->constbyval); READ_DONE(); }
/* * _readQuery */ static Query * _readQuery(void) { READ_LOCALS(Query); READ_ENUM_FIELD(commandType, CmdType); READ_ENUM_FIELD(querySource, QuerySource); local_node->queryId = 0; /* not saved in output format */ READ_BOOL_FIELD(canSetTag); READ_NODE_FIELD(utilityStmt); READ_INT_FIELD(resultRelation); READ_BOOL_FIELD(hasAggs); READ_BOOL_FIELD(hasWindowFuncs); READ_BOOL_FIELD(hasSubLinks); READ_BOOL_FIELD(hasDistinctOn); READ_BOOL_FIELD(hasRecursive); READ_BOOL_FIELD(hasModifyingCTE); READ_BOOL_FIELD(hasForUpdate); READ_BOOL_FIELD(hasRowSecurity); READ_NODE_FIELD(cteList); READ_NODE_FIELD(rtable); READ_NODE_FIELD(jointree); READ_NODE_FIELD(targetList); READ_NODE_FIELD(onConflict); READ_NODE_FIELD(returningList); READ_NODE_FIELD(groupClause); READ_NODE_FIELD(groupingSets); READ_NODE_FIELD(havingQual); READ_NODE_FIELD(windowClause); READ_NODE_FIELD(distinctClause); READ_NODE_FIELD(sortClause); READ_NODE_FIELD(limitOffset); READ_NODE_FIELD(limitCount); READ_NODE_FIELD(rowMarks); READ_NODE_FIELD(setOperations); READ_NODE_FIELD(constraintDeps); READ_BOOL_FIELD(isContinuous); READ_BOOL_FIELD(isCombine); READ_BOOL_FIELD(isCombineLookup); READ_INT_FIELD(swStepFactor); READ_DONE(); }
/* * _readTableSampleClause */ static TableSampleClause * _readTableSampleClause(void) { READ_LOCALS(TableSampleClause); READ_OID_FIELD(tsmid); READ_BOOL_FIELD(tsmseqscan); READ_BOOL_FIELD(tsmpagemode); READ_OID_FIELD(tsminit); READ_OID_FIELD(tsmnextblock); READ_OID_FIELD(tsmnexttuple); READ_OID_FIELD(tsmexaminetuple); READ_OID_FIELD(tsmend); READ_OID_FIELD(tsmreset); READ_OID_FIELD(tsmcost); READ_NODE_FIELD(repeatable); READ_NODE_FIELD(args); READ_DONE(); }
/* * _readBoolExpr */ static BoolExpr * _readBoolExpr(void) { READ_LOCALS(BoolExpr); /* do-it-yourself enum representation */ token = pg_strtok(&length); /* skip :boolop */ token = pg_strtok(&length); /* get field value */ if (strncmp(token, "and", 3) == 0) local_node->boolop = AND_EXPR; else if (strncmp(token, "or", 2) == 0) local_node->boolop = OR_EXPR; else if (strncmp(token, "not", 3) == 0) local_node->boolop = NOT_EXPR; else elog(ERROR, "unrecognized boolop \"%.*s\"", length, token); READ_NODE_FIELD(args); READ_DONE(); }
static Task * _readTask(void) { READ_LOCALS(Task); READ_ENUM_FIELD(taskType, TaskType); READ_UINT64_FIELD(jobId); READ_UINT_FIELD(taskId); READ_STRING_FIELD(queryString); READ_UINT64_FIELD(anchorShardId); READ_NODE_FIELD(taskPlacementList); READ_NODE_FIELD(dependedTaskList); READ_UINT_FIELD(partitionId); READ_UINT_FIELD(upstreamTaskId); READ_NODE_FIELD(shardInterval); READ_BOOL_FIELD(assignmentConstrained); READ_NODE_FIELD(taskExecution); READ_BOOL_FIELD(upsertQuery); READ_DONE(); }
/* * _readAggref */ static Aggref * _readAggref(void) { READ_LOCALS(Aggref); READ_OID_FIELD(aggfnoid); READ_OID_FIELD(aggtype); #ifdef PGXC READ_OID_FIELD(aggtrantype); READ_BOOL_FIELD(agghas_collectfn); #endif /* PGXC */ READ_OID_FIELD(aggcollid); READ_OID_FIELD(inputcollid); READ_NODE_FIELD(args); READ_NODE_FIELD(aggorder); READ_NODE_FIELD(aggdistinct); READ_BOOL_FIELD(aggstar); READ_UINT_FIELD(agglevelsup); READ_LOCATION_FIELD(location); READ_DONE(); }
/* * _readAggref */ static Aggref * _readAggref(void) { READ_LOCALS(Aggref); READ_OID_FIELD(aggfnoid); READ_OID_FIELD(aggtype); READ_OID_FIELD(aggcollid); READ_OID_FIELD(inputcollid); READ_NODE_FIELD(aggdirectargs); READ_NODE_FIELD(args); READ_NODE_FIELD(aggorder); READ_NODE_FIELD(aggdistinct); READ_NODE_FIELD(aggfilter); READ_BOOL_FIELD(aggstar); READ_BOOL_FIELD(aggvariadic); READ_CHAR_FIELD(aggkind); READ_UINT_FIELD(agglevelsup); READ_LOCATION_FIELD(location); READ_DONE(); }
/* * _readScalarArrayOpExpr */ static ScalarArrayOpExpr * _readScalarArrayOpExpr(void) { READ_LOCALS(ScalarArrayOpExpr); READ_OID_FIELD(opno); READ_OID_FIELD(opfuncid); /* * The opfuncid is stored in the textual format primarily for debugging * and documentation reasons. We want to always read it as zero to force * it to be re-looked-up in the pg_operator entry. This ensures that * stored rules don't have hidden dependencies on operators' functions. * (We don't currently support an ALTER OPERATOR command, but might * someday.) */ local_node->opfuncid = InvalidOid; READ_BOOL_FIELD(useOr); READ_NODE_FIELD(args); READ_DONE(); }
/* * _readQuery */ static Query * _readQuery(void) { READ_LOCALS(Query); READ_ENUM_FIELD(commandType, CmdType); READ_ENUM_FIELD(querySource, QuerySource); READ_BOOL_FIELD(canSetTag); READ_NODE_FIELD(utilityStmt); READ_INT_FIELD(resultRelation); READ_NODE_FIELD(intoClause); READ_BOOL_FIELD(hasAggs); READ_BOOL_FIELD(hasWindowFuncs); READ_BOOL_FIELD(hasSubLinks); READ_BOOL_FIELD(hasDistinctOn); READ_BOOL_FIELD(hasRecursive); READ_BOOL_FIELD(hasModifyingCTE); READ_BOOL_FIELD(hasForUpdate); READ_NODE_FIELD(cteList); READ_NODE_FIELD(rtable); READ_NODE_FIELD(jointree); READ_NODE_FIELD(targetList); READ_NODE_FIELD(returningList); READ_NODE_FIELD(groupClause); READ_NODE_FIELD(havingQual); READ_NODE_FIELD(windowClause); READ_NODE_FIELD(distinctClause); READ_NODE_FIELD(sortClause); READ_NODE_FIELD(limitOffset); READ_NODE_FIELD(limitCount); READ_NODE_FIELD(rowMarks); READ_NODE_FIELD(setOperations); READ_NODE_FIELD(constraintDeps); READ_DONE(); }
/* * _readRangeTblEntry */ static RangeTblEntry * _readRangeTblEntry(void) { READ_LOCALS(RangeTblEntry); /* put alias + eref first to make dump more legible */ READ_NODE_FIELD(alias); READ_NODE_FIELD(eref); READ_ENUM_FIELD(rtekind, RTEKind); #ifdef PGXC READ_STRING_FIELD(relname); #endif switch (local_node->rtekind) { case RTE_RELATION: READ_OID_FIELD(relid); READ_CHAR_FIELD(relkind); break; case RTE_SUBQUERY: READ_NODE_FIELD(subquery); READ_BOOL_FIELD(security_barrier); break; case RTE_JOIN: READ_ENUM_FIELD(jointype, JoinType); READ_NODE_FIELD(joinaliasvars); break; case RTE_FUNCTION: READ_NODE_FIELD(funcexpr); READ_NODE_FIELD(funccoltypes); READ_NODE_FIELD(funccoltypmods); READ_NODE_FIELD(funccolcollations); break; case RTE_VALUES: READ_NODE_FIELD(values_lists); READ_NODE_FIELD(values_collations); break; case RTE_CTE: READ_STRING_FIELD(ctename); READ_UINT_FIELD(ctelevelsup); READ_BOOL_FIELD(self_reference); READ_NODE_FIELD(ctecoltypes); READ_NODE_FIELD(ctecoltypmods); READ_NODE_FIELD(ctecolcollations); break; #ifdef PGXC case RTE_REMOTE_DUMMY: /* Nothing to do */ break; #endif /* PGXC */ default: elog(ERROR, "unrecognized RTE kind: %d", (int) local_node->rtekind); break; } READ_BOOL_FIELD(lateral); READ_BOOL_FIELD(inh); READ_BOOL_FIELD(inFromCl); READ_UINT_FIELD(requiredPerms); READ_OID_FIELD(checkAsUser); READ_BITMAPSET_FIELD(selectedCols); READ_BITMAPSET_FIELD(modifiedCols); READ_DONE(); }
void generateMap(string id) { srand(1); int n, l, m, s; READ(cin, n); READ(cin, l); READ(cin, m); READ(cin, s); vector<string> aname(n * l); for (int i = 0; i < n; i++) { for (int j = 0; j < l; j++) { READ_FRAG(cin, j, aname[i * l + j]); } READ_DONE(); } int newL, newM, newS, tagNumber; READ(cin, newL); READ(cin, newM); READ(cin, newS); READ(cin, tagNumber); vector<string> nodeNameList; vector<string> nodeTagList; for (int j = 0; j < newM; j++) { string nodeName; READ_FRAG(cin, 0, nodeName); nodeNameList.push_back(nodeName); for (int i = 0; i < tagNumber; i++) { string nodeTag; READ_FRAG(cin, i+1, nodeTag); nodeTagList.push_back(nodeTag); } READ_DONE(); } fixOldData(n, l, m, s, aname); fixNewData(n, newL, newM, newS, tagNumber, nodeNameList, nodeTagList); if (!validate(n, l, m, s)) { DIAG("ERROR: existing mapping failed validation" << endl); throw "Validation failure"; } if (!validate(n, newL, newM, newS) || !validate(newM, nodeNameList, tagNumber, nodeTagList)) { DIAG("ERROR: new mapping failed validation" << endl); throw "Validation failure"; } if (!IsInRow(nodeNameList, _NULL_NODE_NAME)) { nodeNameList.insert(nodeNameList.begin(), _NULL_NODE_NAME); for (int i = 0; i < tagNumber; i++) { nodeTagList.insert(nodeTagList.begin(), ""); } } Mapping map0(n, l, m, s); map0.InitMapping(aname); vector<int> TagPrice(tagNumber,0); for (int i = 0; i < tagNumber; i++) { TagPrice[i] = 10; // default to 10 for now } stack<int> addedNode; for (int j = 1; j <= newM; ++j ) { if (!IsInRow(map0.nodeNameList, nodeNameList[j])) { addedNode.push(j); } } // Deleted nodes map to zero, used for computing lower bound vector<int> oldNode2NewZero(map0.M + 1, 0); // Deleted nodes map to added nodes if possible // Used for initialize a search for RI vector<int> oldNode2NewMatch(map0.M + 1, 0); string currentNode; bool nodeFound; for (int i = 1; i <= map0.M; i++) { currentNode = map0.nodeNameList[i]; nodeFound = 0; for (int j = 0; j <= newM; ++j ) { if (!currentNode.compare(nodeNameList[j])) { nodeFound = 1; oldNode2NewMatch[i] = j; oldNode2NewZero[i] = j; break; } } if (!nodeFound) { if (!addedNode.empty() ) { oldNode2NewMatch[i] = addedNode.top(); addedNode.pop(); } } } Mapping map1(map0.N, newL, newM, newS); map1.nodeNameList.swap(nodeNameList); map1.nodeTagList.swap(nodeTagList); map1.Rebalance(map0, oldNode2NewMatch, TagPrice); map1.nodeTagNumber = tagNumber; int LowerBound = map1.RebalanceLowerBound(map0, oldNode2NewZero, TagPrice); if (map1.imbalance) DIAG("WARNING : Output mapping has imbalance of " << map1.imbalance << "\n\n"); DIAG("\nRebalance completed.\nNode number : " << map0.M << " ---> " << map1.M); DIAG("\nMove count (index/non-index) : " << map1.MoveCount(map0, 1) << " / "); DIAG(map1.MoveCount(map0, 0) << "\tLower bound : " << LowerBound); DIAG("\n\nSame tags replication :\nPrice : \t"); vector<int> sameTagCount; map1.CheckTags(sameTagCount); for (int i = 0; i < map1.nodeTagNumber; i++) { DIAG(TagPrice[i] << '\t'); } DIAG("\nCount : \t"); for (int i = 0; i < map1.nodeTagNumber; i++) { DIAG(sameTagCount[i] << '\t'); } DIAG(endl); ostringstream mapout; map1.PrintAname(mapout); WRITE(cout, mapout.str() << endl); }
/* * _readRangeTblEntry */ static RangeTblEntry * _readRangeTblEntry(void) { READ_LOCALS(RangeTblEntry); /* put alias + eref first to make dump more legible */ READ_NODE_FIELD(alias); READ_NODE_FIELD(eref); READ_ENUM_FIELD(rtekind, RTEKind); switch (local_node->rtekind) { case RTE_RELATION: READ_OID_FIELD(relid); READ_CHAR_FIELD(relkind); READ_NODE_FIELD(tablesample); if (local_node->relkind == RELKIND_STREAM) { READ_NODE_FIELD(ctecoltypes); READ_NODE_FIELD(ctecoltypmods); READ_NODE_FIELD(ctecolcollations); } break; case RTE_SUBQUERY: READ_NODE_FIELD(subquery); READ_BOOL_FIELD(security_barrier); break; case RTE_JOIN: READ_ENUM_FIELD(jointype, JoinType); READ_NODE_FIELD(joinaliasvars); break; case RTE_FUNCTION: READ_NODE_FIELD(functions); READ_BOOL_FIELD(funcordinality); break; case RTE_VALUES: READ_NODE_FIELD(values_lists); READ_NODE_FIELD(values_collations); break; case RTE_CTE: READ_STRING_FIELD(ctename); READ_UINT_FIELD(ctelevelsup); READ_BOOL_FIELD(self_reference); READ_NODE_FIELD(ctecoltypes); READ_NODE_FIELD(ctecoltypmods); READ_NODE_FIELD(ctecolcollations); break; default: elog(ERROR, "unrecognized RTE kind: %d", (int) local_node->rtekind); break; } READ_BOOL_FIELD(lateral); READ_BOOL_FIELD(inh); READ_BOOL_FIELD(inFromCl); READ_UINT_FIELD(requiredPerms); READ_OID_FIELD(checkAsUser); READ_BITMAPSET_FIELD(selectedCols); READ_BITMAPSET_FIELD(insertedCols); READ_BITMAPSET_FIELD(updatedCols); READ_NODE_FIELD(securityQuals); READ_DONE(); }