> > My initial thought is that this patch does not remove the issue of
> > loading the entire query text (just to return one or a few entries).
>
> This patch is not intended to address the issue of loading the file
> with query texts. We only try to avoid forming and handling tuples
> that we don't really need. Forming a tuple in
> pg_stat_statements_internal() includes calling CStringGetTextDatum(),
> which allocates memory and copies the query text. Avoiding that for
> queries we don't need makes a big difference already.
Yes, but my point is, if someone repeatedly lookup up pg_stat_statements
with filters, they will end up loading the query text multiple times.
for example:
````
select * from pg_stat_statements where query_id in (10000, 20000, 30000);
```
will only load the query text once to retrieve these 3 query IDs.
If I instead do this, with the proposed patch:
```
select * from pg_stat_statements(true, queryid=>10000);
select * from pg_stat_statements(true, queryid=>20000);
select * from pg_stat_statements(true, queryid=>30000);
or
select * from pg_stat_activity a, pg_stat_statements(true, queryid=>a.query_id);
```
I will have to load the query text file into memory for every invocation of
pg_stat_statements.
> > For what it is worth, I have been thinking about what it would take to
> > move query texts into shared memory, which could make this type of
> > filtering more practical.
>
> As far as I can tell, pg_stat_statements is storing query texts in an
> external file to not have problems with long query texts. Here is a
> quote from the docs:
>
> > The representative query texts are kept in an external disk file, and
> > do not consume shared memory. Therefore, even very lengthy query texts
> > can be stored successfully.
pg_stat_statements_internal must load the file when showtext = true, which
is the default.
```
qbuffer = qtext_load_file(&qbuffer_size);
```
--
Sami Imseih
Amazon Web Services (AWS)