Skip to content

feat: add cost model framework with deref/array support#84

Merged
JohannesLichtenberger merged 2 commits intomasterfrom
feature/cost-model-deref
Jan 29, 2026
Merged

feat: add cost model framework with deref/array support#84
JohannesLichtenberger merged 2 commits intomasterfrom
feature/cost-model-deref

Conversation

@JohannesLichtenberger
Copy link
Member

Implement a cost model framework for query optimization with support for JSON/JSONiq-specific operations.

Components:

  • CostModel interface with cost estimation and comparison methods
  • OperatorContext for HFT-style zero-allocation context passing
  • SimpleCostModel with calibrated cost factors for:
    • Basic operations: scan, selection, join, sort, group-by
    • Deref operations: field navigation with depth-based costing
    • Array operations: access, unboxing, slicing costs

Design principles:

  • ThreadLocal pooling for OperatorContext (no allocation in hot paths)
  • Primitive fields to avoid boxing overhead
  • Configurable cost factors via system properties
  • Cost clamping for robustness (NaN, infinity, negative)

Includes comprehensive unit tests for all cost estimation methods.

Johannes Lichtenberger added 2 commits January 25, 2026 23:33
Implement a cost model framework for query optimization with support
for JSON/JSONiq-specific operations.

Components:
- CostModel interface with cost estimation and comparison methods
- OperatorContext for HFT-style zero-allocation context passing
- SimpleCostModel with calibrated cost factors for:
  - Basic operations: scan, selection, join, sort, group-by
  - Deref operations: field navigation with depth-based costing
  - Array operations: access, unboxing, slicing costs

Design principles:
- ThreadLocal pooling for OperatorContext (no allocation in hot paths)
- Primitive fields to avoid boxing overhead
- Configurable cost factors via system properties
- Cost clamping for robustness (NaN, infinity, negative)

Includes comprehensive unit tests for all cost estimation methods.
- Convert SimpleCostModelTest from JUnit 5 to JUnit 4 (project uses JUnit 4)
- Fix test pattern for ThreadLocal pooling: compute costs immediately
  after configuring context since acquire() returns same pooled instance
- Fix bug in OperatorContext.forArrayAccess: isArrayAccess should be
  false for single access, true for full unboxing
@JohannesLichtenberger JohannesLichtenberger merged commit 50d0183 into master Jan 29, 2026
2 checks passed
@JohannesLichtenberger JohannesLichtenberger deleted the feature/cost-model-deref branch January 29, 2026 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant