Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.92) (envelope-from ) id 1jHRpT-0002Qo-S3 for pgsql-bugs@arkaria.postgresql.org; Thu, 26 Mar 2020 12:41:47 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1jHRpQ-0005qW-VR for pgsql-bugs@arkaria.postgresql.org; Thu, 26 Mar 2020 12:41:44 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1jHRpQ-0005qP-EC for pgsql-bugs@lists.postgresql.org; Thu, 26 Mar 2020 12:41:44 +0000 Received: from oss.nttdata.com ([49.212.34.109]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jHRpM-0002D7-HS for pgsql-bugs@postgresql.org; Thu, 26 Mar 2020 12:41:42 +0000 Received: from hnk.local (sp49-97-92-76.msc.spmode.ne.jp [49.97.92.76]) by oss.nttdata.com (Postfix) with ESMTPSA id 5138160535; Thu, 26 Mar 2020 21:41:35 +0900 (JST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.102.2 at oss.nttdata.com Subject: Re: pg_stat_statements: rows not updated for CREATE TABLE AS SELECT statements To: legrand legrand , pgsql-bugs@postgresql.org References: <1584293755198-0.post@n3.nabble.com> From: Fujii Masao Message-ID: Date: Thu, 26 Mar 2020 21:41:34 +0900 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 MIME-Version: 1.0 In-Reply-To: <1584293755198-0.post@n3.nabble.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 2020/03/16 2:35, legrand legrand wrote: > 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) Thanks for the report! Yeah, it seems worth improving this. > 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 ? The utility commands that return CMDTAG_SELECT are only CREATE TABLE AS SELECT and CREATE MATERIALIZED VIEW? I'd just like to confirm that there is no case where "rows" must not be counted when CMDTAG_SELECT is returned. BTW, "rows" should be updated when FETCH or MOVE is executed because each command returns or affects the rows? Regards, -- Fujii Masao NTT DATA CORPORATION Advanced Platform Technology Group Research and Development Headquarters