Received: from magus.postgresql.org ([87.238.57.229]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TMIuX-0007s4-A0 for pgsql-jdbc@postgresql.org; Thu, 11 Oct 2012 13:34:49 +0000 Received: from nm12-vm2.bullet.mail.ne1.yahoo.com ([98.138.91.88]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TMIuP-0008EH-8d for pgsql-jdbc@postgresql.org; Thu, 11 Oct 2012 13:34:48 +0000 Received: from [98.138.90.57] by nm12.bullet.mail.ne1.yahoo.com with NNFMP; 11 Oct 2012 13:34:39 -0000 Received: from [98.138.89.232] by tm10.bullet.mail.ne1.yahoo.com with NNFMP; 11 Oct 2012 13:34:39 -0000 Received: from [127.0.0.1] by omp1047.mail.ne1.yahoo.com with NNFMP; 11 Oct 2012 13:34:39 -0000 X-Yahoo-Newman-Id: 724114.2444.bm@omp1047.mail.ne1.yahoo.com Received: (qmail 88667 invoked from network); 11 Oct 2012 13:34:39 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=DKIM-Signature:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:References:In-Reply-To:Mime-Version:Content-Transfer-Encoding:Content-Type:Message-Id:Cc:X-Mailer:From:Subject:Date:To; b=VfxEplp5w/KvVbaydqkLy94Pe/iWQ+808766iKD5RbegaqvASCodPiH8vFASi/VnxR8a6766t3S2zPRoaJbBE+HTXjb98R5P2jgfvkm5K+Qg+fJ7e8c+4sWqJyFAZTQhjmohst2l2cDch55KZAwr4ZnQTlkX/WAkf+YLyoTxSpk= ; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1349962479; bh=H33nHbh12GVdr5pbhSPix9Xg8fCdeeCEWLpofYmWIxk=; h=X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:References:In-Reply-To:Mime-Version:Content-Transfer-Encoding:Content-Type:Message-Id:Cc:X-Mailer:From:Subject:Date:To; b=LgLnuqKHASVTd7B69MxDEDkPrzTHl6tW7d/aZRfXYSvmaI77fd4HYUstmVlrKZBEIWu3wMFdwdhnOxKFVPFpcp/MJ7vZChdViUH+epnJFZVRgs7QqbO+8wOLIHuwqlprmpDumPKmL0RTLdNcOeH0ZWl+A6kXuYPzw8/w5a8LMJg= X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: 2Jj6BewVM1kWjWyVWhz_scLPXLOrNoQvPtXoznbRIaZlZtq JhPseDQBMRExnsgpTTeQq_uw.fHP7wy9W56nlMZWEopmAv8IFYufoZtzMQoq wFCN8mav0N8ZrYivTk0KMT2GqeZ0TrpSVbxnnCc3Q.xZ.sW909puB8JvFS4K 8YyPU3LXeDppo5bI8tLmlL4yxzIHS1u9cuIwTUyOf7Duat1.a7DVhDRhyVj4 A.sr75ZpYHqkNwE_Xxbr4_nUByP0vxvZuI.wr.vxhgC94caLaxmuPjF7C75F ZzhA_bgJH2tKPwGqzQNCX60DG9UKKKnaVrgpYOvT.niGpKQ9MAsiV6uD9USe IRbuIfoPXORTEn.KGpPb12nGFrUUWKt7hR4f_m6Q9vaiNCl_kgRgs7JoQRcS ZsZW3caXETIBjTx.67dBDVghYlqQGhalUu89xe3LN3PSDRcopseaNCkHRSuV qkr6u X-Yahoo-SMTP: mpGJl6eswBD2IBufoVEg0Pa8gg-- Received: from [192.12.17.101] (polobo@24.93.23.188 with xymcookie) by smtp125-mob.biz.mail.ne1.yahoo.com with SMTP; 11 Oct 2012 13:34:39 +0000 UTC References: <50745541.8060204@ttc-cmc.net> In-Reply-To: Mime-Version: 1.0 (1.0) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=us-ascii Message-Id: Cc: Eyal Wilde , "pgsql-jdbc@postgresql.org" , dmp X-Mailer: iPad Mail (9B206) From: David Johnston Subject: Re: bug report: slow getColumnTypeName Date: Thu, 11 Oct 2012 09:34:38 -0400 To: Luis Flores X-Pg-Spam-Score: -4.1 (----) X-Archive-Number: 201210/43 X-Sequence-Number: 23367 What about a field that concatenates the serial value with a varchar to gene= rate an auto-incrementing but non-numeric primary key? How should that be c= lassified? David J. On Oct 11, 2012, at 3:55, Luis Flores wrote: > I'm still checking the fetchFieldMetadata(), and I will try to > identify a way of getting the serial info without the full penalty we > are having, or to understand if loading metadata one field at a time > is much slower than the current method. >=20 > And I understand, and agree, it is strange to have irregular performance. >=20 > But, for now, we can understand and justify the need to call > isAutoIncrement in int4 and int8 columns, so that we detect if they > are in reality serial columns. We can't justify the isAutoIncrement > call in all other cases. Aside from the huge performance hit, it's the > wrong algorithm, we shouldn't call a method if we don't need the > answer. >=20 > The irregular performance comes from added complexity for some data > types, not from a buggy algorithm. To me it seems it would be easier > to understand the performance hit cause if it only happened on serial > columns. >=20 >=20 > Luis Flores >=20 > On Thu, Oct 11, 2012 at 5:12 AM, Eyal Wilde wrote: >> If i may... after we spent two days tracking this strange behavior, we >> decided to avoid getColumnTypeName at all. The optimization suggested wou= ld >> cause even more strange and un-solid performance, from the everage user's= >> point of view. >>=20 >> I believe this extra info of serial/bigserial is not available as a resul= t >> of optimization. so maybe it's time to ask the pg-server guys, to arrange= >> something in thier area? >>=20 >> Regards. >>=20 >> On Oct 11, 2012 12:46 AM, "Luis Flores" wrot= e: >>>=20 >>> I'm sorry, but I'm a bit sleepy ... >>>=20 >>> I believe the code is more readable/better like this: >>>=20 >>> public String getColumnTypeName(int column) throws SQLException >>> { >>> String type =3D getPGType(column); >>> if ( ( "int4".equals(type) && isAutoIncrement(column)) { >>> type =3D "serial"; >>> } else if ("int8".equals(type) && isAutoIncrement(column)) { >>> type "bigserial"; >>> } >>>=20 >>> return type; >>> } >>>=20 >>> Luis Flores >>>=20 >>> On Wed, Oct 10, 2012 at 11:39 PM, Luis Flores >>> wrote: >>>> I've looked at the AbstractJdbc2ResultSetMetadata getColumnTypeName, >>>> for version 1000 and 802. >>>>=20 >>>> The change is simple, there is an extra call to isAutoIncrement, to be >>>> able to return correct values in the serial and bigserial cases. >>>>=20 >>>> The isAutoIncrement call is slow because it triggers >>>> fetchFieldMetadata, witch get all metada for all fields. >>>>=20 >>>> One simple optimization is to change the current method to: >>>>=20 >>>> public String getColumnTypeName(int column) throws SQLException >>>> { >>>> String type =3D getPGType(column); >>>> if ( ( "int4".equals(type) || "int8".equals(type) ) && >>>> isAutoIncrement(column)) { >>>> if ("int4".equals(type)) { >>>> return "serial"; >>>> } else if ("int8".equals(type)) { >>>> return "bigserial"; >>>> } >>>> } >>>>=20 >>>> return type; >>>> } >>>>=20 >>>> In this case, the isAutoIncrement is only called on int4 and int8 >>>> columns, causing the performance for all the other column types to >>>> remain the same. >>>>=20 >>>> May they are better options, but I think this change is good, it >>>> delays fetching metadata, and speeds up the method, without side >>>> effects. >>>>=20 >>>> Luis Flores >>>>=20 >>>> On Wed, Oct 10, 2012 at 11:10 PM, Luis Flores >>>> wrote: >>>>> I also confirm the performance regression. >>>>>=20 >>>>> Testing on Fedora17 64bit + PostgreSQL 9.1 + jdk 1.6.0_33, localhost >>>>> server, I get these numbers: >>>>> driver 802 >>>>> getColumnType time (ms): 2777 >>>>> getColumnTypeName time (ms): 1847 >>>>> both time (ms): 1948 >>>>>=20 >>>>> driver 903 >>>>> getColumnType time (ms): 3044 >>>>> getColumnTypeName time (ms): 27123 >>>>> both time (ms): 25142 >>>>>=20 >>>>> driver 1000 >>>>> getColumnType time (ms): 2928 >>>>> getColumnTypeName time (ms): 27214 >>>>> both time (ms): 26407 >>>>>=20 >>>>> During the getColumnTypeName tests postgresql daemon used 100% cpu >>>>> time. >>>>>=20 >>>>> Here is the full test class: >>>>>=20 >>>>> import java.sql.Connection; >>>>> import java.sql.DriverManager; >>>>> import java.sql.ResultSet; >>>>> import java.sql.ResultSetMetaData; >>>>> import java.sql.Statement; >>>>>=20 >>>>>=20 >>>>> public class Main >>>>> { >>>>> public static void main( String arg[] ) >>>>> throws Exception >>>>> { >>>>> Class.forName( "org.postgresql.Driver" ); >>>>> Connection conn =3D DriverManager.getConnection( >>>>> "jdbc:postgresql://localhost/test", "postgres", "" ); >>>>> Statement create =3D conn.createStatement(); >>>>> create.execute( "CREATE TABLE t(id SERIAL, name >>>>> VARCHAR);" ); >>>>> create.close(); >>>>> long l =3D System.currentTimeMillis(); >>>>> for( int i =3D 0; i < 10000; ++i ) >>>>> { >>>>> Statement stm =3D conn.createStatement(); >>>>> stm.execute( "SELECT id, name FROM t;" ); >>>>> ResultSet rs =3D stm.getResultSet(); >>>>> ResultSetMetaData rsmd =3D rs.getMetaData(); >>>>> rsmd.getColumnType( 1 ); >>>>> // rsmd.getColumnTypeName( 1 ); >>>>> rs.close(); >>>>> stm.close(); >>>>> } >>>>> System.out.println( "getColumnType time (ms): " + ( >>>>> System.currentTimeMillis() - l ) ); >>>>> l =3D System.currentTimeMillis(); >>>>> for( int i =3D 0; i < 10000; ++i ) >>>>> { >>>>> Statement stm =3D conn.createStatement(); >>>>> stm.execute( "SELECT id, name FROM t;" ); >>>>> ResultSet rs =3D stm.getResultSet(); >>>>> ResultSetMetaData rsmd =3D rs.getMetaData(); >>>>> // rsmd.getColumnType( 1 ); >>>>> rsmd.getColumnTypeName( 1 ); >>>>> rs.close(); >>>>> stm.close(); >>>>> } >>>>> System.out.println( "getColumnTypeName time (ms): " + (= >>>>> System.currentTimeMillis() - l ) ); >>>>> l =3D System.currentTimeMillis(); >>>>> for( int i =3D 0; i < 10000; ++i ) >>>>> { >>>>> Statement stm =3D conn.createStatement(); >>>>> stm.execute( "SELECT id, name FROM t;" ); >>>>> ResultSet rs =3D stm.getResultSet(); >>>>> ResultSetMetaData rsmd =3D rs.getMetaData(); >>>>> rsmd.getColumnType( 1 ); >>>>> rsmd.getColumnTypeName( 1 ); >>>>> rs.close(); >>>>> stm.close(); >>>>> } >>>>> System.out.println( "both time (ms): " + ( >>>>> System.currentTimeMillis() - l ) ); >>>>> Statement drop =3D conn.createStatement(); >>>>> drop.execute( "DROP TABLE t;" ); >>>>> drop.close(); >>>>> conn.close(); >>>>> } >>>>> } >>>>>=20 >>>>>=20 >>>>> Luis Flores >>>>>=20 >>>>> On Tue, Oct 9, 2012 at 5:48 PM, dmp wrote: >>>>>> Eyal Wilde wrote: >>>>>>>=20 >>>>>>> I verified with wireshark that getColumnTypeName indeed do a reques= t >>>>>>> to >>>>>>> the postgres server. This happens with 9.1-901 and 9.1-903 BUT NOT >>>>>>> WITH >>>>>>> 9.0-801!! >>>>>>>=20 >>>>>>> So, the reason for the slowness seems to be obviouse now. >>>>>>>=20 >>>>>>> it will take me some time to wrap up it into a test case. I would >>>>>>> realy >>>>>>> like to help, but please let me know if it's realy necessary. >>>>>>>=20 >>>>>>> On Oct 5, 2012 1:07 AM, "Eyal Wilde" >>>>>> > wrote: >>>>>>>=20 >>>>>>>=20 >>>>>>> ResultSetMetaData __md =3D __rs.getMetaData(= ); >>>>>>> //this is fine >>>>>>> String __sf1name =3D __md.getColumnName(1); >>>>>>> //this is fine >>>>>>> int __if1type =3D __md.getColumnType(1); >>>>>>> //this is fine >>>>>>> String __sf1type =3D >>>>>>> __md.getColumnTypeName(1); //this is SLOW!! ~15msec >>>>>>>=20 >>>>>>> postgres server version is 9.1.5 >>>>>>> jdbc version, i checked both 9.1-901 and 9.1-903 >>>>>>> and... BTW, 9.0-801 works good (while connected pg9.1)! >>>>>>=20 >>>>>>=20 >>>>>> There does appear to be a change in the code that may have created th= e >>>>>> slowness that you are observing. Please try a a test case in which tw= o >>>>>> back to back getColumnTypeName() calls are made. Is there a differenc= e >>>>>> in time between the first and second and is there still on the second= >>>>>> call a request to the postgres server. >>>>>>=20 >>>>>> The code between 9.0-801 and later version does have a change in it >>>>>> that looks like for the caching for field metadata through >>>>>> fetchFieldMetaData(). >>>>>> That method is called in the later versions for getColumnTypeName() >>>>>> with isAutoIncrement(), with was also added in later versions. >>>>>>=20 >>>>>> danap. >>>>>>=20 >>>>>>=20 >>>>>>=20 >>>>>>=20 >>>>>> -- >>>>>> Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) >>>>>> To make changes to your subscription: >>>>>> http://www.postgresql.org/mailpref/pgsql-jdbc >=20 >=20 > --=20 > Sent via pgsql-jdbc mailing list (pgsql-jdbc@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-jdbc