Re: Oracle JDBC Driver ps.setTimestamp() slows down query execution many times
From: Juha Laiho (Juha.Laiho_at_iki.fi)
Date: 01/20/05
- Next message: junk1_at_davidbevan.co.uk: "How do I scroll through multiple pages of JDBC data from a servlet?"
- Previous message: Dundonald: "Re: ID of last insert from DB2 table"
- In reply to: Janusz: "Oracle JDBC Driver ps.setTimestamp() slows down query execution many times"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Thu, 20 Jan 2005 16:53:53 +0000 (UTC)
"Janusz" <januszstu@wytnij.spam.wp.pl> said:
>I have the following problem. I perform simple sql query to Oracle database,
>there are 2 date variables in the query.
>
>final String sSql = "select count(*) from test where start_date > ? and
>start_date < ?";
>
>When I set the date variables using
> preparedStatement.setTimestamp(1, new Timestamp(startDate.getTime()));
> preparedStatement.setTimestamp(2, new Timestamp(endDate.getTime()));
>
>this simple query executes 10500 miliseconds [ms]
>
>but when the dates are hardcoded in SQL like this:
>final String sSql = "select count(*) from test where start_date >
>'2005-01-14' and start_date < '2005-01-18'";
>
>the query runs 50 [ms]
>
>In SQLPlus this simple query is also very fast - 30 [ms]
After seeing Joe's responses (about use of indexes etc), I'll try to add
something; check a couple of variations of your parametrized query.
What happens if you, instead of providing the timestamps with setTimestamp,
provide them as strings (as you do in your hardcoded SQL example)?
How about using an explicit TO_DATE() (hmm.. was it TO_DATE() or was there
something else for greater accuracy?) conversion around your ?-marks in
the query?
Also, check that the index makes sense; so, chek index statistics, and try
to get an idea whether the index is at least somewhat correctly balanced.
And remember, the analyze results will be discarded if they're too old,
so even just re-analyzing an index may help.
--
Wolf a.k.a. Juha Laiho Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)
- Next message: junk1_at_davidbevan.co.uk: "How do I scroll through multiple pages of JDBC data from a servlet?"
- Previous message: Dundonald: "Re: ID of last insert from DB2 table"
- In reply to: Janusz: "Oracle JDBC Driver ps.setTimestamp() slows down query execution many times"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|