pg.ddx.io  pgsql-jdbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: dmp <danap@ttc-cmc.net>
To: Luis Flores <luiscamposflores@gmail.com>
To: pgsql-jdbc@postgresql.org
Subject: Re: bug report: slow getColumnTypeName
Date: Wed, 10 Oct 2012 19:23:52 -0600
Message-ID: <50761FA8.9080208@ttc-cmc.net> (raw)
In-Reply-To: <CA+nXnG-xy8GvVj1gH0f0evuL0uvyw9f87zQVks_zzyuY7ZJEFA@mail.gmail.com>
References: <CAMiEbch4MsNhkTamK3dt4GpJ8qU0BObYPmMNGkrzVFLjwONMpQ@mail.gmail.com>
	<CAMiEbchygfLbpytyOdDXL3-ORjMD76u_0MqwX9QROzCkHUUp0Q@mail.gmail.com>
	<50745541.8060204@ttc-cmc.net>
	<CA+nXnG8thQTe6D-njQYqQUd-LuXD2--RBejCz6Oq7dtMUEEs=g@mail.gmail.com>
	<CA+nXnG-xy8GvVj1gH0f0evuL0uvyw9f87zQVks_zzyuY7ZJEFA@mail.gmail.com>

Luis Flores wrote:
> I've looked at the AbstractJdbc2ResultSetMetadata getColumnTypeName,
> for version 1000 and 802.
>
> The change is simple, there is an extra call to isAutoIncrement, to be
> able to return correct values in the serial and bigserial cases.
>
> The isAutoIncrement call is slow because it triggers
> fetchFieldMetadata, witch get all metada for all fields.
>
> One simple optimization is to change the current method to:
>
>      public String getColumnTypeName(int column) throws SQLException
>      {
>          String type = getPGType(column);
>          if ( ( "int4".equals(type) || "int8".equals(type) )&&
> isAutoIncrement(column)) {
>              if ("int4".equals(type)) {
>                  return "serial";
>              } else if ("int8".equals(type)) {
>                  return "bigserial";
>              }
>          }
>
>          return type;
>      }
>
> 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.
>
> May they are better options, but I think this change is good, it
> delays fetching metadata, and speeds up the method, without side
> effects.
>
> Luis Flores

isAutoIncrement() is not the only place that fetchFieldMetadata() is
called. isNullable(), getBaseColumnName(), getBaseSchemaName(), &
getBaseTableName(). Everyone of those calls is going to have the
same performance hit looks like the first time, the more table columns
the worst it gets. I know its nice to cache for all the table fields,
but when it hits performance like that you have to ask is it worth it.

ResultSetMetaData are usually limited creatures aren't they? Why would
you cache all your table fields info. Cache one by one maybe as called.

danap.




view thread (30+ messages)  latest in thread

Message-ID: <50761FA8.9080208@ttc-cmc.net>
Permalink:  ../50761FA8.9080208@ttc-cmc.net/
Also on:    postgresql.org/message-id/50761FA8.9080208@ttc-cmc.net

 · 

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-jdbc@postgresql.org
  Cc: danap@ttc-cmc.net, luiscamposflores@gmail.com
  Subject: Re: bug report: slow getColumnTypeName
  In-Reply-To: <50761FA8.9080208@ttc-cmc.net>
  References: <CAMiEbch4MsNhkTamK3dt4GpJ8qU0BObYPmMNGkrzVFLjwONMpQ@mail.gmail.com> <CAMiEbchygfLbpytyOdDXL3-ORjMD76u_0MqwX9QROzCkHUUp0Q@mail.gmail.com> <50745541.8060204@ttc-cmc.net> <CA+nXnG8thQTe6D-njQYqQUd-LuXD2--RBejCz6Oq7dtMUEEs=g@mail.gmail.com> <CA+nXnG-xy8GvVj1gH0f0evuL0uvyw9f87zQVks_zzyuY7ZJEFA@mail.gmail.com> <50761FA8.9080208@ttc-cmc.net>

* 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