:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(experiments): hide precompute sub-queries in query performance (#65709)
Juraj Majerik2ed0d5b4652c
diff --git a/frontend/src/scenes/instance/QueryPerformance/QueryPerformance.tsx b/frontend/src/scenes/instance/QueryPerformance/QueryPerformance.tsxindex fa9a4d4f9dcc..2b3aba2f8fb5 100644--- a/frontend/src/scenes/instance/QueryPerformance/QueryPerformance.tsx+++ b/frontend/src/scenes/instance/QueryPerformance/QueryPerformance.tsx@@ -36,14 +36,23 @@ export function QueryPerformance(): JSX.Element {precomputationTeams,precomputationTeamsLoading,search,- slowestQueries,+ visibleSlowestQueries,slowestQueriesLoading,+ showSubQueries,+ allQueriesHiddenAsSubQueries,hoursBack,teamIdFilter,experimentIdFilter,} = useValues(queryPerformanceLogic)- const { setSearch, setPrecomputation, setHoursBack, loadSlowestQueries, setTeamIdFilter, setExperimentIdFilter } =- useActions(queryPerformanceLogic)+ const {+ setSearch,+ setPrecomputation,+ setHoursBack,+ loadSlowestQueries,+ setTeamIdFilter,+ setExperimentIdFilter,+ setShowSubQueries,+ } = useActions(queryPerformanceLogic)if (!user?.is_staff) {return (@@ -310,12 +319,23 @@ export function QueryPerformance(): JSX.Element {>Refresh</LemonButton>+ <LemonSwitch+ label="Show sub-queries"+ checked={showSubQueries}+ onChange={setShowSubQueries}+ size="small"+ bordered+ /></div><LemonTablecolumns={slowestQueryColumns}- dataSource={slowestQueries}+ dataSource={visibleSlowestQueries}loading={slowestQueriesLoading}- emptyState="No queries found in this time range"+ emptyState={+ allQueriesHiddenAsSubQueries+ ? 'All queries in this range are sub-queries — enable "Show sub-queries" to view them'+ : 'No queries found in this time range'+ }pagination={{ pageSize: 20 }}className="overflow-visible! flex-none!"expandable={{diff --git a/frontend/src/scenes/instance/QueryPerformance/queryPerformanceLogic.ts b/frontend/src/scenes/instance/QueryPerformance/queryPerformanceLogic.tsindex 95336a09f801..377a7ce3e5d6 100644--- a/frontend/src/scenes/instance/QueryPerformance/queryPerformanceLogic.ts+++ b/frontend/src/scenes/instance/QueryPerformance/queryPerformanceLogic.ts@@ -1,4 +1,4 @@-import { actions, afterMount, kea, listeners, path, reducers } from 'kea'+import { actions, afterMount, kea, listeners, path, reducers, selectors } from 'kea'import { loaders } from 'kea-loaders'import api from 'lib/api'@@ -47,6 +47,7 @@ export const queryPerformanceLogic = kea<queryPerformanceLogicType>([setHoursBack: (hours: number) => ({ hours }),setTeamIdFilter: (teamId: string) => ({ teamId }),setExperimentIdFilter: (experimentId: string) => ({ experimentId }),+ setShowSubQueries: (show: boolean) => ({ show }),}),reducers({search: [@@ -73,6 +74,12 @@ export const queryPerformanceLogic = kea<queryPerformanceLogicType>([setExperimentIdFilter: (_, { experimentId }) => experimentId,},],+ showSubQueries: [+ false,+ {+ setShowSubQueries: (_, { show }) => show,+ },+ ],}),loaders(({ values }) => ({precomputationTeams: [@@ -116,6 +123,24 @@ export const queryPerformanceLogic = kea<queryPerformanceLogicType>([},],})),+ selectors({+ // The precompute-build INSERTs are sub-queries of a top-level read; hide them by default so the+ // table reflects what a user actually waited for, with a toggle to surface them for debugging.+ visibleSlowestQueries: [+ (s) => [s.slowestQueries, s.showSubQueries],+ (slowestQueries, showSubQueries): SlowestQuery[] =>+ showSubQueries+ ? slowestQueries+ : slowestQueries.filter((query) => query.experiment_query_surface !== 'precompute_build'),+ ],+ // True when the visible table is empty only because every returned row is a hidden sub-query,+ // so the empty state can say so instead of claiming there are no queries in the range.+ allQueriesHiddenAsSubQueries: [+ (s) => [s.slowestQueries, s.visibleSlowestQueries],+ (slowestQueries, visibleSlowestQueries): boolean =>+ slowestQueries.length > 0 && visibleSlowestQueries.length === 0,+ ],+ }),listeners(({ actions }) => ({setSearch: async (_, breakpoint) => {await breakpoint(300)