[ 
https://issues.apache.org/jira/browse/DERBY-4422?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12775919#action_12775919
 ] 

Knut Anders Hatlen commented on DERBY-4422:
-------------------------------------------

I downloaded the database and ran the queries, and I see the same behaviour.

One possible workaround is to rewrite the IN query to a join manually. So 
instead of

SELECT DISTINCT C.INTERNAL_ID
FROM OC_CONCEPTS C
WHERE
   (C.INTERNAL_ID IN (SELECT DISTINCT OCS.CONCEPT_ID FROM OC_CONCEPT_STRINGS 
OCS WHERE OCS.NL_LC = 'dash'))

try this equivalent query

SELECT DISTINCT C.INTERNAL_ID
FROM OC_CONCEPTS C, OC_CONCEPT_STRINGS OCS
WHERE C.INTERNAL_ID = OCS.CONCEPT_ID AND OCS.NL_LC = 'dash'

The latter query is much faster in my environment.

> Extremely slow subqueries when subquerying on strings
> -----------------------------------------------------
>
>                 Key: DERBY-4422
>                 URL: https://issues.apache.org/jira/browse/DERBY-4422
>             Project: Derby
>          Issue Type: Bug
>    Affects Versions: 10.5.3.0
>         Environment: Suse Unix 10.3.
>            Reporter: Tony Brusseau
>         Attachments: badqp.txt, derby.log, fixed-time-derby.log, goodqp.txt, 
> SQLFile1.sqlaa.gz, SQLFile1.sqlab.gz, SQLFile2.sqlaa.gz, SQLFile2.sqlab.gz, 
> SQLFile2.sqlac.gz, tmp2.sql, unlimited-time-derby.log
>
>
> SELECT DISTINCT C.INTERNAL_ID 
> FROM OC_CONCEPTS C
> WHERE
>    (C.INTERNAL_ID IN (SELECT DISTINCT OCS.CONCEPT_ID FROM OC_CONCEPT_STRINGS 
> OCS WHERE OCS.CONCEPT_ID=1))
> Both queries above are trivial and they are both acting on fully indexed 
> primary key columns. This query runs just fine. 
> However, when I make the small modification of searching on an indexed text 
> column in the sub query, it takes over 6 seconds to run, even though both 
> queries independently take < 1ms run.
> SELECT DISTINCT C.INTERNAL_ID 
> FROM OC_CONCEPTS C
> WHERE
>    (C.INTERNAL_ID IN (SELECT DISTINCT OCS.CONCEPT_ID FROM OC_CONCEPT_STRINGS 
> OCS WHERE OCS.NL_LC = 'dash'))

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to