On Mon, Aug 12, 2019 at 2:52 PM Evgeniy Efimkin <efimkin@yandex-team.ru> wrote:
>
> Hi!
> What about adding new column in pg_stat_statements e.g. sql_id it's hash from normalized query. Аnd add function
whichget that hash (using raw_parser, raw_expression_tree_walker) for any query
> `
> postgres=# select get_queryid('select 1');
> get_queryid
> -------------
> 680388963
> (1 row)
One problem with pg_stat_statement's normalized query is that it's not
stable, it's storing the normalized version of the first query string
passed when an entry is created. So you could have different strings
depending on whether the query was fully qualified or relying on
search path for instance.
Exposing the queryid computation at SQL level has already been
proposed, and FWIW I'm all for it.