Datum RestorePlanFromFile(PG_FUNCTION_ARGS) { char *szFilename = textToString(PG_GETARG_TEXT_P(0)); CFileReader fr; fr.Open(szFilename); ULLONG ullSize = fr.UllSize(); char *pcBuf = (char*) gpdb::GPDBAlloc(ullSize); fr.UlpRead((BYTE*)pcBuf, ullSize); fr.Close(); int iBinaryLen; memcpy(&iBinaryLen, pcBuf, sizeof(int)); Assert(iBinaryLen == ullSize - sizeof(int)); char *pcBinary = pcBuf + sizeof(int); int iProcessed = extractFrozenPlanAndExecute(pcBinary); elog(NOTICE, "Processed %d rows.", iProcessed); gpdb::GPDBFree(pcBuf); StringInfoData str; initStringInfo(&str); appendStringInfo(&str, "Query processed %d rows", iProcessed); text *ptResult = stringToText(str.data); PG_RETURN_TEXT_P(ptResult); }
Datum RestorePlanFromDXLFile(PG_FUNCTION_ARGS) { char *szFilename = textToString(PG_GETARG_TEXT_P(0)); CFileReader fr; fr.Open(szFilename); ULLONG ullSize = fr.UllSize(); char *pcBuf = (char*) gpdb::GPDBAlloc(ullSize + 1); fr.UlpRead((BYTE*)pcBuf, ullSize); pcBuf[ullSize] = '\0'; fr.Close(); int iProcessed = executeXMLPlan(pcBuf); elog(NOTICE, "Processed %d rows.", iProcessed); gpdb::GPDBFree(pcBuf); StringInfoData str; initStringInfo(&str); appendStringInfo(&str, "Query processed %d rows", iProcessed); text *ptResult = stringToText(str.data); PG_RETURN_TEXT_P(ptResult); }
Datum EvalExprFromDXLFile(PG_FUNCTION_ARGS) { char *szFileName = textToString(PG_GETARG_TEXT_P(0)); CFileReader fr; fr.Open(szFileName); ULLONG ullSize = fr.UllSize(); char *pcBuf = (char*) gpdb::GPDBAlloc(ullSize + 1); fr.UlpRead((BYTE*)pcBuf, ullSize); fr.Close(); pcBuf[ullSize] = '\0'; char *szResultDXL = COptTasks::SzEvalExprFromXML(pcBuf); gpdb::GPDBFree(pcBuf); if (NULL != szResultDXL) { text *ptResult = stringToText(szResultDXL); gpdb::GPDBFree(szResultDXL); PG_RETURN_TEXT_P(ptResult); } else { // Return a dummy value so the tests can continue PG_RETURN_NULL(); } }
Datum DumpRelStatsDXL(PG_FUNCTION_ARGS) { Oid oid = gpdb::OidFromDatum(PG_GETARG_DATUM(0)); char *szDXL = COptTasks::SzRelStats(ListMake1Oid(oid)); PG_RETURN_TEXT_P(stringToText(szDXL)); }
Datum DumpMDCastDXL(PG_FUNCTION_ARGS) { Oid oidSrc = gpdb::OidFromDatum(PG_GETARG_DATUM(0)); Oid oidDest = gpdb::OidFromDatum(PG_GETARG_DATUM(1)); char *szDXL = COptTasks::SzMDCast(ListMake2Oid(oidSrc, oidDest)); PG_RETURN_TEXT_P(stringToText(szDXL)); }
Datum DumpMDScCmpDXL(PG_FUNCTION_ARGS) { Oid oidLeft = gpdb::OidFromDatum(PG_GETARG_DATUM(0)); Oid oidRight = gpdb::OidFromDatum(PG_GETARG_DATUM(1)); char *szCmpType = textToString(PG_GETARG_TEXT_P(2)); char *szDXL = COptTasks::SzMDScCmp(ListMake2Oid(oidLeft, oidRight), szCmpType); PG_RETURN_TEXT_P(stringToText(szDXL)); }
Datum LibraryVersion() { StringInfoData str; initStringInfo(&str); appendStringInfo(&str, "GPOPT version: %d.%d", GPORCA_VERSION_MAJOR, GPORCA_VERSION_MINOR); appendStringInfo(&str, ", GPOS version: %d.%d", GPOS_VERSION_MAJOR, GPOS_VERSION_MINOR); appendStringInfo(&str, ", Xerces version: %s", XERCES_FULLVERSIONDOT); text *result = stringToText(str.data); PG_RETURN_TEXT_P(result); }
Datum LibraryVersion() { StringInfoData str; initStringInfo(&str); appendStringInfo(&str, "GPOPT version: %s", GPOPT_VERSION); appendStringInfo(&str, ", GPOS version: %s", GPOS_VERSION); appendStringInfo(&str, ", Xerces version: %s", XERCES_VERSION); text *result = stringToText(str.data); PG_RETURN_TEXT_P(result); }
Datum DumpMDObjDXL(PG_FUNCTION_ARGS) { Oid oid = gpdb::OidFromDatum(PG_GETARG_DATUM(0)); char *szDXL = COptTasks::SzMDObjs(ListMake1Oid(oid)); if (NULL == szDXL) { elog(ERROR, "Error dumping MD object"); } PG_RETURN_TEXT_P(stringToText(szDXL)); }
Datum DumpQuery(PG_FUNCTION_ARGS) { char *szSqlText = textToString(PG_GETARG_TEXT_P(0)); Query *pquery = parseSQL(szSqlText); elog(NOTICE, "(DumpQuery - Original) \n %s", pretty_format_node_dump(const_cast<char*>(gpdb::SzNodeToString(pquery)))); Query *pqueryNormalized = preprocess_query_optimizer(pquery, NULL); elog(NOTICE, "(DumpQuery - Normalized) \n %s", pretty_format_node_dump(const_cast<char*>(gpdb::SzNodeToString(pqueryNormalized)))); text *ptResult = stringToText("Query dumped"); PG_RETURN_TEXT_P(ptResult); }
Datum RestorePlanDXL(PG_FUNCTION_ARGS) { char *szXmlString = textToString(PG_GETARG_TEXT_P(0)); int iProcessed = executeXMLPlan(szXmlString); StringInfoData str; initStringInfo(&str); appendStringInfo(&str, "processed %d rows", iProcessed); text *ptResult = stringToText(str.data); PG_RETURN_TEXT_P(ptResult); }
Datum DumpQueryDXL(PG_FUNCTION_ARGS) { char *szSqlText = textToString(PG_GETARG_TEXT_P(0)); Query *pquery = parseSQL(szSqlText); Assert(pquery); char *szXmlString = COptTasks::SzDXL(pquery); if (NULL == szXmlString) { elog(ERROR, "Error translating query to DXL"); } PG_RETURN_TEXT_P(stringToText(szXmlString)); }
Datum DumpPlanDXL(PG_FUNCTION_ARGS) { char *szSqlText = textToString(PG_GETARG_TEXT_P(0)); PlannedStmt *pplstmt = planQuery(szSqlText); Assert(pplstmt); char *szXmlString = COptTasks::SzDXL(pplstmt); if (NULL == szXmlString) { elog(ERROR, "Error translating plan to DXL"); } PG_RETURN_TEXT_P(stringToText(szXmlString)); }
Datum RestoreQuery(PG_FUNCTION_ARGS) { bytea *pbyteaData = PG_GETARG_BYTEA_P(0); char *pcSerializedData = VARDATA(pbyteaData); int iProcessed = extractFrozenQueryPlanAndExecute(pcSerializedData); elog(NOTICE, "(RestorePlan) PROCESSED %d", iProcessed); StringInfoData str; initStringInfo(&str); appendStringInfo(&str, "Query processed %d rows", iProcessed); text *ptResult = stringToText(str.data); PG_RETURN_TEXT_P(ptResult); }
Datum Optimize(PG_FUNCTION_ARGS) { char *szSQLText = textToString(PG_GETARG_TEXT_P(0)); Query *pquery = parseSQL(szSQLText); Query *pqueryNormalized = preprocess_query_optimizer(pquery, NULL); Assert(pqueryNormalized); char *szOutput = COptTasks::SzOptimize(pqueryNormalized); if (NULL == szOutput) { elog(ERROR, "Error optimizing query"); } PG_RETURN_TEXT_P(stringToText(szOutput)); }
Datum OptimizeMinidumpFromFile(PG_FUNCTION_ARGS) { char *szFileName = textToString(PG_GETARG_TEXT_P(0)); char *szResultDXL = COptTasks::SzOptimizeMinidumpFromFile(szFileName); if (NULL != szResultDXL) { text *ptResult = stringToText(szResultDXL); gpdb::GPDBFree(szResultDXL); PG_RETURN_TEXT_P(ptResult); } else { elog(NOTICE, "Execution of UDF 'OptimizeMinidumpFromFile' failed. Consult the LOG for more information."); // return a dummy value PG_RETURN_NULL(); } }
Datum ExecuteMinidumpFromFile(PG_FUNCTION_ARGS) { char *szFileName = textToString(PG_GETARG_TEXT_P(0)); char *szResultDXL = COptTasks::SzOptimizeMinidumpFromFile(szFileName); if (NULL == szResultDXL) { elog(NOTICE, "Execution of UDF 'ExecuteMinidumpFromFile' failed. Consult the LOG for more information."); // return a dummy value PG_RETURN_NULL(); } int iProcessed = executeXMLPlan(szResultDXL); gpdb::GPDBFree(szResultDXL); StringInfoData str; initStringInfo(&str); appendStringInfo(&str, "processed %d rows", iProcessed); text *ptResult = stringToText(str.data); PG_RETURN_TEXT_P(ptResult); }
Datum EnableXform(PG_FUNCTION_ARGS) { char *szXform = textToString(PG_GETARG_TEXT_P(0)); bool fResult = COptTasks::FSetXform(szXform, false /*fDisable*/); StringInfoData str; initStringInfo(&str); if (fResult) { appendStringInfo(&str, "%s is enabled", szXform); } else { appendStringInfo(&str, "%s is not recognized", szXform); } text *result = stringToText(str.data); PG_RETURN_TEXT_P(result); }