此查询 ID 由pg_stat_statements
扩展程序计算,请参阅contrib/pg_stat_statements/pg_stat_statements.c
这条评论解释了它是如何工作的:
As of Postgres 9.2, this module normalizes query entries. Normalization
is a process whereby similar queries, typically differing only in their
constants (though the exact rules are somewhat more subtle than that) are
recognized as equivalent, and are tracked as a single entry. This is
particularly useful for non-prepared queries.
Normalization is implemented by fingerprinting queries, selectively
serializing those fields of each query tree's nodes that are judged to be
essential to the query. This is referred to as a query jumble. This is
distinct from a regular serialization in that various extraneous
information is ignored as irrelevant or not essential to the query, such
as the collations of Vars and, most notably, the values of constants.
This jumble is acquired at the end of parse analysis of each query, and
a 32-bit hash of it is stored into the query's Query.queryId field.
The server then copies this value around, making it available in plan
tree(s) generated from the query. The executor can then use this value
to blame query costs on the proper queryId.