-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PG-592: Treat queries with different parent queries as separate entri…
…es (#403) * PG-592: Treat queries with different parent queries as separate entries 1. Previously pg_stat_monitor had a `topquery` and `topqueryid` field, but it was only a sample: it showed one of the top queries executing the specific query. With this change, the same entry executed by two different functions will result in two entries in the statistics table. 2. This also fixes a bug where the content of these field disappeared for every second query executed: previously the update function changed topqueryid to `0` if it was non zero, and changed it to the proper id when it was 0. This resulted in an alternating behavior, where for every second executed query the top query disappeared. After these changes, the top query is always shown. 3. The previous implementation also leaked dsa memory used to store the parent queries. This is now also fixed. * PG-502: Fixing review comments * dsa_free changed to assert as it can never happen * restructured the ifs to be cleaner Note: kept the two-level ifs, as that makes more sense with the assert Note: didn't convert nested_level checks to macro, as it is used differently at different parts of the code * PG-502: Fixing review comments * PG-592 Add regression test * Make test compatible with PG12 * Remove redundant line --------- Co-authored-by: Artem Gavrilov <[email protected]>
- Loading branch information
1 parent
1aa3081
commit 130d6b5
Showing
6 changed files
with
104 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,6 +45,7 @@ | |
*.mod* | ||
*.cmd | ||
.tmp_versions/ | ||
.deps/ | ||
modules.order | ||
Module.symvers | ||
Mkfile.old | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
CREATE EXTENSION pg_stat_monitor; | ||
SET pg_stat_monitor.pgsm_track='all'; | ||
SELECT pg_stat_monitor_reset(); | ||
pg_stat_monitor_reset | ||
----------------------- | ||
|
||
(1 row) | ||
|
||
CREATE OR REPLACE FUNCTION test() RETURNS VOID AS | ||
$$ | ||
BEGIN | ||
PERFORM 1 + 2; | ||
END; $$ language plpgsql; | ||
CREATE OR REPLACE FUNCTION test2() RETURNS VOID AS | ||
$$ | ||
BEGIN | ||
PERFORM 1 + 2; | ||
END; $$ language plpgsql; | ||
SELECT pg_stat_monitor_reset(); | ||
pg_stat_monitor_reset | ||
----------------------- | ||
|
||
(1 row) | ||
|
||
SELECT test(); | ||
test | ||
------ | ||
|
||
(1 row) | ||
|
||
SELECT test2(); | ||
test2 | ||
------- | ||
|
||
(1 row) | ||
|
||
SELECT 1 + 2; | ||
?column? | ||
---------- | ||
3 | ||
(1 row) | ||
|
||
SELECT left(query, 15) as query, calls, top_query, pgsm_query_id FROM pg_stat_monitor ORDER BY query, top_query COLLATE "C"; | ||
query | calls | top_query | pgsm_query_id | ||
-----------------+-------+-----------------+---------------------- | ||
SELECT 1 + 2 | 1 | SELECT test(); | 5193804135051352284 | ||
SELECT 1 + 2 | 1 | SELECT test2(); | 5193804135051352284 | ||
SELECT 1 + 2 | 1 | | 5193804135051352284 | ||
SELECT pg_stat_ | 1 | | 689150021118383254 | ||
SELECT test() | 1 | | -6801876889834540522 | ||
SELECT test2() | 1 | | 369102705908374543 | ||
(6 rows) | ||
|
||
DROP EXTENSION pg_stat_monitor; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
CREATE EXTENSION pg_stat_monitor; | ||
SET pg_stat_monitor.pgsm_track='all'; | ||
SELECT pg_stat_monitor_reset(); | ||
|
||
CREATE OR REPLACE FUNCTION test() RETURNS VOID AS | ||
$$ | ||
BEGIN | ||
PERFORM 1 + 2; | ||
END; $$ language plpgsql; | ||
|
||
CREATE OR REPLACE FUNCTION test2() RETURNS VOID AS | ||
$$ | ||
BEGIN | ||
PERFORM 1 + 2; | ||
END; $$ language plpgsql; | ||
|
||
SELECT pg_stat_monitor_reset(); | ||
SELECT test(); | ||
SELECT test2(); | ||
|
||
SELECT 1 + 2; | ||
SELECT left(query, 15) as query, calls, top_query, pgsm_query_id FROM pg_stat_monitor ORDER BY query, top_query COLLATE "C"; | ||
|
||
DROP EXTENSION pg_stat_monitor; |