X-Original-To: pgsql-jdbc-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 472719DC829 for ; Wed, 8 Mar 2006 14:40:48 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 50762-05 for ; Wed, 8 Mar 2006 14:40:47 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from uproxy.gmail.com (uproxy.gmail.com [66.249.92.192]) by postgresql.org (Postfix) with ESMTP id 2BEEA9DC82E for ; Wed, 8 Mar 2006 14:40:42 -0400 (AST) Received: by uproxy.gmail.com with SMTP id m3so124556ugc for ; Wed, 08 Mar 2006 10:40:43 -0800 (PST) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:to:subject:in-reply-to:mime-version:content-type:references; b=REpQCpPf024ciMB/NehrNtLRa5tHd4i5+3hO5YEIJtOT1VcylwtX+CTNxxvvCJpY3CdWi/kE5SkPVBOtIlh9xYXglKIalab6s3yfDYPuMrxOvaV7R5CQjWMZfaLEVDBSJT09MQdxIsvrhR9L2UnAX5T9jqDY8KQmb2dQUq+FIwk= Received: by 10.66.238.17 with SMTP id l17mr635434ugh; Wed, 08 Mar 2006 10:40:43 -0800 (PST) Received: by 10.67.30.2 with HTTP; Wed, 8 Mar 2006 10:40:43 -0800 (PST) Message-ID: <224f32340603081040m46f87698y49f3bbc11cfb31df@mail.gmail.com> Date: Wed, 8 Mar 2006 19:40:43 +0100 From: "Thomas Dudziak" To: pgsql-jdbc@postgresql.org Subject: Re: Performance problem with timestamps in result sets In-Reply-To: <20060308162543.GA29522@weaver.tuc.noao.edu> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_14762_10791908.1141843243122" References: <224f32340603080537ld424d49l2eea9440594104d3@mail.gmail.com> <060a01c642bf$b3060220$9001a8c0@zaphod> <224f32340603080657m35f7c35do34a2c6dc3f1b5f0@mail.gmail.com> <006201c642c2$1f17a610$c29c143e@w128mtec> <20060308162543.GA29522@weaver.tuc.noao.edu> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.12 required=5 tests=[AWL=0.120] X-Spam-Score: 0.12 X-Spam-Level: X-Archive-Number: 200603/44 X-Sequence-Number: 14825 ------=_Part_14762_10791908.1141843243122 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Hi, I've run the attached sample with these results (1.000.000 rows): no profiler: 7.850ms for the int's, 58.902ms for the timestamp's cpu profiling: 8.865ms for the int's, 60.357ms for the timestamp's cpu profiling with method count: 262.802ms for the ints, 695.188ms for the timestamps - getTimestamp(int) took 499.047ms for the 1.000.000 invocations with toTimestamp(Calendar, String) 378.854ms of that in contrast, getLong(int) took 169.703ms It does not seem linear (the profiler definitely has some influence, though a strange one). Tom ------=_Part_14762_10791908.1141843243122 Content-Type: application/octet-stream; name=Main.java Content-Transfer-Encoding: 7bit X-Attachment-Id: f_ekjzy275 Content-Disposition: attachment; filename="Main.java" import java.sql.Connection; import java.sql.DriverManager; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.sql.Timestamp; public class Main { private static final long BATCH_SIZE = 10000; private static final long NUM_BATCHES = 100; private static final long NUM_ROWS = NUM_BATCHES * BATCH_SIZE; private static final int FETCH_SIZE = 1000; private static void setupTest(Connection connection) throws SQLException { Statement stmt = connection.createStatement(); System.out.println("Creating the table"); stmt.executeUpdate("CREATE TABLE test ( id INT4 NOT NULL, creationtime TIMESTAMP NOT NULL, PRIMARY KEY (id) )"); stmt.close(); System.out.println("Inserting rows into the table"); connection.setAutoCommit(false); PreparedStatement prepStmt = connection.prepareStatement("INSERT INTO test (id, creationtime) VALUEs (?, ?)"); long numInserted = 0; for (long batchNum = 0; batchNum < NUM_BATCHES; batchNum++) { for (long idx = 0; idx < BATCH_SIZE; idx++, numInserted++) { prepStmt.setLong(1, numInserted + 1); prepStmt.setTimestamp(2, new Timestamp(System.currentTimeMillis())); prepStmt.addBatch(); } prepStmt.executeBatch(); connection.commit(); } prepStmt.close(); } private static void performTest(Connection connection) throws SQLException { System.out.println("Reading " + NUM_ROWS + " integers from the table"); Statement stmt = connection.createStatement(); // First the ids long startTime = System.currentTimeMillis(); ResultSet rs = stmt.executeQuery("SELECT id FROM test"); long numRead = 0; rs.setFetchSize(FETCH_SIZE); while (rs.next()) { numRead++; rs.getLong(1); } stmt.close(); long resultTime = System.currentTimeMillis() - startTime; System.out.println("Fetching " + numRead + " integers from the db took " + resultTime + "ms"); System.out.println("Reading " + NUM_ROWS + " timestamps from the table"); // First the timestamps stmt = connection.createStatement(); startTime = System.currentTimeMillis(); rs = stmt.executeQuery("SELECT creationtime FROM test"); numRead = 0; rs.setFetchSize(FETCH_SIZE); while (rs.next()) { numRead++; rs.getTimestamp(1); } stmt.close(); resultTime = System.currentTimeMillis() - startTime; System.out.println("Fetching " + numRead + " timestamps from the db took " + resultTime + "ms"); } public static void main(String[] args) throws Exception { Class.forName("org.postgresql.Driver"); Connection connection = DriverManager.getConnection("jdbc:postgresql://localhost/timestamptest", "postgres", "root123"); setupTest(connection); performTest(connection); connection.close(); } } ------=_Part_14762_10791908.1141843243122--