Re: Thin driver batching of PreparedStatements

From: Richard Kuhler <noone_at_nowhere.com>
Date: Thu, 11 Apr 2002 21:44:00 GMT
Message-ID: <Asnt8.36716$VQ2.17801430_at_twister.socal.rr.com>


Not that this answers your question but the 'Oracle update batching' mechanism doesn't seem to behave that way...

PreparedStatement ps = con.prepareStatement("insert into address(id) values(?)");

((OraclePreparedStatement)ps).setExecuteBatch (1000);

for (int i=0; i<1000; i++) {

    long longId = (long) i;
    ps.setLong(1, longId);
    ps.executeUpdate();
}

for (int i=1000; i<2000; i++) {

    long longId = (long) i;
    ps.setLong(1, longId);
    ps.executeUpdate();
}

gives 1 parse and 2 executes.

Richard

Justin Ashworth wrote:
>
> Hi,
>
> Using the thin driver, I am seeing a higher parse/execute ratio than I
> would expect when batching PreparedStatements. In the code below, I
> see 2 parses, 2 executes, and 2000 rows processed. The executes and
> rows processed are fine, however I expect to see only 1 parse. If I
> were to remove the ps.executeBatch() lines and change ps.addBatch() to
> ps.executeUpdate(), I would see 1 parse, 2000 executes, and 2000 rows
> processed. That makes sense to me because the PreparedStatement has
> already been parsed and I call executeUpdate() 2000 times. So why not
> the same behavior when using batches? Doesn't the database recognize
> that it has already parsed my PreparedStatement?
>
> =======================
> PreparedStatement ps = con.prepareStatement("insert into address(id)
> values(?)");
> for (int i=0; i<1000; i++)
> {
> long longId = (long) i;
> ps.setLong(1, longId);
> ps.addBatch();
> }
>
> ps.executeBatch();
>
> for (int i=1000; i<2000; i++)
> {
> long longId = (long) i;
> ps.setLong(1, longId);
> ps.addBatch();
> }
>
> ps.executeBatch();
> =======================
>
> Thanks in advance,
>
> Justin Ashworth
> (replace NOSPAM in my e-mail address with 'justin' to e-mail me)
Received on Thu Apr 11 2002 - 23:44:00 CEST

Original text of this message