pgsql: Fix row tracking in pg_stat_statements with extended query proto

Поиск
Список
Период
Сортировка
От Michael Paquier
Тема pgsql: Fix row tracking in pg_stat_statements with extended query proto
Дата
Msg-id E1pkDVR-001Zd6-QT@gemulon.postgresql.org
обсуждение исходный текст
Список pgsql-committers
Fix row tracking in pg_stat_statements with extended query protocol

pg_stat_statements relies on EState->es_processed to count the number of
rows processed by ExecutorRun().  This proves to be a problem under the
extended query protocol when the result of a query is fetched through
more than one call of ExecutorRun(), as es_processed is reset each time
ExecutorRun() is called.  This causes pg_stat_statements to report the
number of rows calculated in the last execute fetch, rather than the
global sum of all the rows processed.

As pquery.c tells, this is a problem when a portal does not use
holdStore.  For example, DMLs with RETURNING would report a correct
tuple count as these do one execution cycle when the query is first
executed to fill in the portal's store with one ExecutorRun(), feeding
on the portal's store for each follow-up execute fetch depending on the
fetch size requested by the client.

The fix proposed for this issue is simple with the addition of an extra
counter in EState that's preserved across multiple ExecutorRun() calls,
incremented with the value calculated in es_processed.  This approach is
not back-patchable, unfortunately.

Note that libpq does not currently give any way to control the fetch
size when using the extended v3 protocol, meaning that in-core testing
is not possible yet.  This issue can be easily verified with the JDBC
driver, though, with *autocommit disabled*.  Hence, having in-core tests
requires more features, left for future discussion:
- At least two new libpq routines splitting PQsendQueryGuts(), one for
the bind/describe and a second for a series of execute fetches with a
custom fetch size, likely in a fashion similar to what JDBC does.
- A psql meta-command for the execute phase.  This part is not strictly
mandatory, still it could be handy.

Reported-by: Andrew Dunstan (original discovery by Simon Siggs)
Author: Sami Imseih
Reviewed-by: Tom Lane, Michael Paquier
Discussion: https://postgr.es/m/EBE6C507-9EB6-4142-9E4D-38B1673363A7@amazon.com
Discussion: https://postgr.es/m/c90890e7-9c89-c34f-d3c5-d5c763a34bd8@dunslane.net

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/1d477a907e63941b58508136f92ac0b5058b68ab

Modified Files
--------------
contrib/pg_stat_statements/pg_stat_statements.c | 2 +-
src/backend/executor/execMain.c                 | 9 ++++++++-
src/backend/executor/execUtils.c                | 1 +
src/include/nodes/execnodes.h                   | 5 ++++-
4 files changed, 14 insertions(+), 3 deletions(-)


В списке pgsql-committers по дате отправления:

Предыдущее
От: Andres Freund
Дата:
Сообщение: pgsql: bufmgr: Introduce infrastructure for faster relation extension
Следующее
От: David Rowley
Дата:
Сообщение: pgsql: Always make a BufferAccessStrategy for ANALYZE