Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Make it so subqueries do not rewrite top-level queryId#78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
shinderuk merged 2 commits intomasterfromtrack_top_level_queryid
Jun 17, 2024
Merged
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
117 changes: 91 additions & 26 deletionspg_wait_sampling.c
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -43,9 +43,14 @@ static bool shmem_initialized = false;

/* Hooks */
static ExecutorStart_hook_typeprev_ExecutorStart = NULL;
static ExecutorRun_hook_type prev_ExecutorRun = NULL;
static ExecutorFinish_hook_type prev_ExecutorFinish = NULL;
static ExecutorEnd_hook_typeprev_ExecutorEnd = NULL;
static planner_hook_typeplanner_hook_next = NULL;

/* Current nesting depth of planner/Executor calls */
static int nesting_level = 0;

/* Pointers to shared memory objects */
shm_mq *pgws_collector_mq = NULL;
uint64 *pgws_proc_queryids = NULL;
Expand All@@ -67,6 +72,10 @@ static PlannedStmt *pgws_planner_hook(Query *parse,
#endif
int cursorOptions, ParamListInfo boundParams);
static void pgws_ExecutorStart(QueryDesc *queryDesc, int eflags);
static void pgws_ExecutorRun(QueryDesc *queryDesc,
ScanDirection direction,
uint64 count, bool execute_once);
static void pgws_ExecutorFinish(QueryDesc *queryDesc);
static void pgws_ExecutorEnd(QueryDesc *queryDesc);

/*
Expand DownExpand Up@@ -395,6 +404,10 @@ _PG_init(void)
planner_hook= pgws_planner_hook;
prev_ExecutorStart= ExecutorStart_hook;
ExecutorStart_hook= pgws_ExecutorStart;
prev_ExecutorRun= ExecutorRun_hook;
ExecutorRun_hook= pgws_ExecutorRun;
prev_ExecutorFinish= ExecutorFinish_hook;
ExecutorFinish_hook= pgws_ExecutorFinish;
prev_ExecutorEnd= ExecutorEnd_hook;
ExecutorEnd_hook= pgws_ExecutorEnd;
}
Expand DownExpand Up@@ -865,27 +878,41 @@ pgws_planner_hook(Query *parse,
int cursorOptions,
ParamListInfo boundParams)
{
if (MyProc)
{
int i = MyProc - ProcGlobal->allProcs;
if (!pgws_proc_queryids[i])
pgws_proc_queryids[i] = parse->queryId;
PlannedStmt *result;
int i = MyProc - ProcGlobal->allProcs;
if (nesting_level == 0)
pgws_proc_queryids[i] = parse->queryId;

}

/* Invoke original hook if needed */
if (planner_hook_next)
return planner_hook_next(parse,
nesting_level++;
PG_TRY();
{
/* Invoke original hook if needed */
if (planner_hook_next)
result = planner_hook_next(parse,
#if PG_VERSION_NUM >= 130000
query_string,
query_string,
#endif
cursorOptions, boundParams);

return standard_planner(parse,
cursorOptions, boundParams);
else
result = standard_planner(parse,
#if PG_VERSION_NUM >= 130000
query_string,
query_string,
#endif
cursorOptions, boundParams);
cursorOptions, boundParams);
nesting_level--;
if (nesting_level == 0)
pgws_proc_queryids[i] = UINT64CONST(0);
}
PG_CATCH();
{
nesting_level--;
if (nesting_level == 0)
pgws_proc_queryids[i] = UINT64CONST(0);
PG_RE_THROW();
}
PG_END_TRY();

return result;
}

/*
Expand All@@ -894,29 +921,67 @@ pgws_planner_hook(Query *parse,
static void
pgws_ExecutorStart(QueryDesc *queryDesc, int eflags)
{
int i;

if (MyProc)
{
i = MyProc - ProcGlobal->allProcs;
if (!pgws_proc_queryids[i])
pgws_proc_queryids[i] = queryDesc->plannedstmt->queryId;
}
int i = MyProc - ProcGlobal->allProcs;
if (nesting_level == 0)
pgws_proc_queryids[i] = queryDesc->plannedstmt->queryId;

if (prev_ExecutorStart)
prev_ExecutorStart(queryDesc, eflags);
else
standard_ExecutorStart(queryDesc, eflags);
}

static void
pgws_ExecutorRun(QueryDesc *queryDesc,
ScanDirection direction,
uint64 count, bool execute_once)
{
nesting_level++;
PG_TRY();
{
if (prev_ExecutorRun)
prev_ExecutorRun(queryDesc, direction, count, execute_once);
else
standard_ExecutorRun(queryDesc, direction, count, execute_once);
nesting_level--;
}
PG_CATCH();
{
nesting_level--;
PG_RE_THROW();
}
PG_END_TRY();
}

static void
pgws_ExecutorFinish(QueryDesc *queryDesc)
{
nesting_level++;
PG_TRY();
{
if (prev_ExecutorFinish)
prev_ExecutorFinish(queryDesc);
else
standard_ExecutorFinish(queryDesc);
nesting_level--;
}
PG_CATCH();
{
nesting_level--;
PG_RE_THROW();
}
PG_END_TRY();
}

/*
* ExecutorEnd hook: clear queryId
*/
static void
pgws_ExecutorEnd(QueryDesc *queryDesc)
{
if (MyProc)
pgws_proc_queryids[MyProc - ProcGlobal->allProcs] = UINT64CONST(0);
int i = MyProc - ProcGlobal->allProcs;
if (nesting_level == 0)
pgws_proc_queryids[i] = UINT64CONST(0);

if (prev_ExecutorEnd)
prev_ExecutorEnd(queryDesc);
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp