pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: kasahara.tatsuhito@gmail.com
To: pgsql-bugs@postgresql.org
Subject: BUG #13979: Strange pg_stat_statements results with PREPARE/EXECUTE
Date: Tue, 23 Feb 2016 08:24:38 +0000
Message-ID: <20160223082438.8550.39180@wrigleys.postgresql.org> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>

The following bug has been logged on the website:

Bug reference:      13979
Logged by:          Kasahara Tatsuhito
Email address:      kasahara.tatsuhito@gmail.com
PostgreSQL version: 9.5.1
Operating system:   RHEL
Description:        

Hi, I noticed that in some cases pg_stat_statements shows strange results.
(example)

=# CREATE TABLE tt(c1 int);
=# INSERT INTO tt SELECT generate_series(1,10);
=# SELECT pg_stat_statements_reset();

Then, performed simple SELECTs via java. (see the end of this mail) 
After that, I got the following pg_stat_statements result, and ISTM it's
reasonable.

=# SELECT queryid, calls, query FROM pg_stat_statements WHERE query LIKE
'%tt%';
  queryid  | calls |             query
-----------+-------+--------------------------------
 575935600 |    10 | SELECT * FROM tt WHERE c1 = $1


Next, reset the pg_stat_statements and performed PREPARE and EXECUTE via
psql. 

=# SELECT pg_stat_statements_reset();
=# PREPARE p1(int) AS SELECT * FROM tt WHERE c1 = $1;
=# EXECUTE p1(1);
=# SELECT queryid, calls, query FROM pg_stat_statements WHERE query LIKE
'%tt%';
  queryid  | calls |                       query
-----------+-------+----------------------------------------------------
 575935600 |     1 | PREPARE p1(int) AS SELECT * FROM tt WHERE c1 = $1;
(1 row)

Then, performed same SELECTs via java.
After that,  I got a bit strange pg_stat_statements result..

=# SELECT queryid, calls, query FROM pg_stat_statements WHERE query LIKE
'%tt%';
  queryid  | calls |                       query
-----------+-------+----------------------------------------------------
 575935600 |    11 | PREPARE p1(int) AS SELECT * FROM tt WHERE c1 = $1;
(1 row)


I'm not sure it's expected behaviors, but seems a bug.

Best regards,

// Java Test code
import java.lang.*;
import java.sql.*;

class Test {
    public static void main(String[] args) {
            String driver = "org.postgresql.Driver";
            String url =
"jdbc:postgresql://localhost/postgres?user=postgres&ApplicationName=my_jdbc_test";
        try{
            Connection con = DriverManager.getConnection(url);
            con.setAutoCommit(false);
            String sql1 = "SELECT * FROM tt WHERE c1 = ?";
            PreparedStatement ps1 = con.prepareStatement(sql1);

            for (int i=1; i<=10; i++) {
                ps1.setInt(1,i);
                ResultSet rs = ps1.executeQuery();
                while(rs.next()){
                    System.out.println("results c1:" + rs.getInt(1));
                }
            }

            con.commit();
            ps1.close();
            con.close();
            }catch (Exception e){
                e.printStackTrace();
            }
    }
}



-- 
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs



view thread (7+ messages)  latest in thread

Message-ID: <20160223082438.8550.39180@wrigleys.postgresql.org>
Permalink:  ../20160223082438.8550.39180@wrigleys.postgresql.org/
Also on:    postgresql.org/message-id/20160223082438.8550.39180@wrigleys.postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: kasahara.tatsuhito@gmail.com
  Subject: Re: BUG #13979: Strange pg_stat_statements results with PREPARE/EXECUTE
  In-Reply-To: <20160223082438.8550.39180@wrigleys.postgresql.org>
  References: <20160223082438.8550.39180@wrigleys.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox