Can you explain to me what is wrong with the following query?

We are running JIRA 4.4.4 and MySQL. One of our customers has a direct access to the database and want's to execute the following query. It didn't terminate and while it's running the JIRA slows down. Can you explain to me why it is problematic and suggest how to fix it.

select cc.id, cc.fieldconfigscheme, cc.customfield, cfv.issue, fcs.configname, fcs.description, cf.cfname, cfo.sequence, cfo.customvalue, cfo.disabled, it.pname
from configurationcontext cc left outer join fieldconfigscheme fcs on fcs.id = cc.fieldconfigscheme
left outer join customfieldoption cfo on cfo.customfieldconfig = fcs.id
left outer join fieldconfigschemeissuetype fcsit on fcsit.fieldconfigscheme = fcs.id
left outer join issuetype it on it.id = fcsit.issuetype
left outer join customfield cf on cf.id = cfo.customfield
left outer join customfieldvalue cfv on cfv.customfield = cf.id 
where cc.project = 10216
order by 1,2,3,4;

2 answers

1 accepted

0 vote
Reed Johnson Atlassian Team Apr 17, 2013

It might help to move some of the constraints on cc into a subquery. My hypothesis is that the subquery will return a smaller result set to join on, rather than performing a huge join, and filtering at the end. Mysql's query optimizer might take care of this for you, but worth a shot.

So it would look like:

select cc.id, cc.fieldconfigscheme, cc.customfield, cfv.issue, fcs.configname, fcs.description, cf.cfname, cfo.sequence, cfo.customvalue, cfo.disabled, it.pname
from 
  (select
     id, fieldconficscheme, customfield
   from configurationcontext
   where cc.project = 10216) cc
left outer join fieldconfigscheme fcs on fcs.id = cc.fieldconfigscheme
left outer join customfieldoption cfo on cfo.customfieldconfig = fcs.id
left outer join fieldconfigschemeissuetype fcsit on fcsit.fieldconfigscheme = fcs.id
left outer join issuetype it on it.id = fcsit.issuetype
left outer join customfield cf on cf.id = cfo.customfield
left outer join customfieldvalue cfv on cfv.customfield = cf.id
order by 1,2,3,4;

The slowing down would be because of the number of joins you have and the amount of data that you are trying join.

Yes, I understand, is there a way to rewrite the query so that it is more effective?

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published 6 hours ago in Jira

5 ways you can make the most of Jira Software and Bitbucket Cloud

As part of the Bitbucket product team I'm always interested in better understanding what kind of impact the use of our tools have on the way you work. In a recent study we conducted of software devel...

21 views 0 3
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you