- Notifications
You must be signed in to change notification settings - Fork41
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
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
2 commits Select commitHold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
117 changes: 91 additions & 26 deletionspg_wait_sampling.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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; | ||
| @@ -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); | ||
| /* | ||
| @@ -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; | ||
| } | ||
| @@ -865,27 +878,41 @@ pgws_planner_hook(Query *parse, | ||
| int cursorOptions, | ||
| ParamListInfo boundParams) | ||
| { | ||
| PlannedStmt *result; | ||
| int i = MyProc - ProcGlobal->allProcs; | ||
| if (nesting_level == 0) | ||
| pgws_proc_queryids[i] = parse->queryId; | ||
| 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, | ||
| #endif | ||
| cursorOptions, boundParams); | ||
| else | ||
| result = standard_planner(parse, | ||
| #if PG_VERSION_NUM >= 130000 | ||
| query_string, | ||
| #endif | ||
| 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(); | ||
shinderuk marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| return result; | ||
| } | ||
| /* | ||
| @@ -894,29 +921,67 @@ pgws_planner_hook(Query *parse, | ||
| static void | ||
| pgws_ExecutorStart(QueryDesc *queryDesc, int eflags) | ||
| { | ||
| 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) | ||
| { | ||
| int i = MyProc - ProcGlobal->allProcs; | ||
| if (nesting_level == 0) | ||
| pgws_proc_queryids[i] = UINT64CONST(0); | ||
| if (prev_ExecutorEnd) | ||
| prev_ExecutorEnd(queryDesc); | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.