///////////////////////////////////////////////////////////// // // pgAdmin 4 - PostgreSQL Tools // // Copyright (C) 2013 - 2024, The pgAdmin Development Team // This software is released under the PostgreSQL Licence // ////////////////////////////////////////////////////////////// import React from 'react'; import { Box, Grid, makeStyles } from '@material-ui/core'; import gettext from 'sources/gettext'; import { commonTableStyles } from '../Theme'; import clsx from 'clsx'; import _ from 'lodash'; import PropTypes from 'prop-types'; const useStyles = makeStyles((theme)=>({ title: { fontWeight: 'bold', padding: '4px', backgroundColor: theme.otherVars.cardHeaderBg, borderTopLeftRadius: theme.shape.borderRadius, borderTopRightRadius: theme.shape.borderRadius, }, tableRow: { backgroundColor: theme.palette.grey[200] }, tableName:{ fontWeight: 'bold', }, nodeName: { paddingLeft: '30px', }, })); export default function ExplainStatistics({explainTable}) { // _renderStatisticsTable const classes = useStyles(); const tableClasses = commonTableStyles(); return (
{gettext('Statistics per Node Type')}
{explainTable.show_timings && <> } {_.sortBy(Object.keys(explainTable.statistics.nodes)).map((key, i)=>{ let node = explainTable.statistics.nodes[key]; return {explainTable.show_timings && <> } ; })}
{gettext('Node type')} {gettext('Count')}{gettext('Time spent')} {'% '+gettext('of query')}
{node.name} {node.count}{Math.ceil10(node.sum_of_times, -3) + ' ms'} {Math.ceil10(((node.sum_of_times||0)/(explainTable.total_time||1)) * 100, -2)+ '%'}
{gettext('Statistics per Relation')}
{explainTable.show_timings && <> } {explainTable.show_timings && <> } {_.sortBy(Object.keys(explainTable.statistics.tables)).map((key, i)=>{ let table = explainTable.statistics.tables[key]; table.sum_of_times = _.sumBy(Object.values(table.nodes), 'sum_of_times'); return {explainTable.show_timings && <> } {_.sortBy(Object.keys(table.nodes)).map((nodeKey, j)=>{ let node = table.nodes[nodeKey]; return {explainTable.show_timings && <> } ; })} ; })}
{gettext('Relation name')} {gettext('Scan count')}{gettext('Total time')} {'% '+gettext('of query')}
{gettext('Node type')} {gettext('Count')}{gettext('Sum of times')} {'% '+gettext('of relation')}
{table.name} {table.count}{Math.ceil10(table.sum_of_times, -3) + ' ms'} {Math.ceil10(((table.sum_of_times||0)/(explainTable.total_time||1)) * 100, -2)+ '%'}
{node.name}
{node.count}{Math.ceil10(node.sum_of_times, -3) + ' ms'} {Math.ceil10(((node.sum_of_times||0)/(table.sum_of_times||1)) * 100, -2)+ '%'}
); } ExplainStatistics.propTypes = { explainTable: PropTypes.shape({ show_timings: PropTypes.bool, statistics: PropTypes.shape({ nodes: PropTypes.object, tables: PropTypes.object, }), total_time: PropTypes.number, }), };