mirror of https://github.com/citusdata/citus.git
Set buffer usage with explain
It seems that currently we process even postgres tables in explain commands. This is because we register a hook for explain and we don't have any check to see if the query has any citus table. With this commit, we now send the buffer usage as well to the relevant API. There is some duplicate in the code but it is because of the existing structure, we can refactor this separately.pull/3900/head
parent
fe1e1c9b68
commit
63ed126ad4
|
@ -272,7 +272,16 @@ ExplainSubPlans(DistributedPlan *distributedPlan, ExplainState *es)
|
|||
ParamListInfo params = NULL;
|
||||
char *queryString = NULL;
|
||||
instr_time planduration;
|
||||
#if PG_VERSION_NUM >= PG_VERSION_13
|
||||
|
||||
BufferUsage bufusage_start,
|
||||
bufusage;
|
||||
|
||||
if (es->buffers)
|
||||
{
|
||||
bufusage_start = pgBufferUsage;
|
||||
}
|
||||
#endif
|
||||
if (es->format == EXPLAIN_FORMAT_TEXT)
|
||||
{
|
||||
char *resultId = GenerateResultId(planId, subPlan->subPlanId);
|
||||
|
@ -314,7 +323,18 @@ ExplainSubPlans(DistributedPlan *distributedPlan, ExplainState *es)
|
|||
|
||||
INSTR_TIME_SET_ZERO(planduration);
|
||||
|
||||
ExplainOnePlanCompat(plan, into, es, queryString, params, NULL, &planduration);
|
||||
#if PG_VERSION_NUM >= PG_VERSION_13
|
||||
|
||||
/* calc differences of buffer counters. */
|
||||
if (es->buffers)
|
||||
{
|
||||
memset(&bufusage, 0, sizeof(BufferUsage));
|
||||
BufferUsageAccumDiff(&bufusage, &pgBufferUsage, &bufusage_start);
|
||||
}
|
||||
#endif
|
||||
|
||||
ExplainOnePlanCompat(plan, into, es, queryString, params, NULL, &planduration,
|
||||
(es->buffers ? &bufusage : NULL));
|
||||
|
||||
if (es->format == EXPLAIN_FORMAT_TEXT)
|
||||
{
|
||||
|
@ -1123,6 +1143,15 @@ CitusExplainOneQuery(Query *query, int cursorOptions, IntoClause *into,
|
|||
/* rest is copied from ExplainOneQuery() */
|
||||
instr_time planstart,
|
||||
planduration;
|
||||
#if PG_VERSION_NUM >= PG_VERSION_13
|
||||
BufferUsage bufusage_start,
|
||||
bufusage;
|
||||
|
||||
if (es->buffers)
|
||||
{
|
||||
bufusage_start = pgBufferUsage;
|
||||
}
|
||||
#endif
|
||||
|
||||
INSTR_TIME_SET_CURRENT(planstart);
|
||||
|
||||
|
@ -1132,9 +1161,19 @@ CitusExplainOneQuery(Query *query, int cursorOptions, IntoClause *into,
|
|||
INSTR_TIME_SET_CURRENT(planduration);
|
||||
INSTR_TIME_SUBTRACT(planduration, planstart);
|
||||
|
||||
#if PG_VERSION_NUM >= PG_VERSION_13
|
||||
|
||||
/* calc differences of buffer counters. */
|
||||
if (es->buffers)
|
||||
{
|
||||
memset(&bufusage, 0, sizeof(BufferUsage));
|
||||
BufferUsageAccumDiff(&bufusage, &pgBufferUsage, &bufusage_start);
|
||||
}
|
||||
#endif
|
||||
|
||||
/* run it (if needed) and produce output */
|
||||
ExplainOnePlanCompat(plan, into, es, queryString, params, queryEnv,
|
||||
&planduration);
|
||||
&planduration, (es->buffers ? &bufusage : NULL));
|
||||
}
|
||||
|
||||
|
||||
|
@ -1454,7 +1493,13 @@ ExplainOneQuery(Query *query, int cursorOptions,
|
|||
{
|
||||
instr_time planstart,
|
||||
planduration;
|
||||
#if PG_VERSION_NUM >= PG_VERSION_13
|
||||
BufferUsage bufusage_start,
|
||||
bufusage;
|
||||
|
||||
if (es->buffers)
|
||||
bufusage_start = pgBufferUsage;
|
||||
#endif
|
||||
INSTR_TIME_SET_CURRENT(planstart);
|
||||
|
||||
/* plan the query */
|
||||
|
@ -1463,9 +1508,18 @@ ExplainOneQuery(Query *query, int cursorOptions,
|
|||
INSTR_TIME_SET_CURRENT(planduration);
|
||||
INSTR_TIME_SUBTRACT(planduration, planstart);
|
||||
|
||||
#if PG_VERSION_NUM >= PG_VERSION_13
|
||||
|
||||
/* calc differences of buffer counters. */
|
||||
if (es->buffers)
|
||||
{
|
||||
memset(&bufusage, 0, sizeof(BufferUsage));
|
||||
BufferUsageAccumDiff(&bufusage, &pgBufferUsage, &bufusage_start);
|
||||
}
|
||||
#endif
|
||||
/* run it (if needed) and produce output */
|
||||
ExplainOnePlanCompat(plan, into, es, queryString, params, queryEnv,
|
||||
&planduration);
|
||||
&planduration, (es->buffers ? &bufusage : NULL));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -36,8 +36,8 @@
|
|||
#define standard_planner_compat(a, c, d) standard_planner(a, NULL, c, d)
|
||||
#define getOwnedSequencesCompat(a, b) getOwnedSequences(a)
|
||||
#define CMDTAG_SELECT_COMPAT CMDTAG_SELECT
|
||||
#define ExplainOnePlanCompat(a, b, c, d, e, f, g) ExplainOnePlan(a, b, c, d, e, f, g, \
|
||||
NULL)
|
||||
#define ExplainOnePlanCompat(a, b, c, d, e, f, g, h) ExplainOnePlan(a, b, c, d, e, f, g, \
|
||||
h)
|
||||
#define SetListCellPtr(a, b) ((a)->ptr_value = (b))
|
||||
#define RangeTableEntryFromNSItem(a) ((a)->p_rte)
|
||||
#define QueryCompletionCompat QueryCompletion
|
||||
|
@ -49,7 +49,7 @@
|
|||
#define standard_planner_compat(a, c, d) standard_planner(a, c, d)
|
||||
#define CMDTAG_SELECT_COMPAT "SELECT"
|
||||
#define getOwnedSequencesCompat(a, b) getOwnedSequences(a, b)
|
||||
#define ExplainOnePlanCompat(a, b, c, d, e, f, g) ExplainOnePlan(a, b, c, d, e, f, g)
|
||||
#define ExplainOnePlanCompat(a, b, c, d, e, f, g, h) ExplainOnePlan(a, b, c, d, e, f, g)
|
||||
#define SetListCellPtr(a, b) ((a)->data.ptr_value = (b))
|
||||
#define RangeTableEntryFromNSItem(a) (a)
|
||||
#define QueryCompletionCompat char
|
||||
|
|
Loading…
Reference in New Issue