Class IndexStatisticsDaemonImpl
- java.lang.Object
-
- org.apache.derby.impl.services.daemon.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:
- schedule update (the only action carried out by the user thread)
- for each index:
- scan index
- invalidate statements dependent on current statistics
- drop existing statistics
- add new statistics
List of possible improvements:
- 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:
- 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 booleanskipDisposableStatsTells 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description voidrun()Drives the statistics generation.voidrunExplicitly(LanguageConnectionContext lcc, TableDescriptor td, ConglomerateDescriptor[] cds, java.lang.String runContext)Runs the statistics update sequence explicitly as requested by the user.voidschedule(TableDescriptor td)Schedules an update of the index statistics for the specified table.voidstop()Stops the 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 todoLog- whether to log activity informationtraceLevel- 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 ownerdatabaseName- 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:
schedulein interfaceIndexStatisticsDaemon- 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:
runin interfacejava.lang.Runnable
-
runExplicitly
public void runExplicitly(LanguageConnectionContext lcc, TableDescriptor td, ConglomerateDescriptor[] cds, java.lang.String runContext) throws StandardException
Runs the statistics update sequence explicitly as requested by the user.- Specified by:
runExplicitlyin interfaceIndexStatisticsDaemon- Parameters:
lcc- connection context to use to perform the worktd- the base tablecds- the indexes to update (non-index conglomerates are ignored)runContext- the context in which the operation is run (i.e. 'ALTER TABLE', may benull)- Throws:
StandardException- if updating the index statistics fails
-
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:
stopin interfaceIndexStatisticsDaemon
-
-
DataMelt 3.0 © DataMelt by jWork.ORG