From e617099feb5faaec20a3eff4b7ffce60e22454b1 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Wed, 18 Oct 2023 18:16:08 +0200 Subject: [PATCH] Fix join condition for nested collection query For a list:list:list collection this brings the query from 12.5 seconds (after the database cache is already hot ...) to 11 ms --- lib/galaxy/model/__init__.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/galaxy/model/__init__.py b/lib/galaxy/model/__init__.py index 6652ff72814d..f2904f989c7b 100644 --- a/lib/galaxy/model/__init__.py +++ b/lib/galaxy/model/__init__.py @@ -6145,9 +6145,9 @@ def attribute_columns(column_collection, attributes, nesting_level=None): inner_dc = alias(DatasetCollection) inner_dce = alias(DatasetCollectionElement) order_by_columns.append(inner_dce.c.element_index) - q = q.join(inner_dc, inner_dc.c.id == dce.c.child_collection_id).outerjoin( - inner_dce, inner_dce.c.dataset_collection_id == inner_dc.c.id - ) + q = q.join( + inner_dc, and_(inner_dc.c.id == dce.c.child_collection_id, dce.c.dataset_collection_id == dc.c.id) + ).outerjoin(inner_dce, inner_dce.c.dataset_collection_id == inner_dc.c.id) q = q.add_columns( *attribute_columns(inner_dce.c, element_attributes, nesting_level), *attribute_columns(inner_dc.c, collection_attributes, nesting_level),