pg_stat_statements: rows not updated for CREATE TABLE AS SELECT statements

From: legrand legrand <legrand_legrand(at)hotmail(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: pg_stat_statements: rows not updated for CREATE TABLE AS SELECT statements
Date: 2020-03-15 17:35:55
Message-ID: 1584293755198-0.post@n3.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers

Hello,
it seems that column "rows" is not updated after CREATE TABLE AS SELECT
statements.

pg13devel (snapshot 2020-03-14)
postgres=# select name,setting from pg_settings where name like 'pg_stat%';
name | setting
----------------------------------+---------
pg_stat_statements.max | 5000
pg_stat_statements.save | on
pg_stat_statements.track | all
pg_stat_statements.track_utility | on
(4 rows)

postgres=# select pg_stat_statements_reset();
pg_stat_statements_reset
--------------------------

(1 row)

postgres=# create table ctas as select * from pg_class;
SELECT 386
postgres=# select query,calls,rows from pg_stat_statements where query like
'create table ctas%';
query | calls | rows
---------------------------------------------+-------+------
create table ctas as select * from pg_class | 1 | 0
(1 row)

after modifying the following line in pg_stat_statements.c

rows = (qc && qc->commandTag == CMDTAG_COPY) ? qc->nprocessed : 0;
into
rows = (qc && (qc->commandTag == CMDTAG_COPY
|| qc->commandTag == CMDTAG_SELECT)
) ? qc->nprocessed : 0;

column rows seems properly updated.

What do you think about that fix ?
Thanks in advance
Regards
PAscal

--
Sent from: https://www.postgresql-archive.org/PostgreSQL-bugs-f2117394.html

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Amit Langote 2020-03-16 02:27:55 Re: BUG #16302: too many range table entries - when count partition table(65538 childs)
Previous Message Andres Freund 2020-03-15 00:35:41 Re: BUG #16293: postgres segfaults and returns SQLSTATE 08006

Browse pgsql-hackers by date

  From Date Subject
Next Message Pavel Stehule 2020-03-15 18:23:36 Re: proposal: new polymorphic types - commontype and commontypearray
Previous Message James Coleman 2020-03-15 17:35:32 Re: [PATCH] Incremental sort (was: PoC: Partial sort)