Recently there was discussion #42 (comment) about unwanted usage of queryIds taken from PgBackendStatus entries in BackendStatusArray as they represent only top-level queries. But current implementation behave in similar manner: once queryId was kept all successive nested queries cannot submit their own queryIds.
The open question here - how to organize tracking queryIds for nested queries? @rjuju AFAICS in pg_stat_kcache this problem is also not solved - all inner queries rewrite queryId of previously executing queries before executor running. Maybe it makes sense to store queryId in some shared stack structure allocated for each process slot and using it keep/restore queryId for upper-level queries?