Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimise query used to retrieve metadata links results #7453

Merged
merged 1 commit into from
Mar 19, 2024

Conversation

josegar74
Copy link
Member

The query to retrieve the metadata links status information when using filters, specially with users that are User Administrators and have the Editor profile, can take very long time (more than 45 minutes).

Updated the code to simplify the query with a new one, that semantically should be equivalent. The new one is not superfast, but it finishes in seconds.

Original query

select
    distinct count(distinct link0_.id) as col_0_0_
from
    Links link0_
    inner join MetadataLink records1_ on link0_.id = records1_.linkId
    inner join MetadataLink records2_ on link0_.id = records2_.linkId
    inner join MetadataLink records3_ on link0_.id = records3_.linkId
where
    (
        records1_.metadataId in (
            select
                operationa4_.metadataId
            from
                OperationAllowed operationa4_
                cross join Metadata metadata5_
            where
                metadata5_.id = operationa4_.metadataId
                and (metadata5_.groupOwner in (9))
                or (operationa4_.groupId in (9))
                and operationa4_.operationId = 2
        )
    )
    and (
        records2_.metadataId in (
            select
                operationa6_.metadataId
            from
                OperationAllowed operationa6_
            where
                (operationa6_.groupId in (9))
                and operationa6_.operationId = 0
        )
    )
    and (
        records3_.metadataId in (
            select
                metadata7_.id
            from
                Metadata metadata7_
            where
                metadata7_.groupOwner in (9)
        )
    )

Updated query

select distinct count(distinct link0_.id) as col_0_0_ 
from 
    Links link0_ inner join MetadataLink records1_ on link0_.id=records1_.linkId 
where 
    records1_.metadataId in (
        select 
            operationa2_.metadataId 
        from 
            OperationAllowed operationa2_ 
            cross join Metadata metadata3_
         where 
            (metadata3_.id=operationa2_.metadataId 
            
            and 
                (metadata3_.groupOwner in (9)) or (operationa2_.groupId in (9)) 
                        and operationa2_.operationId=2) 
		 		
            and 
                (operationa2_.groupId in (9)) and operationa2_.operationId=0 
		 	
            and 
                (metadata3_.groupOwner in (9)))

Checklist

  • I have read the [contribution guidelines](https://github.com/geonetwork/core-geonetwork/blob/main/CONTRIBUTING.md
  • Pull request provided for main branch, backports managed with label
  • Good housekeeping of code, cleaning up comments, tests, and documentation
  • Clean commit history broken into understandable chucks, avoiding big commits with hundreds of files, cautious of reformatting and whitespace changes
  • Clean commit messages, longer verbose messages are encouraged
  • API Changes are identified in commit messages
  • Testing provided for features or enhancements using automatic tests)
  • User documentation provided for new features or enhancements in mannual
  • Build documentation provided for development instructions in README.md files
  • Library management using pom.xml dependency management. Update build documentation with intended library use and library tutorials or documentation

@josegar74 josegar74 added this to the 4.4.1 milestone Oct 24, 2023
@fxprunayre fxprunayre modified the milestones: 4.4.1, 4.4.2 Nov 22, 2023
@fxprunayre fxprunayre modified the milestones: 4.4.2, 4.4.3 Jan 23, 2024
@fxprunayre fxprunayre modified the milestones: 4.4.3, 4.4.4 Mar 13, 2024
@josegar74 josegar74 merged commit b044e90 into geonetwork:main Mar 19, 2024
6 checks passed
@juanluisrp juanluisrp deleted the metadatalinks-query-optimisation branch March 19, 2024 17:15
@juanluisrp juanluisrp restored the metadatalinks-query-optimisation branch March 19, 2024 17:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants