mini\Table\Wrappers\OptimizingTable class

Documentation

Adaptive optimization wrapper that measures and improves table access patterns

Wraps any table and transparently optimizes repeated operations:

  • Builds TreapIndex for frequently accessed columns
  • Escalates to SQLite (InMemoryTable) for large datasets
  • Measures actual performance to make decisions

Use hints when caller knows access patterns upfront:

$optimized = OptimizingTable::from($table)
    ->withExpectedHasCalls(10000)
    ->withIndexOn('user_id', 'order_id');

Inheritance

Extends: mini\Table\Wrappers\AbstractTableWrapper

Implements: mini\Table\Contracts\TableInterface Traversable Countable IteratorAggregate mini\Table\Contracts\SetInterface

Constants (4)

Name Value
MEASURE_CALLS 3
INDEX_BENEFIT_THRESHOLD_MS 50.0
SQLITE_ROW_THRESHOLD 500000
SQLITE_TIME_THRESHOLD 2.0

Properties (17)

private int $expectedHasCalls
private int $expectedEqCalls
private array $indexColumns
private int $hasCallCount
private float $hasTotalTime
private array $eqCallCounts
private array $eqTotalTimes
private ?mini\Table\Index\TreapIndex $hasIndex
private array $columnIndexes
private ?mini\Table\InMemoryTable $materialized
private string $hasStrategy
private array $eqStrategies
private ?array $rowCache
protected mini\Table\AbstractTable $source
protected ?Closure $compareFn
protected ?int $limit
protected int $offset

Methods (52)

Wrap a table for optimization, or return if already wrapped

Hint: expected number of has() calls

Hint: expected number of eq() calls

Hint: columns that will be used for eq() lookups

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Get all rows, caching for reuse during index building

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Get current optimization state for debugging

Documentation missing

Get the source table this wrapper delegates to

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Hook for subclasses to customize clone behavior

Get column name(s) that the row key represents

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Get the current table alias (null if not set)

Documentation missing

Documentation missing

Documentation missing

Documentation missing

Get the primary key column definition (cached)

Iterate over rows with visible columns only

Return table with property set

Source

src/Table/Wrappers/OptimizingTable.php:28-413