Thin driver batching of PreparedStatements

From: Justin Ashworth <NOSPAM_at_ashworth.org>
Date: 11 Apr 2002 10:54:11 -0700
Message-ID: <b460c7c4.0204110954.2a2f542f_at_posting.google.com>



Hi,

[Quoted] 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 - 19:54:11 CEST

Original text of this message