Skip to content

[SYNCOPE-1855] Rewriting JPAAnySearchDAO to reduce subqueries#957

Merged
ilgrosso merged 11 commits intoapache:3_0_Xfrom
ilgrosso:ANY_SEARCH_DAO_REWRITE
Jan 21, 2025
Merged

[SYNCOPE-1855] Rewriting JPAAnySearchDAO to reduce subqueries#957
ilgrosso merged 11 commits intoapache:3_0_Xfrom
ilgrosso:ANY_SEARCH_DAO_REWRITE

Conversation

@ilgrosso
Copy link
Member

@ilgrosso ilgrosso commented Jan 17, 2025

The current JPAAnySearchDAO implementation is based on incrementally constructing the final query string.

The new implementation is instead meant to build a tree representation and finally generating the query string from it.

The new implementation was initially provided as AnySearchNodeDAO, not updating JPAAnySearchDAO yet to avoid build errors under core/persistence-jpa-json.

TODO:

  • check and fix integration tests running on standard persistence (H2, PostgreSQL, MySQL, MariaDB, Oracle)
  • adjust and check the JPA JSON implementations (PostgreSQL, MySQL, MariaDB, Oracle)

@ilgrosso
Copy link
Member Author

ojson current issue; the generated query is

SELECT DISTINCT sv.any_id,sv.username
FROM user_search sv
WHERE (((plainSchema='fullname' AND ustringValue LIKE '%o%' ESCAPE '\' ) 
AND ((sv.any_id IN (
SELECT DISTINCT any_id FROM user_search_umembership WHERE group_id='37d15e4c-cdc1-460b-a591-8505c8133806') 
OR sv.any_id IN (SELECT DISTINCT any_id FROM UDynGroupMembers WHERE group_id='37d15e4c-cdc1-460b-a591-8505c8133806')))) 
AND (plainSchema='loginDate' AND JSON_VALUE(dateValue, '$[*]')='2009-05-26T00:00:00+02:00') 
) 
ORDER BY sv.username ASC

but returns no results, while the amended

SELECT DISTINCT sv.any_id,sv.username
FROM user_search sv
WHERE ((plainSchema='fullname' AND ustringValue LIKE '%o%' ESCAPE '\')  
OR (plainSchema='loginDate' AND JSON_VALUE(dateValue, '$[*]')='2009-05-26T00:00:00+02:00'))
AND ((sv.any_id IN (
SELECT DISTINCT any_id FROM user_search_umembership WHERE group_id='37d15e4c-cdc1-460b-a591-8505c8133806') 
OR sv.any_id IN (SELECT DISTINCT any_id FROM UDynGroupMembers WHERE group_id='37d15e4c-cdc1-460b-a591-8505c8133806'))) 
GROUP BY sv.any_id,sv.username
HAVING COUNT(*) = 2
ORDER BY sv.username ASC

works as expected.

The problem is recognizing sibling AND conditions for plainSchema and refactoring as OR conditions with GROUP BY / HAVING.

@ilgrosso ilgrosso changed the title Rewriting JPAAnySearchDAO to reduce subqueries [SYNCOPE-1855] Rewriting JPAAnySearchDAO to reduce subqueries Jan 21, 2025
@ilgrosso ilgrosso marked this pull request as ready for review January 21, 2025 11:23
@ilgrosso ilgrosso merged commit db24b63 into apache:3_0_X Jan 21, 2025
28 of 29 checks passed
@ilgrosso ilgrosso deleted the ANY_SEARCH_DAO_REWRITE branch January 21, 2025 12:49
ilgrosso added a commit to ilgrosso/syncope that referenced this pull request Jan 21, 2025
ilgrosso added a commit to ilgrosso/syncope that referenced this pull request Jan 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant