Prepare statement bug
Posted in 2003
Can anyone give me some hints as to what may be going on here.
I've got an old java (1.1.8 with Informix JDBC Driver 1.40.JC2) application
talking to a old Informix database (Informix Dynamic Server Version
7.31.UC4). It's been running for years without problems.
I'm just trying to reconfig the disk space so that we can move to newer
versions of all the software. However we still want the old DB and app to
continue running.
I have dbexported and the dbimported to a different database name residing
on new database spaces. The plan is to switch the old app to point at the
new database and then drop the old database spaces and reconfigure.
However when pointing at the new database one query using PreparedStatements
fails.
This is the original database:
User Table:
100_1 informix unique No usersid
100_2 informix unique No ecardid_lc
idx_firstname informix dupls No firstname_lc
idx_lastname informix dupls No lastname_lc
idx_altfirstname informix dupls No altfirstname_lc
idx_soundex informix dupls No soundex
And when I run the application with SET EXPLAIN ON I get the following. (and
a special thanks to CVS for recovering the source so nicely...)
QUERY: (FIRST_ROWS OPTIMIZATION)
------
SELECT usersId, eCardId, ePassword, emailAuth, title, pvtTitle, firstName,
pvtFirstName, altFirstName, pvtAltFirstName, middleName, pvtMiddleName,
lastName, pvtLastName, suffix, pvtSuffix, companyName, pvtCompanyName,
jobTitle, pvtJobTitle, businessComment, pvtBusinessComment, webPageURL,
pvtWebPageURL, eCardId_lc, firstName_lc, lastName_lc, altFirstName_lc,soundEx FROM Users WHERE (firstName_lc LIKE ? OR altFirstName_lc LIKE ?) AND
lastName_lc LIKE ? AND pvtFirstName = 0 AND pvtLastName = 0 ORDER BY
lastName_lc, firstName_lc
Estimated Cost: 2
Estimated # of Rows Returned: 1
Temporary Files Required For: Order By
1) informix.users: SEQUENTIAL SCAN (Serial, fragments: ALL)
Filters: ((informix.users.firstname_lc LIKE 'chris%' OR
informix.users.altfirstname_lc LIKE 'chris%' ) AND
(informix.users.lastname_lc LIKE 'mckay%' AND (informix.users.pvtfirstname =
0 AND informix.users.pvtlastname = 0 ) ) )
1 row is returned
I switched to the new database after Dbexport, dbimport and change name of
DB by changing the dbexport directory name. Dropped and recreated the
indexes, updated statistics
UPDATE STATISTICS MEDIUM FOR TABLE users DISTRIBUTIONS ONLY;
UPDATE STATISTICS HIGH FOR TABLE users (firstname_lc);
UPDATE STATISTICS HIGH FOR TABLE users (lastname_lc);
UPDATE STATISTICS HIGH FOR TABLE users (altfirstname_lc);
Db_new
100_1 informix unique No ecardid_lc
100_2 informix unique No usersid
idx_firstname informix dupls No firstname_lc
idx_lastname informix dupls No lastname_lc
idx_altfirstname informix dupls No altfirstname_lc
idx_soundex informix dupls No soundex
And now the query does this
QUERY: (FIRST_ROWS OPTIMIZATION)
------
SELECT usersId, eCardId, ePassword, emailAuth, title, pvtTitle, firstName,pvtFi
rstName, altFirstName, pvtAltFirstName, middleName, pvtMiddleName, lastName,
pvt
LastName, suffix, pvtSuffix, companyName, pvtCompanyName, jobTitle,
pvtJobTitle,
businessComment, pvtBusinessComment, webPageURL, pvtWebPageURL, eCardId_lc,
fir
stName_lc, lastName_lc, altFirstName_lc, soundEx FROM Users WHERE
(firstName_lc
LIKE ? OR altFirstName_lc LIKE ?) AND lastName_lc LIKE ? AND pvtFirstName =
0
AND pvtLastName = 0 ORDER BY lastName_lc, firstName_lc
Estimated Cost: 52
Estimated # of Rows Returned: 1
Temporary Files Required For: Order By
1) informix.users: INDEX PATH
Filters: ((informix.users.firstname_lc LIKE 'chris%' OR
informix.users.altfirstname_lc LIKE 'chris%' ) AND
(informix.users.pvtfirstname = 0 AND informix.users.pvtlastname = 0 ) )
(1) Index Keys: lastname_lc
Lower Index Filter: informix.users.lastname_lc > 'mckaz'
Upper Index Filter: informix.users.lastname_lc < 'mckaz'
PostIndex Filter:informix.users.lastname_lc LIKE 'mckaz'
No rows are returned. Notice the line "PostIndex
Filter:informix.users.lastname_lc LIKE 'mckaz'" This was NOT what was input
into the application.
So I hard coded the values in the prepare statement.
QUERY: (FIRST_ROWS OPTIMIZATION)
------
SELECT usersId, eCardId, ePassword, emailAuth, title, pvtTitle, firstName,
pvtFirstName, altFirstName, pvtAltFirstName, middleName, pvtMiddleName,
lastName, pvtLastName, suffix, pvtSuffix, companyName, pvtCompanyName,
jobTitle, pvtJobTitle,
businessComment, pvtBusinessComment, webPageURL, pvtWebPageURL, eCardId_lc,
firstName_lc, lastName_lc, altFirstName_lc, soundEx FROM Users WHERE
(firstName_lc LIKE 'chris%' OR altFirstName_lc LIKE 'chris%') AND
lastName_lc LIKE 'mckay%' AND pvtFirstName = 0 AND pvtLastName = 0 ORDER BY
lastName_lc, firstName_lc
Estimated Cost: 52
Estimated # of Rows Returned: 1
Temporary Files Required For: Order By
1) informix.users: INDEX PATH
Filters: ((informix.users.firstname_lc LIKE 'chris%' OR
informix.users.altfirstname_lc LIKE 'chris%' ) AND
(informix.users.pvtfirstname = 0 AND informix.users.pvtlastname = 0 ) )
(1) Index Keys: lastname_lc
Lower Index Filter: informix.users.lastname_lc > 'mckax'
Upper Index Filter: informix.users.lastname_lc < 'mckaz'
PostIndex Filter:informix.users.lastname_lc LIKE 'mckay%'
1 row returned.
And got this. I can only presume it is a bug and by dumb luck the old
database is of such a structure that we never hit it. Has anyone seen
anything like this before? Haven't found anything with google as yet. I'll
try to update the JDBC driver at least, but I can't really upgrade Informix
at this stage. Anyone with any advice?
Chris