16 $tableList = $this->connection->query(
"
19 ,pg_table_size(quote_ident(table_name)) data_length
20 ,pg_indexes_size(quote_ident(table_name)) index_length
21 ,pg_catalog.pg_class.reltuples row_count
23 information_schema.tables
24 left join pg_catalog.pg_class on pg_catalog.pg_class.oid = quote_ident(table_name)::regclass::oid
26 table_schema = 'public'
28 while ($table = $tableList->fetch())
31 'TABLE_NAME' => $table[
'TABLE_NAME'],
33 'NUM_ROWS' => $table[
'ROW_COUNT'],
34 'BYTES' => $table[
'DATA_LENGTH'],
35 'BYTES_INDEX' => $table[
'INDEX_LENGTH'],
41 $tableList = $this->connection->query(
"
45 information_schema.tables
47 table_schema = 'public'
49 while ($table = $tableList->fetch())
52 'TABLE_NAME' => $table[
'TABLE_NAME'],
62 $result->InitFromArray($tables);
72 $table = $this->schema->tables->search($tableName);
75 $table = new \Bitrix\Perfmon\Sql\Table($tableName);
77 $sqlHelper = $this->connection->getSqlHelper();
85 SELECT a.attnum, a.attname
87 LEFT JOIN pg_attribute a ON a.attrelid = t.oid
88 WHERE t.relname = '" . $sqlHelper->forSql($tableName) .
"'
92 if ($column[
'ATTNUM'] > 0)
94 $tableColumns[$column[
'ATTNUM']] = $column[
'ATTNAME'];
98 $indexList = $this->connection->query(
"
99 SELECT relname, indkey, indisprimary, indisunique, pg_get_expr(pg_index.indexprs, pg_index.indrelid) full_text
100 FROM pg_class, pg_index
101 WHERE pg_class.oid = pg_index.indexrelid
102 AND pg_class.oid IN (
104 FROM pg_index, pg_class
105 WHERE pg_class.relname = '" . $sqlHelper->forSql($tableName) .
"'
106 AND pg_class.oid = pg_index.indrelid
108 ORDER BY indisprimary desc
111 while ($indexColumn = $indexList->fetch())
113 $indexColumns[$indexColumn[
'RELNAME']] = [];
114 $unique[$indexColumn[
'RELNAME']] = $indexColumn[
'INDISPRIMARY'] ===
't' || $indexColumn[
'INDISUNIQUE'] ===
't';
115 $fulltext[$indexColumn[
'RELNAME']] = !empty($indexColumn[
'FULL_TEXT']);
116 if ($indexColumn[
'FULL_TEXT'])
119 if (preg_match_all(
'/,\s*([a-z0-9_]+)/i', $indexColumn[
'FULL_TEXT'], $match))
121 foreach ($match[1] as
$i => $colName)
123 $indexColumns[$indexColumn[
'RELNAME']][
$i] = mb_strtoupper($colName);
129 foreach (explode(
' ', $indexColumn[
'INDKEY']) as
$i => $indkey)
131 $indexColumns[$indexColumn[
'RELNAME']][
$i] = mb_strtoupper($tableColumns[$indkey]);
140 foreach ($indexColumns as $indexName => $columns)
142 $index = new \Bitrix\Perfmon\Sql\Index($indexName, $unique[$indexName], $fulltext[$indexName]);
143 $index->columns = array_values($columns);
144 $table->indexes->add($index);
146 $this->schema->tables->add($table);
157 $sqlHelper = $this->connection->getSqlHelper();
161 FROM information_schema.columns
162 WHERE table_schema = 'public'
163 AND table_name = '" . $sqlHelper->forSql($tableName) .
"'
172 switch ($column[
'DATA_TYPE'])
174 case 'character varying':
175 $dataType =
'string';
176 $ormDataType =
'string';
179 $dataType =
'string';
181 $column[
'CHARACTER_MAXIMUM_LENGTH'] == 1
183 substr($column[
'COLUMN_DEFAULT'], 0, 3) ===
"'N'"
184 || substr($column[
'COLUMN_DEFAULT'], 0, 3) ===
"'Y'"
188 $column[
'COLUMN_DEFAULT'] = $column[
'COLUMN_DEFAULT'][1];
189 $ormDataType =
'boolean';
193 $ormDataType =
'string';
199 $dataType =
'string';
200 $ormDataType =
'string';
216 $ormDataType =
'integer';
218 case 'double precision':
223 $dataType =
'double';
224 $ormDataType =
'float';
226 case 'timestamp without time zone':
227 $dataType =
'datetime';
228 $ormDataType =
'datetime';
232 $ormDataType =
'date';
236 $dataType =
'unknown';
237 $ormDataType =
'UNKNOWN';
241 $result[mb_strtoupper($column[
'COLUMN_NAME'])] = $dataType;
242 $resultExt[mb_strtoupper($column[
'COLUMN_NAME'])] = [
244 'length' => $column[
'CHARACTER_MAXIMUM_LENGTH'],
245 'nullable' => $column[
'IS_NULLABLE'] !==
'NO',
246 'default' => preg_match(
'/^\'(.*)\'::/', $column[
'COLUMN_DEFAULT'], $match) ? $match[1] : $column[
'COLUMN_DEFAULT'],
247 'sortable' => $canSort,
248 'orm_type' => $ormDataType,
249 'increment' => strpos($column[
'COLUMN_DEFAULT'],
'nextval(') !==
false || $column[
'IS_IDENTITY'] ===
'YES',