Skip to content

Commit

Permalink
Recommend enabling auto_explain.log_timing
Browse files Browse the repository at this point in the history
  • Loading branch information
seanlinsley committed May 10, 2024
1 parent ad4f290 commit 9c252b1
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 3 deletions.
86 changes: 86 additions & 0 deletions components/Callout.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
import React from "react";

import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
import {
faExclamationTriangle,
faLightbulbOn,
IconDefinition,
} from "@fortawesome/pro-solid-svg-icons";

type CalloutVariantType = "info" | "warning";
type CalloutButton = {
label: string;
onClick: () => void;
};

const Callout: React.FunctionComponent<{
title?: string;
children: React.ReactNode;
variant?: CalloutVariantType;
className?: string;
learnMoreLink?: string;
calloutButton?: CalloutButton;
}> = ({
title,
children,
className,
learnMoreLink,
variant = "info",
calloutButton,
}) => {
const commonStyles = { fontWeight: "500", borderWidth: "1px", borderRadius: "0.25rem", paddingLeft: "1rem", paddingRight: "1rem", paddingTop: "0.75rem", paddingBottom: "0.75rem", marginBottom: "1.25rem" }
let variantStyles: any;
let iconStyles: any;
let icon: IconDefinition;
switch (variant) {
case "info":
variantStyles = { backgroundColor: "rgb(248 250 252)", borderColor: "rgb(226 232 240)", color: "rgb(51 65 85)" }
iconStyles = { color: "#337ab7" }
icon = faLightbulbOn;
break;
case "warning":
variantStyles = { backgroundColor: "rgb(254 252 232)", borderColor: "rgb(234 179 8)", color: "rgb(161 98 7)" }
iconStyles = { color: "rgb(202 138 4)" }
icon = faExclamationTriangle;
break;
}
const content = (
<>
{title && <div style={{ fontWeight: 600, marginBottom: "0.25rem" }}>{title}</div>}
{children}
</>
);
return (
<div style={{...commonStyles, ...variantStyles}} className={className}>
<div style={{ display: "grid", gridTemplateColumns: "30px 1fr" }}>
<div style={{ paddingTop: "0.25rem", paddingBottom: "0.25rem" }}>
<FontAwesomeIcon style={iconStyles} icon={icon} />
</div>
<div style={{ paddingTop: "0.25rem", paddingBottom: "0.25rem" }}>
{calloutButton ? (
<div style={{ display: "grid", gridTemplateColumns: "1fr 180px", alignItems: "center", gap: "0.75rem" }}>
<div>{content}</div>
<button
className="btn btn-success"
onClick={calloutButton.onClick}
>
{calloutButton.label}
</button>
</div>
) : (
<>{content}</>
)}
{learnMoreLink && (
<div style={{ marginTop: "0.5rem" }}>
<a target="_blank" rel="noopener" href={learnMoreLink}>
Learn more in documentation
</a>
</div>
)}
</div>
</div>
</div>
);
};

export default Callout;
13 changes: 10 additions & 3 deletions components/PgSettingsRecommendations.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Null from './Null';
import styles from './style.module.scss';
import { useDescriptionPopup } from './WithDescriptionPopup';
import { useIcon } from './WithIcons';
import Callout from "./Callout";

type PGSettingRecommendation = {
name: string;
Expand All @@ -17,7 +18,7 @@ type PGSettingRecommendation = {

type RecommendationMode = 'list' | 'alter system';

type Props ={
type Props = {
mode?: RecommendationMode,
recommendations: PGSettingRecommendation[]
}
Expand Down Expand Up @@ -54,6 +55,12 @@ const PGSettingsRecommendations: React.FunctionComponent<Props> = ({ mode = 'lis
})}
</tbody>
</table>
<Callout
learnMoreLink="https://www.postgresql.org/docs/current/using-explain.html#USING-EXPLAIN-CAVEATS"
>
<code>auto_explain.log_timing</code> is helpful when understanding complex queries, but the 5% or more query
overhead may not be acceptable for your production database.
</Callout>
<RecommendationSummary mode={mode} recommendations={recommendations} />
</>
)
Expand Down Expand Up @@ -207,9 +214,9 @@ export const getAllAutoExplainRecommendations = (settings: CurrentSettings | und
},
{
name: 'auto_explain.log_timing',
recommended: 'off',
recommended: 'on',
recommendChange: true,
description: "Controls whether per-node timing information is printed when an execution plan is logged; it's equivalent to the TIMING option of EXPLAIN. The overhead of repeatedly reading the system clock can slow down queries significantly. This parameter has no effect unless auto_explain.log_analyze is enabled."
description: "Controls whether per-node timing information is printed when an execution plan is logged; it's equivalent to the TIMING option of EXPLAIN. The overhead of repeatedly reading the system clock can slow down queries by 5% or more. This parameter has no effect unless auto_explain.log_analyze is enabled."
},
{
name: 'auto_explain.log_triggers',
Expand Down

0 comments on commit 9c252b1

Please sign in to comment.