Skip to content

QueryGraph edge-explorer cache does not work for edge-based CH. #1623

Closed

Description

@easbar

We can do

queryGraph.setUseEdgeExplorerCache(true);

and

queryGraph.createEdgeExplorer(edgeFilter)

will return the same edge-explorer instance for all subsequent calls of DefaultEdgeFilter.inEdges, DefaultEdgeFilter.outEdges, DefaultEdgeFilter.allEdges and EdgeFilter.ALL_EDGES (for each of these filters there will be a separate edge-explorer instance).

The problem is that in some cases we explicitly need to create two different instances for the same filter. This is not needed very often, but for example here:

// we need extra edge explorers, because they get called inside a loop that already iterates over edges
innerInExplorer = graph.createEdgeExplorer(DefaultEdgeFilter.inEdges(flagEncoder));
innerOutExplorer = graph.createEdgeExplorer(DefaultEdgeFilter.outEdges(flagEncoder));

there is a nested loop over edge iterators where the 'inner' explorer must be different to the 'outer' one.

Because of this using the edge-explorer cache with edge-based CH fails at the moment.

I started adding a test for the query graph behavior here: 58e7ac1, but so far it does not show much, obviously if we use the same instance of the edge explorer within an inner loop the outer loop will be messed up.

Activity

  1. easbar commented on May 27, 2019

    @easbar
    MemberAuthor

    Was about to add the 'bug' label, but at least the query graph cache is described as an 'experimental' feature at the moment :)

  2. easbar commented on May 27, 2019

    @easbar
    MemberAuthor

    Maybe add a second parameter to createEdgeExplorer that is used as an 'id' to identify the explorer ?

    EdgeExplorer createEdgeExplorer(EdgeFilter filter) {
        return createEdgeExplorer(filter, DEFAULT_ID);
    }
    
    EdgeExplorer createEdgeExplorer(EdgeFilter filter, int explorerId) {
       // use the filter type like we do so far, but also take into account the explorerId to identify the explorer 
    }
    

    Not very pretty thats for sure, but we would need a way to express that we want another instance (and ideally this other instance would still be cached / we do not want another instance for every call).

  3. karussell commented on May 27, 2019

    @karussell
    Member

    but at least the query graph cache is described as an 'experimental' feature at the moment :)

    Ups, you are right. (please remove whenever you like :) )

    The problem is that in some cases we explicitly need to create two different instances for the same filter

    Did you mean the same edge explorer for two different filters? (Because we should return two different instances for the two different filters "inEdges" and "outEdges")

  4. easbar commented on May 27, 2019

    @easbar
    MemberAuthor

    please remove

    no no its fine ;)

    Did you mean the same edge explorer for two different filters?

    No I mean two different explorers for the same filter. Sure there are different instances if we first use an inEdge and then an outEdge filter. But here the problem is that for example we need two different explorers for the inEdge filter.

    EdgeExplorer exp1 = graph.createEdgeExplorer(DefaultEdgeFilter.inEdges());
    EdgeExplorer exp2 = graph.createEdgeExplorer(DefaultEdgeFilter.inEdges());
    
    EdgeIterator outerIter = exp1.setBaseNode(base);
    while (outerIter.next()) {
        EdgeIterator innerIter = exp2.setBaseNode(outerIter.getAdjNode());
        while (innerIter.next()) {
              // whatever
        }
    }

    Obviously if exp1==exp2 this will fail / do something very unexpected.

  5. karussell commented on May 27, 2019

    @karussell
    Member

    What about instead of two methods DefaultEdgeFilter.acceptsForward/acceptsBackward creating the unique integer in QueryGraph via using just one hashCode() method? Then for these special cases we could overload them or do

    EdgeExplorer exp1 = graph.createEdgeExplorer(DefaultEdgeFilter.inEdges(1));
    EdgeExplorer exp2 = graph.createEdgeExplorer(DefaultEdgeFilter.inEdges(2 /* forces different EdgeExplorer instance*/));
    
    // DefaultEdgeFilter:
    int hashCode() {
       int val = additionalValue; // in this example 1 or 2
       if (acceptsBackward())
           val += 1;
       if (acceptsForward())
           val += 2;
       ...
       return val;
    }

    We could then also make this independent of the DefaultEdgeFilter via a CachableEdgeFilter interface or something.

  6. easbar commented on May 27, 2019

    @easbar
    MemberAuthor

    Yeah, I like the idea. So two things basically:

    • if query graph cache is enabled createEdgeExplorer returns the same instance for all filters that are equal in the equals/java sense. This caching mechanism will become independent of DefaultEdgeFilter etc.

    • provide creator, hashCode and equals methods for DefaultEdgeFilter as you suggested so it is easy to create equal instances of the different default edge filter at different code locations.

    Is this what you meant ? I do not think we need a CacheableEdgeFilter and we would also get rid of the previous limitation that the caching did not work for custom filters. To use createEdgeExplorer with the query graph cache one would only have to make sure that equals does what it should for the custom filter.

  7. karussell commented on May 27, 2019

    @karussell
    Member

    Much clearer for me now due to your explanation, but yes 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions