Issue Details (XML | Word | Printable)

Key: RDBMS-33
Type: Bug Bug
Status: Closed Closed
Resolution: Won't Fix
Priority: Major Major
Assignee: Unassigned
Reporter: Andy Jefferson
Votes: 2
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
JPOX RDBMS (ARCHIVED)

JDOQL : MySQL query using 2 contains results in invalid SQL

Created: 19/Feb/06 11:43 AM   Updated: 27/May/10 07:24 AM   Resolved: 17/May/10 02:38 PM
Component/s: Queries
Affects Version/s: None
Fix Version/s: None

Issue Links:
Duplicate
 

Datastore: Apache Derby, HSQL, MySQL


 Description  « Hide
The JPOX unit testcase "testQueryUsesContainsValueTwiceOnFieldUsingWorkaroundInverse" results in the following with MySQL 4.1

Error executing JDOQL query
"SELECT 'org.jpox.samples.fitness.Gym' AS JPOXMETADATA,`THIS`.`GYM_ID`,`THIS`.`LOCATION`,`THIS`.`NAME`,`THIS`.`STRING_KEY`,`THIS`.`STRING_VA
LUE`
FROM `GYM` `THIS`
WHERE EXISTS
(SELECT 1 FROM `WARDROBE` `THIS_WARDROBESINVERSE_W1`
LEFT OUTER JOIN `WARDROBE` `THIS_WARDROBESINVERSE_W1_MODEL` ON `THIS_WARDROBESINVERSE_W1`.`WARDROBE_ID` = `THIS_WARDROBESINVERSE_W1_MODEL`.`WARDROBE_ID` WHERE `THIS_WARDROBESINVERSE_W1`.`GYM_GYM_ID_OID` = `THIS`.`GYM_ID` AND `THIS_WARDROBESINVERSE_W1`.`GYM_GYM_ID_OID` = `THIS`.`GYM_ID`)
AND EXISTS
(SELECT 1 FROM `WARDROBE` `THIS_WARDROBESINVERSE_W2`
LEFT OUTER JOIN `WARDROBE` `THIS_WARDROBESINVERSE_W2_MODEL` ON `THIS_WARDROBESINVERSE_W2`.`WARDROBE_ID` = `THIS_WARDROBESINVERSE_W2_MODEL`.`WARDROBE_ID` WHERE `THIS_WARDROBESINVERSE_W2`.`GYM_GYM_ID_OID` = `THIS`.`GYM_ID` AND `THIS_WARDROBESINVERSE_W2`.`GYM_GYM_ID_OID` = `THIS`.`GYM_ID`) AND `THIS_WARDROBESINVERSE_W1_MODEL`.`MODEL` = ? OR `THIS_WARDROBESINVERSE_W2_MODEL`.`MODEL` = ?"
Unknown table 'THIS_WARDROBESINVERSE_W1_MODEL' in where clause

MySQL's subselect support in 4.1 doesn't seem complete to me based on this.

Sort Order: Ascending order - Click to sort in descending order
Andy Jefferson added a comment - 18/Apr/06 10:06 AM
Actually, the SQL is indeed just wrong. The second EXISTS is carrying across 'THIS_WARDROBESINVERSE_W1_MODEL' which is for the first contains I think. This table alias is not visible in that scope ... its only available within the first EXISTS.

Erik Bengtson added a comment - 27/May/06 09:36 AM
Actually, this is not a big issue because similar queries can be constructed and works by putting parenthesis in right places. JPOX, however, should be able to handle when parenthesis are not in place, doing some magical contextual compilation.

Erik Bengtson added a comment - 27/May/06 11:06 AM
Confirmed to not work with derby, mysql and hsql.

Since derby has a good query compiler, i doubt it will work in another database

Andy Jefferson added a comment - 08/Jan/08 05:35 PM
Moving to JPOX 1.3 since workaround is use of parentheses, and nobody to work on it in JPOX 1.2 timescales

Andy Jefferson added a comment - 11/Jan/08 06:10 PM
See also RDBMS-77 which is another case where EXISTS is generated incorrectly and use of parentheses helps to some extent. Also "org.jpox.rdbms.jdoql.existsIncludesConstraints" query extension. Unbound variable clauses should only be applied on EXISTS that involve the variable (which is where parentheses are sufficient hint to the compiler)

Andy Jefferson added a comment - 23/Mar/09 12:30 PM
Query issues like this will not be addressed with the legacy JDOQL implementation; wait for "JDOQL2" to be complete

Andy Jefferson added a comment - 17/May/10 02:38 PM
DataNucleus RDBMS 2.x resolved all such issues