-
Notifications
You must be signed in to change notification settings - Fork 117
Open
Description
This can be reproduce in psql
create extension pg_hint_plan;set pg_hint_plan.enable_hint_table = on;
postgres=# select version();
version
-----------------------------------------------------------------------------------------------------------------------------
PostgreSQL 18.1 (Homebrew) on aarch64-apple-darwin24.6.0, compiled by Apple clang version 17.0.0 (clang-1700.4.4.1), 64-bit
(1 row)
Session 1
load 'pg_hint_plan';
create extension pg_hint_plan;
set pg_hint_plan.enable_hint_table = on;
postgres=# set pg_hint_plan.enable_hint_table = on;
SET
postgres=# select pg_sleep(10) from t2;
pg_sleep
----------
(1 row)
postgres=# select pg_sleep(10) from t3;
pg_sleep
----------
(1 row)
Session 2 monitoring process
postgres=# select query_id, query from pg_stat_activity where pid = 15282;
query_id | query
---------------------+------------------------------
9119088274641895962 | select pg_sleep(10) from t2;
(1 row)
postgres=# select query_id, query from pg_stat_activity where pid = 15282;
query_id | query
---------------------+------------------------------
9119088274641895962 | select pg_sleep(10) from t3;
(1 row)
The hint_plan.hints table lookup query (shown below) sets backendStatus first, preventing the actual user query from setting its own query_id since backendStatus is already non-zero:
const char *search_query =
"SELECT hints "
" FROM hint_plan.hints "
" WHERE query_id = $1 "
" AND ( application_name = $2 "
" OR application_name = '' ) "
" ORDER BY application_name DESC";
p = SPI_prepare(search_query, 2, argtypes);
plan = SPI_saveplan(p);
SPI_execute_plan(plan, values, nulls, true, 1);
This explains why query_id 9119088274641895962 persists across different queries (pg_sleep(10) from t2 and pg_sleep(10) from t3) when pg_hint_plan.enable_hint_table is enabled.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels