Opened 9 years ago

Closed 9 years ago

#1471 closed defect (fixed)

Packing dataviews too slow on SQL Server 2016

Reported by: Kurt Endress Owned by: Kurt Endress
Priority: major Milestone:
Component: Dataviews (CT) Version: N/A
Severity: Keywords:
Cc: Database Engine: SQL Server
Operating System: N/A

Description

The report dataviews order_packing2 and order_packing_nsgc often time out when used with the new SQL Server 2016 database. This seems to be due to the new optimizer with 2014 as it still works in 2012 compatibility mode.

Change History (2)

comment:1 by Kurt Endress, 9 years ago

Changes made to the two packing report dataviews. They work under 2016. Loaded on npgsdev for additional testing.

order_packing_nsgc_20170504.dataview
order_packing2_20170504.dataview

Change details follow.

This was the sub-select join I replaced:

INNER JOIN (

SELECT order_request_item_id FROM order_request_item

WHERE order_request_item_id IN (:orderrequestitemid)


UNION SELECT order_request_item_id FROM order_request_item

WHERE order_request_id IN (:orderrequestid)

UNION SELECT order_request_item_id FROM order_request_item

WHERE web_order_request_item_id IN (:weborderrequestitemid)

UNION SELECT order_request_item_id FROM order_request_item

WHERE inventory_id IN (:inventoryid)

UNION SELECT order_request_item_id FROM order_request_item

WHERE source_cooperator_id IN (:cooperatorid)

UNION SELECT ori.order_request_item_id FROM order_request_item ori

INNER JOIN inventory i ON i.inventory_id = ori.inventory_id
WHERE i.accession_id IN (:accessionid)

UNION SELECT ori.order_request_item_id FROM order_request_item ori

INNER JOIN order_request o ON o.order_request_id = ori.order_request_id
WHERE o.web_order_request_id IN (:weborderrequestid)

) list ON oi.order_request_item_id = list.order_request_item_id

With this:

WHERE oi.order_request_id IN (:orderrequestid)

Simplifying that makes the optimizer work for these two dataviews without adding an index to the database. That looks like a clear win for simplification, but to get it to support two id parameters I had to duplicate the other 147 lines of SQL into a separate UNION SELECT statement with a where on the item ids. Avoiding multiple copies of large select blocks was the reason I switched to the sub-select join of parameters. But in this case it seems to confuse the optimizer

I also made a slight change to a sub-select that pulled taxonomic usage restriction when I noticed it was slowing down large orders:

FROM inventory
INNER JOIN accession ON accession.accession_id = inventory.accession_id
INNER JOIN taxonomy_species ON taxonomy_species.taxonomy_species_id = accession.taxonomy_species_id
OR taxonomy_species.current_taxonomy_species_id = accession.taxonomy_species_id
INNER JOIN taxonomy_use tu ON tu.taxonomy_species_id = taxonomy_species.taxonomy_species_id

Simplified to:

FROM inventory
INNER JOIN accession ON accession.accession_id = inventory.accession_id
INNER JOIN taxonomy_species ON taxonomy_species.current_taxonomy_species_id = accession.taxonomy_species_id
INNER JOIN taxonomy_use tu ON tu.taxonomy_species_id = taxonomy_species.taxonomy_species_id

The idea is to find tax use notes the accession’s taxon and also for synonyms of the taxon. I supplied the original to Karen from John’s notes on how he did it in Oracle. But looking at the code again I realized I could get rid of the OR and get the same result.

comment:2 by Kurt Endress, 9 years ago

Resolution: → fixed
Status: new → closed

Placed on production 7/1/2017 and included in 1.9.9.2 build

Note: See TracTickets for help on using tickets.