PoC-injection-point-test-for-pg_log_query_plan.txt
text/x-diff
Filename: PoC-injection-point-test-for-pg_log_query_plan.txt
Type: text/x-diff
Part: 1
Patch
Same data as JSON:
GET /api/v1/attachments/:id/patch
the parsed metadata as JSON — format, series position, per-file stats; never the diff bytes.
API reference →
Format: unified
| File | + | − |
|---|---|---|
| src/backend/commands/dynamic_explain.c | 3 | 0 |
| src/backend/executor/execMain.c | 3 | 0 |
| src/test/isolation/expected/pg_log_query_plan.out | 36 | 0 |
| src/test/isolation/specs/pg_log_query_plan.spec | 27 | 0 |
diff --git a/src/backend/commands/dynamic_explain.c b/src/backend/commands/dynamic_explain.c
index b21a51aafe4..41951966838 100644
--- a/src/backend/commands/dynamic_explain.c
+++ b/src/backend/commands/dynamic_explain.c
@@ -22,6 +22,7 @@
#include "storage/proc.h"
#include "storage/procarray.h"
#include "utils/backend_status.h"
+#include "utils/injection_point.h"
/* Is plan node wrapping for query plan logging currently in progress? */
static bool WrapNodesInProgress = false;
@@ -80,6 +81,8 @@ LogQueryPlan(void)
ExplainStringAssemble(es, queryDesc, es->format, 0, -1);
+ INJECTION_POINT("logging-query-plan", NULL);
+
ereport(LOG_SERVER_ONLY,
errmsg("query and its plan running on backend with PID %d are:\n%s",
MyProcPid, es->str->data));
diff --git a/src/backend/executor/execMain.c b/src/backend/executor/execMain.c
index df5b55ae64d..db792e97c4b 100644
--- a/src/backend/executor/execMain.c
+++ b/src/backend/executor/execMain.c
@@ -59,6 +59,7 @@
#include "tcop/utility.h"
#include "utils/acl.h"
#include "utils/backend_status.h"
+#include "utils/injection_point.h"
#include "utils/lsyscache.h"
#include "utils/partcache.h"
#include "utils/rls.h"
@@ -333,6 +334,8 @@ standard_ExecutorRun(QueryDesc *queryDesc,
oldQueryDesc = GetCurrentQueryDesc();
SetCurrentQueryDesc(queryDesc);
+ INJECTION_POINT("standard-executor-run", NULL);
+
/*
* Switch into per-query memory context
*/
diff --git a/src/test/isolation/expected/pg_log_query_plan.out b/src/test/isolation/expected/pg_log_query_plan.out
new file mode 100644
index 00000000000..2d126785c18
--- /dev/null
+++ b/src/test/isolation/expected/pg_log_query_plan.out
@@ -0,0 +1,36 @@
+Parsed test spec with 2 sessions
+
+starting permutation: query1 logreq2 wakeup2 detach2
+injection_points_attach
+-----------------------
+
+(1 row)
+
+step query1: SELECT COUNT(*) FROM foo; <waiting ...>
+step logreq2: SELECT pg_log_query_plan(pid) FROM pg_stat_activity WHERE backend_type = 'client backend';
+pg_log_query_plan
+-----------------
+t
+t
+t
+(3 rows)
+
+step wakeup2: SELECT injection_points_wakeup('standard-executor-run');
+injection_points_wakeup
+-----------------------
+
+(1 row)
+
+s1: NOTICE: notice triggered for injection point logging-query-plan
+step query1: <... completed>
+count
+-----
+ 100
+(1 row)
+
+step detach2: SELECT injection_points_detach('standard-executor-run');
+injection_points_detach
+-----------------------
+
+(1 row)
+
diff --git a/src/test/isolation/specs/pg_log_query_plan.spec b/src/test/isolation/specs/pg_log_query_plan.spec
new file mode 100644
index 00000000000..11c344d9fdd
--- /dev/null
+++ b/src/test/isolation/specs/pg_log_query_plan.spec
@@ -0,0 +1,27 @@
+# pg_log_query_plan() test
+
+setup
+{
+ CREATE EXTENSION injection_points;
+ CREATE TABLE foo AS SELECT generate_series(1,100);
+}
+teardown
+{
+ DROP EXTENSION injection_points;
+ DROP TABLE foo;
+}
+
+session s1
+setup {
+ SELECT injection_points_set_local();
+ SELECT injection_points_attach('logging-query-plan', 'notice');
+ SELECT injection_points_attach('standard-executor-run', 'wait');
+}
+step query1 { SELECT COUNT(*) FROM foo; }
+
+session s2
+step logreq2 { SELECT pg_log_query_plan(pid) FROM pg_stat_activity WHERE backend_type = 'client backend'; }
+step wakeup2 { SELECT injection_points_wakeup('standard-executor-run'); }
+step detach2 { SELECT injection_points_detach('standard-executor-run'); }
+
+permutation query1 logreq2 wakeup2 detach2