#1780 closed defect (fixed)
Querying 2 traits in maize causes public website to time out
| Reported by: | Mark J. Millard | Owned by: | dbmulg |
|---|---|---|---|
| Priority: | major | Milestone: | Server Release 1.10.4 |
| Component: | Public Website App. | Version: | Server 1.10.3 |
| Severity: | Keywords: | trait query | |
| Cc: | Database Engine: | SQL Server | |
| Operating System: | N/A |
Description
I was querying for kernel type equal to pop and kernel color equal to white and the query presents an error. It also happens on npgsdev as of today. The error to the user is that your last query caused an error. Kurt looked into the logs and these were not informative. Laura was able to run the query on her dev box.
Attachments (2)
Change History (6)
by , 8 years ago
| Attachment: | query error_2018-11-16.jpg added |
|---|
comment:1 by , 8 years ago
| Priority: | medium → major |
|---|
comment:2 by , 8 years ago
this query caused the time out which I could run against my local sql server without any problem and returns some 600 records:
select
a.accession_id as 'Accession ID',
+ (coalesce(a.accession_number_part1,) + ' ' + coalesce(convert(nvarchar, a.accession_number_part2), ) + ' ' + coalesce(a.accession_number_part3,)) + as 'Plant ID',
coalesce(ctl.title, ct.coded_name) as crop_trait_name,
coalesce(coalesce(ctcl.title, ctc.code, convert(nvarchar, cto.crop_trait_code_id)), string_value, convert(nvarchar, cast(numeric_value as float))) as value
from
crop_trait_observation cto
inner join crop_trait ct
on cto.crop_trait_id = ct.crop_trait_id
left join crop_trait_lang ctl
on ct.crop_trait_id = ctl.crop_trait_id
and ctl.sys_lang_id = 1
left join crop_trait_code ctc
on cto.crop_trait_code_id = ctc.crop_trait_code_id
left join crop_trait_code_lang ctcl
on ctc.crop_trait_code_id = ctcl.crop_trait_code_id
and ctcl.sys_lang_id = 1
left join inventory i
on cto.inventory_id = i.inventory_id
left join accession a
on i.accession_id = a.accession_id
where (cto.is_archived = 'N' and cto.crop_trait_id = 89027 and cto.crop_trait_code_id IN (3909) ) and ( a.accession_id in ( select accession_id from inventory where inventory_id in (
select inventory_id
from crop_trait_observation cto where (cto.is_archived = 'N' and cto.crop_trait_id = 89027 and cto.crop_trait_code_id IN (3909) ) )) and a.accession_id in ( select accession_id from inventory where inventory_id in (
select inventory_id
from crop_trait_observation cto where (cto.is_archived = 'N' and cto.crop_trait_id = 89026 and cto.crop_trait_code_id IN (3904) ) )) ) Union
select
a.accession_id as 'Accession ID',
+ (coalesce(a.accession_number_part1,) + ' ' + coalesce(convert(nvarchar, a.accession_number_part2), ) + ' ' + coalesce(a.accession_number_part3,)) + as 'Plant ID',
coalesce(ctl.title, ct.coded_name) as crop_trait_name,
coalesce(coalesce(ctcl.title, ctc.code, convert(nvarchar, cto.crop_trait_code_id)), string_value, convert(nvarchar, cast(numeric_value as float))) as value
from
crop_trait_observation cto
inner join crop_trait ct
on cto.crop_trait_id = ct.crop_trait_id
left join crop_trait_lang ctl
on ct.crop_trait_id = ctl.crop_trait_id
and ctl.sys_lang_id = 1
left join crop_trait_code ctc
on cto.crop_trait_code_id = ctc.crop_trait_code_id
left join crop_trait_code_lang ctcl
on ctc.crop_trait_code_id = ctcl.crop_trait_code_id
and ctcl.sys_lang_id = 1
left join inventory i
on cto.inventory_id = i.inventory_id
left join accession a
on i.accession_id = a.accession_id
where (cto.is_archived = 'N' and cto.crop_trait_id = 89026 and cto.crop_trait_code_id IN (3904) ) and ( a.accession_id in ( select accession_id from inventory where inventory_id in (
select inventory_id
from crop_trait_observation cto where (cto.is_archived = 'N' and cto.crop_trait_id = 89027 and cto.crop_trait_code_id IN (3909) ) )) and a.accession_id in ( select accession_id from inventory where inventory_id in (
select inventory_id
from crop_trait_observation cto where (cto.is_archived = 'N' and cto.crop_trait_id = 89026 and cto.crop_trait_code_id IN (3904) ) )) ) order by 1, 2, 3
by , 8 years ago
| Attachment: | TheQuery.sql added |
|---|
comment:3 by , 8 years ago
| Milestone: | → Server Release 1.10.4 |
|---|---|
| Resolution: | → fixed |
| Status: | new → closed |
Would still like to find out what exactly is slowing down Kernel Color queries but for now the new index seems to solve the problem. It seems related to the is_archived flag and kernel_color has some archived data. But so do others and they were not affected.
comment:4 by , 5 years ago
Note: The index Quinn added was
CREATE NONCLUSTERED INDEX [ndx_cto_maize] ON [dbo].[crop_trait_observation]
(
[crop_trait_id] ASC,
[crop_trait_code_id] ASC,
[is_archived] ASC
)
INCLUDE([inventory_id],[numeric_value],[string_value])
WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
This helps because of multiple uses in the query of the form
where cto.is_archived = 'N' and cto.crop_trait_id = X and cto.crop_trait_code_id IN (Y)

Query setup that gives error