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

Improve cacheability of filters #871

Draft
wants to merge 2 commits into
base: development
Choose a base branch
from

Conversation

arteymix
Copy link
Member

@arteymix arteymix commented Sep 25, 2023

Sort clauses and sub-clauses so that equivalent queries have identical filters.

Implement padding to the next power-of-two by repeating the last element of a collection.

Break-up filters so we can cache expensive clauses and run simpler queries against the database.

Fix #869 and #870

TODO

  • more testing is needed and we have to identify edge cases

@arteymix arteymix added this to the 1.31.0 milestone Sep 25, 2023
@arteymix arteymix added database Issues that involve the database performance labels Sep 25, 2023
@arteymix arteymix self-assigned this Sep 25, 2023
if ( filters != null ) {
Iterator<Iterable<Filter>> it = filters.iterator();
if ( it.hasNext() ) {
Set<Long> ids = new HashSet<>( doLoadIdsWithCache( Filters.by( IterableUtils.toList( it.next() ) ), null, true ) );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might not be worth to do this for every single filter.

Maybe having a list of properties that are expensive to filter by would be interesting.

* @author tesarst
* @author poirigui
*/
@Value
@EqualsAndHashCode(of = { "objectAlias", "operator", "requiredValue" })
public class Filter implements PropertyMapping {
@EqualsAndHashCode(of = { "objectAlias", "propertyName", "operator", "requiredValue" })
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be included immediatly in the dev branch and next patch release.

*
* <p>
* Clauses and sub-clauses are always sorted by objectAlias, propertyName, operator and requiredValue. A clause is
* sorted by its first element, if any.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not correct, a clause is sorted lexicographically and a sub-clause as mentioned.

@@ -89,7 +89,7 @@ public CacheManager cacheManager() {
@Test
public void testFindTerm() throws OntologySearchException {
Collection<OntologyTerm> matches = gos.findTerm( "toxin" );
assertEquals( 4, matches.size() );
assertEquals( 7, matches.size() );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't be here...

// assertThat( filters.iterator().next().get( 1 ) )
// .hasFieldOrPropertyWithValue( "propertyName", "c" )
// .hasFieldOrPropertyWithValue( "operator", Filter.Operator.eq )
// .hasFieldOrPropertyWithValue( "requiredValue", "d" );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uncomment and fix this test.

// assertThat( filters.iterator().next().get( 1 ) )
// .hasFieldOrPropertyWithValue( "propertyName", "c" )
// .hasFieldOrPropertyWithValue( "operator", Filter.Operator.eq )
// .hasFieldOrPropertyWithValue( "requiredValue", "d" );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uncomment and fix this test.

// assertThat( of.get( 1 ) )
// .hasFieldOrPropertyWithValue( "propertyName", "g" )
// .hasFieldOrPropertyWithValue( "operator", Filter.Operator.eq )
// .hasFieldOrPropertyWithValue( "requiredValue", "h" );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uncomment and fix this test.

// assertThat( of.get( 1 ) )
// .hasFieldOrPropertyWithValue( "propertyName", "e" )
// .hasFieldOrPropertyWithValue( "operator", Filter.Operator.eq )
// .hasFieldOrPropertyWithValue( "requiredValue", "f" );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uncomment and fix this test.

@arteymix arteymix force-pushed the feature-cache-optimization-for-filters branch from 9c76424 to 068b152 Compare September 25, 2023 22:10
@arteymix arteymix force-pushed the development branch 2 times, most recently from 84692c7 to e0ec3da Compare December 4, 2023 19:58
@arteymix arteymix modified the milestones: 1.31.0, 1.32.0 Dec 5, 2023
@arteymix arteymix modified the milestones: 1.32.0, 1.31.1 Jan 23, 2024
Sort clauses and sub-clauses so that equivalent queries have identical
filters.

Implement padding to the next power-of-two by repeating the last element
of a collection.
@arteymix arteymix force-pushed the feature-cache-optimization-for-filters branch from 068b152 to 0b3ce18 Compare January 25, 2024 21:51
@arteymix arteymix modified the milestones: 1.31.1, 1.31.2 Feb 9, 2024
@arteymix
Copy link
Member Author

arteymix commented Mar 7, 2024

This has to be rebased and tested again. I'll try to squeeze it in tomorrow's release.

@arteymix arteymix modified the milestones: 1.31.2, 1.31.4 Apr 3, 2024
@arteymix arteymix removed this from the 1.31.4 milestone Apr 29, 2024
@arteymix arteymix linked an issue Oct 18, 2024 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
database Issues that involve the database performance
Projects
None yet
1 participant