- Notifications
You must be signed in to change notification settings - Fork4.9k
Commit8a1459f
committed
pg_stat_statements: Fix parameter number gaps in normalized queries
pg_stat_statements anticipates that certain constant locations may berecorded multiple times and attempts to avoid calculating a length forthese locations in fill_in_constant_lengths().However, during generate_normalized_query() where normalized querystrings are generated, these locations are not excluded fromconsideration. This could increment the parameter number counter forevery recorded occurrence at such a location, leading to an incorrectnormalization in certain cases with gaps in the numbers reported.For example, take this query:SELECT WHERE '1' IN ('2'::int, '3'::int::text)Before this commit, it would be normalized like that, with gaps in theparameter numbers:SELECT WHERE $1 IN ($3::int, $4::int::text)However the correct, less confusing one should be like that:SELECT WHERE $1 IN ($2::int, $3::int::text)This commit fixes the computation of the parameter numbers to track thenumber of constants replaced with an $n by a separate counter instead ofthe iterator used to loop through the list of locations.The underlying query IDs are not changed, neither are the normalizedstrings for existing PGSS hash entries. New entries with freshnormalized queries would automatically get reshaped based on the newparameter numbering.Issue discovered while discussing a separate problem for HEAD, but thisaffects all the stable branches.Author: Sami Imseih <samimseih@gmail.com>Discussion:https://postgr.es/m/CAA5RZ0tzxvWXsacGyxrixdhy3tTTDfJQqxyFBRFh31nNHBQ5qA@mail.gmail.comBackpatch-through: 131 parent0c09922 commit8a1459f
File tree
3 files changed
+40
-1
lines changed- contrib/pg_stat_statements
- expected
- sql
3 files changed
+40
-1
lines changedLines changed: 29 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
398 | 398 |
| |
399 | 399 |
| |
400 | 400 |
| |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
401 | 430 |
| |
402 | 431 |
| |
403 | 432 |
| |
|
Lines changed: 3 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
2640 | 2640 |
| |
2641 | 2641 |
| |
2642 | 2642 |
| |
| 2643 | + | |
2643 | 2644 |
| |
2644 | 2645 |
| |
2645 | 2646 |
| |
| |||
2683 | 2684 |
| |
2684 | 2685 |
| |
2685 | 2686 |
| |
2686 |
| - | |
| 2687 | + | |
| 2688 | + | |
2687 | 2689 |
| |
2688 | 2690 |
| |
2689 | 2691 |
| |
|
Lines changed: 8 additions & 0 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
201 | 201 |
| |
202 | 202 |
| |
203 | 203 |
| |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
204 | 212 |
| |
205 | 213 |
| |
206 | 214 |
| |
|
0 commit comments
Comments
(0)