-
Notifications
You must be signed in to change notification settings - Fork 1
cost models
Stand: 5. Dezember 2025
Version: 1.0.0
Kategorie: Development
Diese Entwickler-Dokumentation beschreibt die vereinfachten Kostenmodelle, die zur Planwahl für Hybrid Queries in ThemisDB eingesetzt werden.
Eingabeparameter (QueryOptimizer::VectorGeoCostInput):
-
hasVectorIndex: HNSW/ANN Index verfügbar -
hasSpatialIndex: R-Tree verfügbar -
bboxRatio: Fläche des Bounding Box Filters relativ zur Gesamtfläche (Selectivity) -
prefilterSize: Kandidatenmenge nach Equality/Range Prefilter (Index-Intersect) -
spatialIndexEntries: Anzahl der räumlich indexierten Entities -
k: gewünschte Top-k -
vectorDim: Vektordimension (Skalierung der Distanzkosten) -
overfetch: Multiplikator beim Vector-first Plan
Kostenformeln (abstrakte Einheiten):
C_vec = C_vec_base * (vectorDim / 128)
Spatial-first: cost = spatialCandidates * C_index_spatial + spatialCandidates * C_vec
Vector-first: cost = ANN(log(N)*dimScale) + (k * overfetch) * C_spatial_eval
Prefilter-Rabatt reduziert beide Kosten wenn prefilterSize < 0.1 * spatialIndexEntries.
Planwahl: VectorThenSpatial, wenn costVectorFirst < costSpatialFirst, sonst SpatialThenVector.
Ziel: Auswahl zwischen zwei Plänen
- Fulltext-Then-Spatial (FT zuerst, dann Geometrie-Filter + optional Distanz-Boost)
- Spatial-Then-Fulltext (räumliche Kandidaten über SpatialIndex, dann naive Token-Match Evaluierung)
Eingaben (ContentGeoCostInput):
hasFulltextIndexhasSpatialIndex-
fulltextHits(Schätzung, Fallback:limit) -
bboxRatio(Flächenverhältnis BBox/Total) limit
Konstanten (Tuning):
-
C_fulltext_baseBasis für logarithmische FT-Kosten -
C_spatial_evalKosten pro räumlicher Kandidat ohne Index -
C_spatial_indexKosten pro Kandidat mit Index -
smallBBoxBoostRabatt für sehr kleine BBox (<1%)
Formeln:
hits = max(1, fulltextHits or limit)
ftPhase = C_fulltext_base * ln(hits + 5)
spatialPhase_fulltext_first = hits * (hasSpatialIndex ? C_spatial_index : C_spatial_eval) * bboxRatio
costFulltextThenSpatial = ftPhase + spatialPhase_fulltext_first
spatialCandidates ≈ max(1, hits * bboxRatio)
spatialFetch = spatialCandidates * (hasSpatialIndex ? C_spatial_index : C_spatial_eval)
ftEvalCandidates = spatialCandidates * 0.25
costSpatialThenFulltext = spatialFetch + ftEvalCandidates
if bboxRatio < 0.01:
costSpatialThenFulltext *= smallBBoxBoost
chooseFulltextFirst = costFulltextThenSpatial <= costSpatialThenFulltext
Tracer Attribute:
-
optimizer.cg.plan(fulltext_then_spatial|spatial_then_fulltext) optimizer.cg.cost_fulltext_firstoptimizer.cg.cost_spatial_first
Grenzen:
- Spatial-first verwendet naiven Token-AND ohne BM25 Score.
- Bei großem
bboxRatiokaum Vorteil gegenüber Fulltext-first. - Sehr selektive BBox (<1%) bevorzugt Spatial-first.
Ausblick:
- Postinglisten-Längen speichern zur besseren
fulltextHitsSchätzung. - Bloom-Filter / inverted skip lists für schnellere Token-Tests.
- Kostenmodell Einbezug von Distanz-Boost (falls aktiviert).
Ziel: Schätzung der Vertex-Expansion und frühzeitiger Abbruch bei Explosion.
Eingaben (GraphPathCostInput):
-
maxDepth: maximale Traversierungstiefe -
branchingFactor: geschätzte durchschnittliche ausgehende Kanten pro Vertex -
hasSpatialConstraint: räumlicher Filter aktiv -
spatialSelectivity: Anteil der Vertices, die räumliche Bedingung erfüllen (0.0–1.0)
Dynamische Branching-Faktor Schätzung:
- Sampling über erste 2 Tiefen vom Startknoten
- Zähle ausgehende Kanten pro besuchtem Vertex
branchingEstimate = sampledEdges / sampledVertices- Fallback: 1.0 wenn keine Kanten gefunden
Formeln:
expanded = 1 // start node
for d = 1 to maxDepth:
expanded += branchingFactor^d
if hasSpatialConstraint:
expanded *= spatialSelectivity
timeMs = expanded * 0.02 // heuristic constant
Frühabbruch-Heuristik:
- Schwellwert:
ABORT_THRESHOLD = 1e6(1 Million geschätzte Vertices) - Wenn
estimatedExpandedVertices > ABORT_THRESHOLD: Rückgabe leerer Pfadliste - Attribut
optimizer.graph.aborted = truegesetzt
Tracer Attribute:
-
optimizer.graph.branching_estimate: gemessener Branching-Faktor -
optimizer.graph.expanded_estimate: geschätzte Anzahl expandierter Vertices -
optimizer.graph.time_ms_estimate: geschätzte Zeit in Millisekunden -
optimizer.graph.aborted: true wenn Frühabbruch erfolgt
Grenzen:
- Branching-Faktor-Schätzung berücksichtigt nur erste 2 Tiefen (kann bei heterogenen Graphen ungenau sein)
- Spatial Selectivity vereinfacht als globales bbox-Ratio (keine lokale Vertex-Dichte)
- Frühabbruch-Schwellwert statisch (nicht konfigurierbar)
Ausblick:
- Adaptive Schwellwerte basierend auf verfügbarem Memory
- Vertex-Dichte-Histogramme für präzisere Expansion-Schätzung
- Edge-Typ-spezifische Branching-Faktoren
- Inkrementelle Tiefenbegrenzung (iterative deepening) bei unbekanntem Branching
- Gleichheiten: Intersection von PK-Mengen über Einzel-Indizes.
- Ranges: Zusammenführung mehrfacher Bounds pro Feld, Scan über Range-Index.
- Composite-Indizes (zukünftig): Erkennung AND-Ketten aller beteiligten Spalten ->
scanKeysEqualComposite().
-
C_vec_base,C_spatial_eval,C_index_spatial,prefilterDiscountFactoraktuell hartkodiert. - Geplante Migration zu konfigurierbaren Parametern in
config:hybrid_query.
- Span-Attribute:
optimizer.plan,optimizer.cost_spatial_first,optimizer.cost_vector_first. - Ermöglicht Analyse in Tracing Backend für Plan-Qualität.
- Statistische Modelle (Histogramme, Kumulative Verteilung der Distanzwerte) zur verbesserten Annäherung.
- Adaptive Überfetch-Steuerung basierend auf Trefferqualität.
- Dynamische Branching-Faktor Schätzung für Graph Queries anhand realer Nachbarschaftsgrößen.
ThemisDB v1.3.4 | GitHub | Documentation | Discussions | License
Last synced: January 02, 2026 | Commit: 6add659
Version: 1.3.0 | Stand: Dezember 2025
- Übersicht
- Home
- Dokumentations-Index
- Quick Reference
- Sachstandsbericht 2025
- Features
- Roadmap
- Ecosystem Overview
- Strategische Übersicht
- Geo/Relational Storage
- RocksDB Storage
- MVCC Design
- Transaktionen
- Time-Series
- Memory Tuning
- Chain of Thought Storage
- Query Engine & AQL
- AQL Syntax
- Explain & Profile
- Rekursive Pfadabfragen
- Temporale Graphen
- Zeitbereichs-Abfragen
- Semantischer Cache
- Hybrid Queries (Phase 1.5)
- AQL Hybrid Queries
- Hybrid Queries README
- Hybrid Query Benchmarks
- Subquery Quick Reference
- Subquery Implementation
- Content Pipeline
- Architektur-Details
- Ingestion
- JSON Ingestion Spec
- Enterprise Ingestion Interface
- Geo-Processor Design
- Image-Processor Design
- Hybrid Search Design
- Fulltext API
- Hybrid Fusion API
- Stemming
- Performance Tuning
- Migration Guide
- Future Work
- Pagination Benchmarks
- Enterprise README
- Scalability Features
- HTTP Client Pool
- Build Guide
- Implementation Status
- Final Report
- Integration Analysis
- Enterprise Strategy
- Verschlüsselungsstrategie
- Verschlüsselungsdeployment
- Spaltenverschlüsselung
- Encryption Next Steps
- Multi-Party Encryption
- Key Rotation Strategy
- Security Encryption Gap Analysis
- Audit Logging
- Audit & Retention
- Compliance Audit
- Compliance
- Extended Compliance Features
- Governance-Strategie
- Compliance-Integration
- Governance Usage
- Security/Compliance Review
- Threat Model
- Security Hardening Guide
- Security Audit Checklist
- Security Audit Report
- Security Implementation
- Development README
- Code Quality Pipeline
- Developers Guide
- Cost Models
- Todo Liste
- Tool Todo
- Core Feature Todo
- Priorities
- Implementation Status
- Roadmap
- Future Work
- Next Steps Analysis
- AQL LET Implementation
- Development Audit
- Sprint Summary (2025-11-17)
- WAL Archiving
- Search Gap Analysis
- Source Documentation Plan
- Changefeed README
- Changefeed CMake Patch
- Changefeed OpenAPI
- Changefeed OpenAPI Auth
- Changefeed SSE Examples
- Changefeed Test Harness
- Changefeed Tests
- Dokumentations-Inventar
- Documentation Summary
- Documentation TODO
- Documentation Gap Analysis
- Documentation Consolidation
- Documentation Final Status
- Documentation Phase 3
- Documentation Cleanup Validation
- API
- Authentication
- Cache
- CDC
- Content
- Geo
- Governance
- Index
- LLM
- Query
- Security
- Server
- Storage
- Time Series
- Transaction
- Utils
Vollständige Dokumentation: https://makr-code.github.io/ThemisDB/