5 public static function IsBanned($table, $columns)
11 where TABLE_NAME = '" .
$DB->ForSql($table) .
"'
12 AND COLUMN_NAMES = '" .
$DB->ForSql($columns) .
"'
14 return is_array(
$rs->Fetch());
17 public static function Ban($table, $columns)
20 $DB->Add(
'b_perf_index_ban', [
22 'TABLE_NAME' => $table,
23 'COLUMN_NAMES' => $columns,
31 $table = trim($table,
'`');
33 if (!array_key_exists($table, $cache))
35 $strSql =
'SHOW COLUMNS FROM `' .
$DB->ForSql($table) .
'`';
46 return $cache[$table];
57 $arColumns = explode(
',', $columns);
58 if (
count($arColumns) != 1)
63 $column = trim($arColumns[0],
'`');
64 $value = trim($q->find_value($table, $arColumns[0]),
"'");
76 if (!array_key_exists($column, $arTableColumns))
81 if ($arTableColumns[$column][
'Type'] ===
'char(1)')
106 if ($tab->IsExists())
109 if (!is_array($arStat))
127 if ($tab->IsExists())
130 if (!is_array($arStat))
147 $table = trim($table,
'`');
152 $rs =
$DB->Query(
"show table status like '" .
$DB->ForSql($table) .
"'");
153 $arDBStat =
$rs->Fetch();
154 $DB->Add(
'b_perf_tab_stat', $arStat = [
155 'TABLE_NAME' => $table,
156 'TABLE_SIZE' => $arDBStat[
'Data_length'],
157 'TABLE_ROWS' => $arDBStat[
'Rows'],
163 protected static function _gather_stat($table, $column, $value, $max_size = -1)
166 $table = trim($table,
'`');
167 $column = trim($column,
'`');
170 if ($max_size < 0 || $arStat[
'TABLE_SIZE'] < $max_size)
172 $table = preg_replace(
'/[^A-Za-z0-9%_]+/i',
'', $table);
173 $column = preg_replace(
'/[^A-Za-z0-9%_]+/i',
'', $column);
179 from ' .
$DB->ForSql($table) .
'
180 where `' .
$DB->ForSql($column) .
"` = '" .
$DB->ForSql($value) .
"'
186 select count(distinct `' .
$DB->ForSql($column) .
'`) CNT
187 from ' .
$DB->ForSql($table) .
'
193 $DB->Add(
'b_perf_tab_column_stat', [
194 'TABLE_NAME' => $table,
195 'COLUMN_NAME' => $column,
196 'TABLE_ROWS' => $arStat[
'TABLE_ROWS'],
197 'COLUMN_ROWS' =>
$ar[
'CNT'],
198 'VALUE' => $value ??
false,
209 protected static function _get_stat($table, $column =
'', $value =
'')
212 $table = trim($table,
'`');
213 $column = trim($column,
'`');
220 where TABLE_NAME = '" .
$DB->ForSql($table) .
"'
227 $where = ($value ===
'' ?
'' :
"AND VALUE = '" .
$DB->ForSql($value, 100) .
"'");
231 $where =
'AND VALUE IS NULL';
236 from b_perf_tab_column_stat
237 where TABLE_NAME = '" .
$DB->ForSql($table) .
"'
238 AND COLUMN_NAME = '" .
$DB->ForSql($column) .
"'
250 $arColumns = explode(
',', $columns);
251 if (
count($arColumns) != 1)
256 $arColumns = array_map([
$DB,
'ForSQL'], $arColumns);
258 select max(TABLE_ROWS) TABLE_ROWS, max(COLUMN_ROWS) COLUMN_ROWS
259 from b_perf_tab_column_stat
260 where TABLE_NAME = '" .
$DB->ForSql($table) .
"'
261 AND COLUMN_NAME in ('" . implode(
"','", $arColumns) .
"')
264 if (
$ar &&
$ar[
'TABLE_ROWS'] > 0)
266 return $ar[
'COLUMN_ROWS'] /
$ar[
'TABLE_ROWS'] > 0.05;
static IsSelective($table, $columns)
static GatherColumnStatByValue($table, $column, $value)
static GatherTableStat($table)
static _gather_stat($table, $column, $value, $max_size=-1)
static IsBanned($table, $columns)
static GatherColumnStatOverall($table, $column)
static GatherExpressStat($table, $columns, $q)
static GetTableColumns($table)
static Ban($table, $columns)
static _get_stat($table, $column='', $value='')
Init($TABLE_NAME, $connection=null)
</p ></td >< td valign=top style='border-top:none;border-left:none;border-bottom:solid windowtext 1.0pt;border-right:solid windowtext 1.0pt;padding:0cm 2.0pt 0cm 2.0pt;height:9.0pt'>< p class=Normal align=center style='margin:0cm;margin-bottom:.0001pt;text-align:center;line-height:normal'>< a name=ТекстовоеПоле54 ></a ><?=($taxRate > count( $arTaxList) > 0) ? $taxRate."%"