cursor use vs pg_stat_statements

From: Andrew Dunstan <andrew(at)dunslane(dot)net>
To: PostgreSQL Hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: cursor use vs pg_stat_statements
Date: 2021-10-19 19:24:33
Message-ID: c90890e7-9c89-c34f-d3c5-d5c763a34bd8@dunslane.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


The problem I'm writing about (h/t Simon Riggs for finding it) is
illustrated by the following snippet of java:

public static void runtest(Connection conn) throws Exception {
Statement stmt = conn.createStatement();
stmt.setFetchSize(10);
ResultSet rs = stmt.executeQuery("select oid, relfileid, relname from pg_class");
int count = 100;
while (rs.next() && count-- > 0) {
System.out.print(".");
}
rs.close();
stmt.commit();
stmt.close();
System.out.println("");
}

When called, this prints out a line with 100 dots showing 100 lines were
fetched, but pg_stat_statements shows this:

query | select oid, relfilenode, relname from pg_class
calls | 1
rows  | 10

suggesting only 10 rows were returned. It appears that only the first
"EXECUTE 10" command against the portal is counted. At the very least
this is a POLA violation, and it seems to be a bug. Maybe it's
documented somewhere but if so it's not obvious to me.

cheers

andrew

--
Andrew Dunstan
EDB: https://www.enterprisedb.com

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jeff Davis 2021-10-19 19:28:20 Re: Delegating superuser tasks to new security roles (Was: Granting control of SUSET gucs to non-superusers)
Previous Message Tom Lane 2021-10-19 19:22:15 Re: [RFC] building postgres with meson