Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sampling doesn't work on the Global activity/Parallel activity/Backend age views #254

Open
marco44 opened this issue Jan 22, 2025 · 0 comments · May be fixed by #255
Open

Sampling doesn't work on the Global activity/Parallel activity/Backend age views #254

marco44 opened this issue Jan 22, 2025 · 0 comments · May be fixed by #255
Assignees

Comments

@marco44
Copy link
Contributor

marco44 commented Jan 22, 2025

It comes from this query:

FROM 
            (SELECT pgsa_history.srvid,
              dense_rank() OVER (ORDER BY pgsa_history.ts) AS number,
              count(*) OVER () AS total,
              ts,
              datid,
              cur_txid,
              backend_xid,
              backend_xmin,
              backend_start,
              xact_start,
              query_start,
              state,
              leader_pid
              FROM (
                SELECT *
                FROM (
                  SELECT srvid, (unnest(records)).*
                  FROM public.powa_stat_activity_history pgsah
                  WHERE coalesce_range && tstzrange('2025-01-22 08:23:04+0100', '2025-01-22 09:23:04+0100', '[]')
                  AND pgsah.srvid = '1'
                ) AS unnested
                WHERE ts <@ tstzrange('2025-01-22 08:23:04+0100', '2025-01-22 09:23:04+0100', '[]')
                UNION ALL
                SELECT srvid, (record).*
                FROM public.powa_stat_activity_history_current pgsac
                WHERE (pgsac.record).ts <@ tstzrange('2025-01-22 08:23:04+0100', '2025-01-22 09:23:04+0100', '[]')
                AND pgsac.srvid = '1'
              ) AS pgsa_history
              
            ) AS pgsa
            WHERE number % ( int8larger((total)/(100+1),1) ) = 0;

The problem is that "total" is not the amount of samples we want to return, it's the total count of records (and we have one record per active session in the snapshot. So If you have 100 sessions, total is off by a factor of 100 for the sampling, and you end up with 1 sample instead of 100

PR incoming

@marco44 marco44 self-assigned this Jan 22, 2025
marco44 added a commit that referenced this issue Jan 22, 2025
It wrongly computes the sampling: the "total" column is not correct in
this context: we (most of the time) have more than 1 record per sample.
If you have 100 sessions, the sampling will be off by a factor of 100,
and you'll end up with only 1 sample

It's a bit ugly to fix, because we need another subquery...

Closes #254
@marco44 marco44 linked a pull request Jan 22, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant