Thread: extra rowcopy in ResultSet allways needed ?.

extra rowcopy in ResultSet allways needed ?.

From
Gustav Trede
Date:
hello,

I would be happy if someone could explain something i dont understand in
the current code.

Is the extra rowcopy allways needed to be done, for example in   boolean
next() method in resultset ?

Is the copy not only needed in some detectable special case ?.

thanks
  gustav

Re: extra rowcopy in ResultSet allways needed ?.

From
Kris Jurka
Date:

On Sat, 16 Feb 2008, Gustav Trede wrote:

> Is the extra rowcopy allways needed to be done, for example in   boolean
> next() method in resultset ?
>
> Is the copy not only needed in some detectable special case ?.
>

The rowBuffer copy is only needed for updateable ResultSets, so we could
probably wrap all those calls with isUpdateable() { }.  Are you seein a
significant performance impact from those calls or are you just curious?

Kris Jurka

Re: extra rowcopy in ResultSet allways needed ?.

From
Kris Jurka
Date:
Gustav Trede wrote:
> Kris Jurka skrev:
>> The rowBuffer copy is only needed for updateable ResultSets, so we
>> could probably wrap all those calls with isUpdateable() { }.  Are you
>> seein a significant performance impact from those calls or are you
>> just curious?
>>
>
> its good news that its avoidable.
> I buffer roughly 2Gbyte of data by jdbc in RAM.
> im using several threads to max the speed and im currently cpu bound for
> performance.
> its importent for me to keep the init time as low as possible, since it
> delays failover response in my setup.
> (long time outs on client IO keeps client in an ok state though.)
>
> I have a general interests in performance despite that im using
> webservices for clients =),
> and tend to look around in code on my sparetime, and i sometimes find
> things.
> Whenever the things are not risky to implement, its often to be
> considered free as in beer.
> Its only if there is noticable complexity, that the performance boost
> must be proven to be very substantial inorder
> to motivate risky code changes imo.
>
> I would be happy if its possible to check for isUpdatable in the
> official codebase,
> its a mess for me to keep local patches synced with CVS.
>
> I dont have any hard numbers atm.
> If its needed, i can try to provide it next week or so ?
>

No I don't need the numbers, I was just curious if you had them handy.
Also I was initially looking at the full cost of isUpdateable and the
idea that for a small ResultSet it would be faster to just do the copy
rather than doing the parsing and stuff to see if a ResultSet was
updateable.  Re-reading that now, we don't really want to call
isUpdateable, but probably just wrap things in "if (resultsetconcurrency
== ResultSet.CONCUR_UPDATABLE) { } ".  That'll be a simple quick check
that should always be a win.

So are you planning on coding this up, or just throwing it out as a
suggestion?

Kris Jurka


Re: extra rowcopy in ResultSet allways needed ?.

From
Kris Jurka
Date:
Gustav Trede wrote:
>
> I will do it for all methods that is not update methods.
> doing it in one method and then call it.
>
> i just attach the new AbstractJdbc2ResultSet.java in an email or ?
>

A patch would be better.  If you've got cvs checkout, the "cvs diff -c"
is what we'd like to see.

Also, please keep replies on the list so other people can read/comment
on your emails.

Kris Jurka

Re: extra rowcopy in ResultSet allways needed ?.

From
Gustav Trede
Date:
here is diff from current cvs.
>
>>
>> I will do it for all methods that is not update methods.
>> doing it in one method and then call it.
>>
>> i just attach the new AbstractJdbc2ResultSet.java in an email or ?
>>
>
> A patch would be better.  If you've got cvs checkout, the "cvs diff
> -c" is what we'd like to see.
>
> Also, please keep replies on the list so other people can read/comment
> on your emails.
>
> Kris Jurka
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Have you searched our list archives?
>
>               http://archives.postgresql.org
>
> __________ Information from ESET NOD32 Antivirus, version of virus
> signature database 2880 (20080215) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>

Index: AbstractJdbc2ResultSet.java
===================================================================
RCS file: /cvsroot/jdbc/pgjdbc/org/postgresql/jdbc2/AbstractJdbc2ResultSet.java,v
retrieving revision 1.102
diff -c -r1.102 AbstractJdbc2ResultSet.java
*** AbstractJdbc2ResultSet.java    19 Feb 2008 06:12:24 -0000    1.102
--- AbstractJdbc2ResultSet.java    20 Feb 2008 08:08:16 -0000
***************
*** 250,259 ****
          }

          current_row = internalIndex;
!         this_row = (byte[][]) rows.elementAt(internalIndex);
!
!         rowBuffer = new byte[this_row.length][];
!         System.arraycopy(this_row, 0, rowBuffer, 0, this_row.length);
          onInsertRow = false;

          return true;
--- 250,256 ----
          }

          current_row = internalIndex;
!         initRowBuffer();
          onInsertRow = false;

          return true;
***************
*** 295,304 ****
              return false;

          current_row = 0;
!         this_row = (byte[][]) rows.elementAt(current_row);
!
!         rowBuffer = new byte[this_row.length][];
!         System.arraycopy(this_row, 0, rowBuffer, 0, this_row.length);
          onInsertRow = false;

          return true;
--- 292,298 ----
              return false;

          current_row = 0;
!         initRowBuffer();
          onInsertRow = false;

          return true;
***************
*** 629,638 ****
              return false;

          current_row = rows_size - 1;
!         this_row = (byte[][]) rows.elementAt(current_row);
!
!         rowBuffer = new byte[this_row.length][];
!         System.arraycopy(this_row, 0, rowBuffer, 0, this_row.length);
          onInsertRow = false;

          return true;
--- 623,629 ----
              return false;

          current_row = rows_size - 1;
!         initRowBuffer();
          onInsertRow = false;

          return true;
***************
*** 658,666 ****
          {
              current_row--;
          }
!         this_row = (byte[][]) rows.elementAt(current_row);
!         rowBuffer = new byte[this_row.length][];
!         System.arraycopy(this_row, 0, rowBuffer, 0, this_row.length);
          return true;
      }

--- 649,655 ----
          {
              current_row--;
          }
!         initRowBuffer();
          return true;
      }

***************
*** 877,886 ****
          }
          else
          {
!             this_row = (byte[][]) rows.elementAt(current_row);
!
!             rowBuffer = new byte[this_row.length][];
!             System.arraycopy(this_row, 0, rowBuffer, 0, this_row.length);
          }

          onInsertRow = false;
--- 866,872 ----
          }
          else
          {
!             initRowBuffer();
          }

          onInsertRow = false;
***************
*** 1858,1867 ****
              current_row++;
          }

!         this_row = (byte [][])rows.elementAt(current_row);
!
!         rowBuffer = new byte[this_row.length][];
!         System.arraycopy(this_row, 0, rowBuffer, 0, this_row.length);
          return true;
      }

--- 1844,1850 ----
              current_row++;
          }

!         initRowBuffer();
          return true;
      }

***************
*** 2808,2813 ****
--- 2791,2806 ----
          return 0;  // SQL NULL
      }

+     private void initRowBuffer(){
+         this_row = (byte[][]) rows.elementAt(current_row);
+         if (resultsetconcurrency == ResultSet.CONCUR_UPDATABLE) {
+             rowBuffer = new byte[this_row.length][];
+             System.arraycopy(this_row, 0, rowBuffer, 0, this_row.length);
+         }else{
+             rowBuffer = this_row;
+         }
+     }
+
      private boolean isColumnTrimmable(int columnIndex) throws SQLException
      {
          switch (getSQLType(columnIndex))

Re: extra rowcopy in ResultSet allways needed ?.

From
Kris Jurka
Date:

On Wed, 20 Feb 2008, Gustav Trede wrote:

>
> here is diff from current cvs.


Patch applied, thanks.  The one minor change I made was to set rowBuffer =
null instead of rowBuffer = this_row in the non-updatable case to catch
any potential issues where the rowBuffer was being used improperly.

Kris Jurka