Пример #1
0
    echo $message->Show();
    $lAdmin->EndPrologContent();
}
$lAdmin->AddHeaders(array(array("id" => "BANNED", "content" => GetMessage("PERFMON_INDEX_BANNED"), "align" => "center", "default" => true), array("id" => "TABLE_NAME", "content" => GetMessage("PERFMON_INDEX_TABLE_NAME"), "default" => true, "sort" => "TABLE_NAME"), array("id" => "COLUMN_NAMES", "content" => GetMessage("PERFMON_INDEX_COLUMN_NAMES"), "default" => true), array("id" => "SQL_COUNT", "content" => GetMessage("PERFMON_INDEX_SQL_COUNT"), "align" => "right", "default" => true, "sort" => "SQL_COUNT"), array("id" => "SQL_TIME_AVG", "content" => GetMessage("PERFMON_INDEX_SQL_TIME_AVG"), "align" => "right", "default" => true), array("id" => "SQL_TIME", "content" => GetMessage("PERFMON_INDEX_SQL_TIME"), "align" => "right", "default" => true, "sort" => "SQL_TIME"), array("id" => "SQL_TEXT", "content" => GetMessage("PERFMON_INDEX_SQL_TEXT"), "default" => true)));
$arSelectedFields = $lAdmin->GetVisibleHeaderColumns();
if (!is_array($arSelectedFields) || count($arSelectedFields) < 1) {
    $arSelectedFields = array("TABLE_NAME", "COLUMN_NAMES", "SQL_COUNT", "SQL_TIME", "SQL_TEXT");
}
$arSelectedFields[] = "ID";
$cData = new CPerfomanceIndexSuggest();
$rsData = $cData->GetList($arSelectedFields, array("!=BANNED" => "Y"), array($by => $order));
$rsData = new CAdminResult($rsData, $sTableID);
$rsData->NavStart();
$lAdmin->NavText($rsData->GetNavPrint(GetMessage("PERFMON_INDEX_PAGE")));
while ($arRes = $rsData->NavNext(true, "f_")) {
    $arRes["SQL_TEXT"] = CPerfomanceSQL::Format($arRes["SQL_TEXT"]);
    $row =& $lAdmin->AddRow($f_NAME, $arRes);
    $row->AddViewField("SQL_TIME", perfmon_NumberFormat($f_SQL_TIME, 6));
    if ($f_SQL_COUNT > 0) {
        $row->AddViewField("SQL_TIME_AVG", perfmon_NumberFormat($f_SQL_TIME / $f_SQL_COUNT, 6));
    }
    $row->AddViewField("SQL_COUNT", '<a href="perfmon_sql_list.php?lang=' . LANGUAGE_ID . '&amp;set_filter=Y&amp;find_suggest_id=' . $f_ID . '">' . $f_SQL_COUNT . '</a>');
    $row->AddViewField("COLUMN_NAMES", str_replace(",", "<br>", $f_COLUMN_NAMES));
    if ($f_BANNED == "N") {
        $row->AddViewField("BANNED", '<span class="adm-lamp adm-lamp-in-list adm-lamp-green" title="' . htmlspecialcharsbx(GetMessage("PERFMON_INDEX_GREEN_ALT")) . '"></span>');
    } elseif ($f_BANNED == "Y") {
        $row->AddViewField("BANNED", '<span class="adm-lamp adm-lamp-in-list adm-lamp-red" title="' . htmlspecialcharsbx(GetMessage("PERFMON_INDEX_RED_ALT")) . '"></span>');
    } else {
        $row->AddViewField("BANNED", '<span class="adm-lamp adm-lamp-in-list adm-lamp-yellow" title="' . htmlspecialcharsbx(GetMessage("PERFMON_INDEX_YELLOW_ALT")) . '"></span>');
    }
    $rsQueries = CPerfomanceSQL::GetList(array("ID"), array("=SUGGEST_ID" => $f_ID), array("ID" => "ASC"), false, array("nTopCount" => 1));
Пример #2
0
while ($arQuery = $rsQueries->Fetch()) {
    $arQuery["STAT"] = array();
    $arQuery["WHERE"] = array();
    $arQuery["JOIN"] = array();
    $q = new CPerfQuery();
    if ($q->parse($q->transform2select($arQuery["SQL_TEXT"]))) {
        foreach ($arColumns as $column_name) {
            $arQuery["WHERE"][$column_name] = $q->find_value($arSuggest["TABLE_NAME"], $column_name);
            if ($arQuery["WHERE"][$column_name] == "") {
                $arQuery["JOIN"][$column_name] = $q->find_join($arSuggest["TABLE_NAME"], $column_name);
            } else {
                $arQuery["JOIN"][$column_name] = "";
            }
        }
    }
    $sql = CPerfomanceSQL::Format($arQuery["SQL_TEXT"]);
    $sql = htmlspecialcharsEx($sql);
    $sql = preg_replace("/(" . preg_quote($arSuggest["TABLE_NAME"]) . "\\s+(?i:as\\s+)*" . $arSuggest["TABLE_ALIAS"] . ")\\s+/", "<b>\\1</b> ", $sql);
    foreach (explode(",", $arSuggest["COLUMN_NAMES"]) as $column_name) {
        $sql = str_replace($arSuggest["TABLE_ALIAS"] . "." . $column_name, "<b>" . $arSuggest["TABLE_ALIAS"] . "." . $column_name . "</b>", $sql);
    }
    $arQuery["FORMATTED_SQL_TEXT"] = $sql;
    foreach ($arColumns as $column_name) {
        if ($arQuery["WHERE"][$column_name]) {
            $arColStat = CPerfQueryStat::GatherColumnStatByValue($arSuggest["TABLE_NAME"], $column_name, trim($arQuery["WHERE"][$column_name], "'"));
            if ($arColStat && $arColStat["TABLE_ROWS"] > 0) {
                $arQuery["STAT"][$column_name] = $arColStat["COLUMN_ROWS"] / $arColStat["TABLE_ROWS"];
            }
        } elseif ($arQuery["JOIN"][$column_name]) {
            $arColStat = CPerfQueryStat::GatherColumnStatOverall($arSuggest["TABLE_NAME"], $column_name);
            if ($arColStat && $arColStat["TABLE_ROWS"] > 0) {
Пример #3
0
    if ($DBType == "mysql") {
        $rsData = $DB->Query("explain " . $strSQL, true);
    } elseif ($DBType == "oracle") {
        $rsData = $DB->Query("explain plan for " . $strSQL, true);
        if ($rsData) {
            $rsData = $DB->Query("select * from plan_table order by ID");
            $arPlan = $rsData->Fetch();
        }
    } else {
        $rsData = false;
    }
} else {
    $rsData = false;
}
if ($rsData) {
    $SQL_TEXT = CPerfomanceSQL::Format($strSQL);
    $lAdmin->BeginPrologContent();
    if (class_exists("geshi")) {
        $obGeSHi = new GeSHi(CSqlFormat::reformatSql($SQL_TEXT), 'sql');
        echo $obGeSHi->parse_code();
    } else {
        echo "<p>" . str_replace(array(" ", "\t", "\n"), array(" ", "&nbsp;&nbsp;&nbsp;", "<br>"), htmlspecialcharsbx(CSqlFormat::reformatSql($SQL_TEXT))) . "</p>";
    }
    if ($arPlan["OPTIMIZER"]) {
        echo "<p>" . GetMessage("PERFMON_EXPLAIN_F_OPTIMIZER") . ": " . $arPlan["OPTIMIZER"] . "</p>";
        echo "<p>" . GetMessage("PERFMON_EXPLAIN_F_COST") . ": " . $arPlan["POSITION"] . "</p>";
    }
    $lAdmin->EndPrologContent();
} else {
    $rsData = new CDBResult();
    $rsData->InitFromArray(array());