forked frompostgres/postgres
- Notifications
You must be signed in to change notification settings - Fork6
Commit1d477a9
committed
Fix row tracking in pg_stat_statements with extended query protocol
pg_stat_statements relies on EState->es_processed to count the number ofrows processed by ExecutorRun(). This proves to be a problem under theextended query protocol when the result of a query is fetched throughmore than one call of ExecutorRun(), as es_processed is reset each timeExecutorRun() is called. This causes pg_stat_statements to report thenumber of rows calculated in the last execute fetch, rather than theglobal sum of all the rows processed.As pquery.c tells, this is a problem when a portal does not useholdStore. For example, DMLs with RETURNING would report a correcttuple count as these do one execution cycle when the query is firstexecuted to fill in the portal's store with one ExecutorRun(), feedingon the portal's store for each follow-up execute fetch depending on thefetch size requested by the client.The fix proposed for this issue is simple with the addition of an extracounter in EState that's preserved across multiple ExecutorRun() calls,incremented with the value calculated in es_processed. This approach isnot back-patchable, unfortunately.Note that libpq does not currently give any way to control the fetchsize when using the extended v3 protocol, meaning that in-core testingis not possible yet. This issue can be easily verified with the JDBCdriver, though, with *autocommit disabled*. Hence, having in-core testsrequires more features, left for future discussion:- At least two new libpq routines splitting PQsendQueryGuts(), one forthe bind/describe and a second for a series of execute fetches with acustom fetch size, likely in a fashion similar to what JDBC does.- A psql meta-command for the execute phase. This part is not strictlymandatory, still it could be handy.Reported-by: Andrew Dunstan (original discovery by Simon Siggs)Author: Sami ImseihReviewed-by: Tom Lane, Michael PaquierDiscussion:https://postgr.es/m/EBE6C507-9EB6-4142-9E4D-38B1673363A7@amazon.comDiscussion:https://postgr.es/m/c90890e7-9c89-c34f-d3c5-d5c763a34bd8@dunslane.net1 parent31966b1 commit1d477a9
File tree
4 files changed
+14
-3
lines changed- contrib/pg_stat_statements
- src
- backend/executor
- include/nodes
4 files changed
+14
-3
lines changedLines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
1060 | 1060 |
| |
1061 | 1061 |
| |
1062 | 1062 |
| |
1063 |
| - | |
| 1063 | + | |
1064 | 1064 |
| |
1065 | 1065 |
| |
1066 | 1066 |
| |
|
Lines changed: 8 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
289 | 289 |
| |
290 | 290 |
| |
291 | 291 |
| |
292 |
| - | |
| 292 | + | |
| 293 | + | |
293 | 294 |
| |
294 | 295 |
| |
295 | 296 |
| |
| |||
372 | 373 |
| |
373 | 374 |
| |
374 | 375 |
| |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
375 | 382 |
| |
376 | 383 |
| |
377 | 384 |
| |
|
Lines changed: 1 addition & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
147 | 147 |
| |
148 | 148 |
| |
149 | 149 |
| |
| 150 | + | |
150 | 151 |
| |
151 | 152 |
| |
152 | 153 |
| |
|
Lines changed: 4 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
661 | 661 |
| |
662 | 662 |
| |
663 | 663 |
| |
664 |
| - | |
| 664 | + | |
| 665 | + | |
| 666 | + | |
| 667 | + | |
665 | 668 |
| |
666 | 669 |
| |
667 | 670 |
| |
|
0 commit comments
Comments
(0)