///////////////////////////////////////////////////////////// // // 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 { styled } from '@mui/material/styles'; import { Box, Grid } from '@mui/material'; import gettext from 'sources/gettext'; import _ from 'lodash'; import PropTypes from 'prop-types'; import Table from '../components/Table'; const StyledBox = styled(Box)(({theme}) => ({ '& .ExplainStatistics-title': { fontWeight: 'bold', padding: '4px', backgroundColor: theme.otherVars.cardHeaderBg, borderTopLeftRadius: theme.shape.borderRadius, borderTopRightRadius: theme.shape.borderRadius, }, '& .ExplainStatistics-tableRow': { backgroundColor: theme.palette.grey[200], '& .ExplainStatistics-tableName': { fontWeight: 'bold', '& .ExplainStatistics-nodeName': { paddingLeft: '30px', } }, }, })); export default function ExplainStatistics({explainTable}) { // _renderStatisticsTable 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, }), };