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

Consider using EXISTS for count query #1244

Closed
punktilious opened this issue Jun 18, 2020 · 2 comments
Closed

Consider using EXISTS for count query #1244

punktilious opened this issue Jun 18, 2020 · 2 comments
Assignees
Labels

Comments

@punktilious
Copy link
Collaborator

punktilious commented Jun 18, 2020

Describe the bug

SELECT COUNT(R.RESOURCE_ID)  FROM Basic_LOGICAL_RESOURCES LR 
JOIN Basic_RESOURCES R 
   ON R.LOGICAL_RESOURCE_ID=LR.LOGICAL_RESOURCE_ID 
 AND R.RESOURCE_ID = LR.CURRENT_RESOURCE_ID AND R.IS_DELETED <> 'Y'  
JOIN (SELECT DISTINCT LOGICAL_RESOURCE_ID FROM Basic_TOKEN_VALUES  
           WHERE (PARAMETER_NAME_ID=39 AND ((TOKEN_VALUE = ?)))) Basic0 
ON Basic0.LOGICAL_RESOURCE_ID = R.LOGICAL_RESOURCE_ID

The DISTINCT in the sub-query might prevent the optimizer from picking a better plan. Consider using EXISTS and correlate the sub-query (without distinct) with the main body. Semantically the result should be the same.

To Reproduce
Run JDBCPagingTest as an example.

Expected behavior
Best possible performance.
Additional context
Add any other context about the problem here.

@punktilious punktilious added the performance performance label Jun 18, 2020
@prb112 prb112 added the search label Oct 12, 2020
@punktilious
Copy link
Collaborator Author

This has been implemented as part of #1385

@prb112
Copy link
Contributor

prb112 commented May 10, 2021

Verified during Code Review, the queries do not generate the DISTINCT and use the EXISTS approach to counting. As discussed on the Team call, I am closing this issue.

@prb112 prb112 closed this as completed May 10, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants