Commit 89f4dcb
committed
Improve _touch_collection_update_time_cte performance
by avoiding left outer join.
The extra subquery is an sqlalchemy artifact optimized away by the query
planner.
The improved query is this:
```sql
WITH RECURSIVE collection_hierarchy(collection_id, depth_level) AS (
SELECT dataset_collection_element.dataset_collection_id AS collection_id, 0 AS depth_level
FROM dataset_collection_element
JOIN history_dataset_association ON dataset_collection_element.hda_id = history_dataset_association.id
WHERE history_dataset_association.dataset_id = 134996190
UNION
SELECT dataset_collection_element.dataset_collection_id AS collection_id, 0 AS depth_level
FROM dataset_collection_element
JOIN library_dataset_dataset_association ON dataset_collection_element.ldda_id = library_dataset_dataset_association.id
WHERE library_dataset_dataset_association.dataset_id = 134996190
UNION ALL
SELECT parent_dce.dataset_collection_id AS collection_id, ch.depth_level + 1 AS depth_level
FROM dataset_collection_element AS parent_dce
INNER JOIN collection_hierarchy AS ch ON parent_dce.child_collection_id = ch.collection_id
WHERE ch.depth_level < 50
)
SELECT collection_id
FROM collection_hierarchy
ORDER BY collection_id;
```
while before it was:
```sql
WITH RECURSIVE collection_hierarchy(collection_id, depth_level) AS (
SELECT dataset_collection_element.dataset_collection_id AS collection_id, 0 AS depth_level
FROM dataset_collection_element
LEFT OUTER JOIN history_dataset_association ON dataset_collection_element.hda_id = history_dataset_association.id
LEFT OUTER JOIN library_dataset_dataset_association ON dataset_collection_element.ldda_id = library_dataset_dataset_association.id
WHERE history_dataset_association.dataset_id = 134996190 OR library_dataset_dataset_association.dataset_id = 134996190
UNION ALL
SELECT parent_dce.dataset_collection_id AS collection_id, ch.depth_level + 1 AS depth_level
FROM dataset_collection_element AS parent_dce, collection_hierarchy AS ch
WHERE parent_dce.child_collection_id = ch.collection_id AND ch.depth_level < 50
)
SELECT collection_id
FROM collection_hierarchy
ORDER BY collection_id
```1 parent c443d08 commit 89f4dcb
1 file changed
+18
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4727 | 4727 | | |
4728 | 4728 | | |
4729 | 4729 | | |
4730 | | - | |
4731 | | - | |
| 4730 | + | |
| 4731 | + | |
| 4732 | + | |
4732 | 4733 | | |
4733 | 4734 | | |
4734 | | - | |
| 4735 | + | |
4735 | 4736 | | |
4736 | | - | |
4737 | | - | |
4738 | | - | |
4739 | 4737 | | |
4740 | 4738 | | |
4741 | | - | |
4742 | | - | |
4743 | | - | |
4744 | | - | |
| 4739 | + | |
| 4740 | + | |
| 4741 | + | |
| 4742 | + | |
| 4743 | + | |
| 4744 | + | |
| 4745 | + | |
| 4746 | + | |
4745 | 4747 | | |
| 4748 | + | |
4746 | 4749 | | |
4747 | | - | |
| 4750 | + | |
| 4751 | + | |
| 4752 | + | |
| 4753 | + | |
4748 | 4754 | | |
4749 | | - | |
| 4755 | + | |
4750 | 4756 | | |
4751 | 4757 | | |
4752 | 4758 | | |
| |||
0 commit comments