org.eclipse.rdf4j.sail.extensiblestore.evaluationstatistics

## Class ExtensibleDynamicEvaluationStatistics

- java.lang.Object
- - org.eclipse.rdf4j.query.algebra.evaluation.impl.EvaluationStatistics
  - - org.eclipse.rdf4j.sail.extensiblestore.evaluationstatistics.ExtensibleEvaluationStatistics
    - - org.eclipse.rdf4j.sail.extensiblestore.evaluationstatistics.ExtensibleDynamicEvaluationStatistics

- All Implemented Interfaces:
    DynamicStatistics

      @Experimental
      public class ExtensibleDynamicEvaluationStatistics
      extends ExtensibleEvaluationStatistics
      implements DynamicStatistics

  ExtensibleDynamicEvaluationStatistics aims to keep an internal estimate of the cardinality of various statement patterns.

  It support getting the overall size, any single dimension cardinality (eg. ?a rdf:type ?b) and also two multidimensional patterns (:Peter rdf:type ?b; and ?a rdf:type foaf:Person).

  Since evaluation statistics are best-effort, we use HLL as sets to keep the number of statements for each pattern we support. HLL is a very memory efficient set implementation. Furthermore we hash each pattern into a fixed bucket size, 1024 for single dimension and 64 per dimension for multidimensional patterns.

  This means that adding ':peter rdf:type foaf:Person' and ':lisa rdf:type foaf:Person' could potentially return getCardinality(:peter, ?b, ?c) = 2 if both :peter and :lisa hash to the same of the 1024 buckets in subjectIndex.

  HLL does not support "remove" operations, so there are two sets of every index. One for all added statements and one for all removed statements. If the user adds, removes and re-adds the same statement then the cardinality for that statement will be incorrect. We call this effect "staleness". To prevent staleness from affecting the returned cardinalities this class needs to be monitored by calling the staleness(...) method. This will automatically be done every 60 seconds by the ExtensibleSailStore.

- - ### Nested Class Summary

    - ### Nested classes/interfaces inherited from class org.eclipse.rdf4j.query.algebra.evaluation.impl.EvaluationStatistics

      `EvaluationStatistics.CardinalityCalculator`

  - ### Field Summary

    - ### Fields inherited from class org.eclipse.rdf4j.query.algebra.evaluation.impl.EvaluationStatistics

      `cc`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ExtensibleDynamicEvaluationStatistics(ExtensibleSailStore extensibleSailStore)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `add(ExtensibleStatement statement)`
    `protected EvaluationStatistics.CardinalityCalculator` | `createCardinalityCalculator()`
    `void` | `remove(ExtensibleStatement statement)`
    `void` | `removeByQuery(Resource subj, IRI pred, Value obj, boolean inferred, Resource... contexts)`
    `double` | `staleness(long expectedSize)`
    `void` | `waitForQueue()`

    - ### Methods inherited from class org.eclipse.rdf4j.query.algebra.evaluation.impl.EvaluationStatistics

      `getCardinality`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ExtensibleDynamicEvaluationStatistics

          public ExtensibleDynamicEvaluationStatistics(ExtensibleSailStore extensibleSailStore)

  - ### Method Detail

    - #### createCardinalityCalculator

          protected EvaluationStatistics.CardinalityCalculator createCardinalityCalculator()

      Specified by:
        `createCardinalityCalculator` in class `ExtensibleEvaluationStatistics`

    - #### staleness

          public double staleness(long expectedSize)

      Specified by:
        `staleness` in interface `DynamicStatistics`
      Returns:
        1 if stale, 0 if not stale, 0.5 if 50% stale. Seen as, given a random statement (that has either been added, or removed), what is the probability that the statistics will return an incorrect result?

    - #### add

          public void add(ExtensibleStatement statement)

      Specified by:
        `add` in interface `DynamicStatistics`

    - #### remove

          public void remove(ExtensibleStatement statement)

      Specified by:
        `remove` in interface `DynamicStatistics`

    - #### removeByQuery

          public void removeByQuery(Resource subj,
                                    IRI pred,
                                    Value obj,
                                    boolean inferred,
                                    Resource... contexts)

      Specified by:
        `removeByQuery` in interface `DynamicStatistics`

    - #### waitForQueue

          public void waitForQueue()
                            throws InterruptedException

      Throws:
        `InterruptedException`

Copyright © 2015-2022 Eclipse Foundation. All Rights Reserved.