Skip site navigation (1) Skip section navigation (2)

Re: contrib/pg_stat_statements

From: ITAGAKI Takahiro <itagaki(dot)takahiro(at)oss(dot)ntt(dot)co(dot)jp>
To: Martin Pihlak <martin(dot)pihlak(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: contrib/pg_stat_statements
Date: 2008-10-30 11:45:04
Message-ID: 20081030201555.2A22.52131E4D@oss.ntt.co.jp (view raw or flat)
Thread:
Lists: pgsql-hackers
Martin Pihlak <martin(dot)pihlak(at)gmail(dot)com> wrote:

> Attached is a patch that adds sourceText to QueryDesc.

It worked fine surprisingly :) . Internal and C functions don't use
executor, so we can ignore trivial function calls (ex. operators).
Furthermore, it is ok if QueryDesc doesn't have queryText
because the result is counted up in the upper statement.

> But is the idea of extending QueryDesc generally acceptable? Is it OK
> to make a copy of the query string?

The only thing I'm worried about is that QueryDesc lives longer than
its queryText. Can I assume it never occurs?

> I tested with modified pg_stat_statements (removed toplevel checks),

Stack of counters would be better. The attached is modified to do so.
It might be worth thinking about adding counters that are equivalent
to total_time and self_time in in pg_stat_user_functions.

=# CREATE OR REPLACE FUNCTION plfn(integer) RETURNS bigint AS
$$
DECLARE
  i bigint;
BEGIN
  SELECT count(*) INTO i FROM pg_class;
  SELECT count(*) INTO i FROM pg_class;
  SELECT count(*) INTO i FROM generate_series(1, $1);
  RETURN i;
END;
$$
LANGUAGE plpgsql;

=# SELECT sum(plfn(10000)) FROM generate_series(1, 100);
=# SELECT query, calls, total_time, rows FROM pg_stat_statements;

                         query                         | calls | total_time | rows
-------------------------------------------------------+-------+------------+------
 SELECT sum(plfn(10000)) FROM generate_series(1, 100); |     1 |        428 |    1
 SELECT count(*) FROM pg_class                         |   200 |         32 |  200
 SELECT count(*) FROM generate_series(1,  $1 )         |   100 |        309 |  100
(3 rows)

Regards,
---
ITAGAKI Takahiro
NTT Open Source Software Center


Attachment: pg_stat_statements.c
Description: application/octet-stream (21.3 KB)

In response to

Responses

pgsql-hackers by date

Next:From: Tom LaneDate: 2008-10-30 12:16:41
Subject: Re: pre-MED
Previous:From: Markus WannerDate: 2008-10-30 11:20:19
Subject: Re: Postgres-R pacth

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group