Documentation of 'org.apache.derby.impl.services.daemon.IndexStatisticsDaemonImpl' Java class
IndexStatisticsDaemonImpl
org.apache.derby.impl.services.daemon

Class IndexStatisticsDaemonImpl

  • All Implemented Interfaces:
    java.lang.Runnable, IndexStatisticsDaemon


    public class IndexStatisticsDaemonImpl
    extends java.lang.Object
    implements IndexStatisticsDaemon, java.lang.Runnable
    Daemon acting as a coordinator for creating and updating index cardinality statistics.

    The need for updated statistics is currently determined when compiling a SELECT query. The unit of work is then scheduled with this daemon, and the work itself will be carried out in a separate thread. If the worker thread doesn't exist it is created, if it is idle the unit of work will be processed immediately, and if it is busy the unit of work has to wait in the queue.

    The daemon code has a notion of a background task. If the update is run as a background task, it will try to affect other activity in the Derby database as little as possible. As far as possible, it will not set locks on the conglomerates it scans, and if it needs to take locks it will give up immediately if the locks cannot be obtained. In some cases it will also roll back to release locks already taken, ad then retry. Since we are accessing shared structures the background work may still interfere with the user activity in the database due to locking, but all such operations carried out by the daemon are of short duration.

    The high level flow of an update to index statistics is:

    1. schedule update (the only action carried out by the user thread)
    2. for each index:
      1. scan index
      2. invalidate statements dependent on current statistics
      3. drop existing statistics
      4. add new statistics

    List of possible improvements:

    1. Reduce potential impact of multiple invalidations (per table), probably by finding a way to invalidate only once after all indexes for a table have had their statistics updated. So far invalidation has proven to be the most difficult piece of the puzzle due to the interaction with the data dictionary and sensitivity to concurrent activity for the table.

    Implementation notes: List of potential cleanups before going into a release:

    1. Consider removing all tracing code. May involve improving logging if parts of the trace output is valuable enough.
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      boolean skipDisposableStats
      Tells if disposable stats should be generated, which will happen in soft-upgrade mode or when the user asks us to revert to the old behavior.
    • Constructor Summary

      Constructors 
      Constructor and Description
      IndexStatisticsDaemonImpl(HeaderPrintWriter log, boolean doLog, java.lang.String traceLevel, Database db, java.lang.String userName, java.lang.String databaseName)
      Creates a new daemon.
    • Field Detail

      • skipDisposableStats

        public final boolean skipDisposableStats
        Tells if disposable stats should be generated, which will happen in soft-upgrade mode or when the user asks us to revert to the old behavior.

        Made public to allow access for CreateIndexConstantAction and FromBaseTable, but this is no longer necessary when the debug property to keep disposable statistics is removed.

    • Constructor Detail

      • IndexStatisticsDaemonImpl

        public IndexStatisticsDaemonImpl(HeaderPrintWriter log,
                                         boolean doLog,
                                         java.lang.String traceLevel,
                                         Database db,
                                         java.lang.String userName,
                                         java.lang.String databaseName)
        Creates a new daemon.
        Parameters:
        log - the log to write to
        doLog - whether to log activity information
        traceLevel - whether, and to where, trace information should be written ("off|log|stdout|both")
        db - the database ("off|log|stdout|both")
        userName - the name of the database owner
        databaseName - the name of the database (not stored in the db obj)
    • Method Detail

      • schedule

        public void schedule(TableDescriptor td)
        Schedules an update of the index statistics for the specified table.

        Assume the descriptor will be valid until we get around to generate the statistics. If it turns out to be invalid, it will be discarded.

        Specified by:
        schedule in interface IndexStatisticsDaemon
        Parameters:
        td - base table descriptor to update index statistics for
      • run

        public void run()
        Drives the statistics generation.

        This method will be run in a separate thread, and it will keep working as long as there is work to do. When the queue is exhausted, the method will exit (the thread dies).

        Specified by:
        run in interface java.lang.Runnable
      • stop

        public void stop()
        Stops the daemon.

        Will also clear the queue and print runtime statistics to the log the first time the method is invoked.

        Specified by:
        stop in interface IndexStatisticsDaemon

DataMelt 3.0 © DataMelt by jWork.ORG

Ads help maintain this website.