P1 Fixes Quick Reference
P1 Fixes Quick Reference
Quick reference guide for the three implemented P1 TODO fixes.
P1-5: Branch Merge with Auto-Delete
SQL Syntax
-- Delete source branch after successful mergeMERGE BRANCH feature_branch INTO mainWITH ( conflict_resolution = 'branch_wins', delete_branch_after = true)Code Location
/home/claude/HeliosDB Nano/src/sql/executor/phase3.rs
- Lines 183-191: Deletion logic
- Lines 507-518: Helper function
Behavior
- ✅ Deletes source branch only after successful merge
- ✅ Skips deletion if merge has conflicts
- ✅ Logs deletion for audit trail
- ✅ Respects
delete_branch_afterboolean value
P1-6: CREATE INDEX WITH Options
SQL Syntax
-- HNSW vector index with full configurationCREATE INDEX embedding_idx ON documents USING hnsw (embedding)WITH ( -- HNSW parameters m = 16, ef_construction = 200,
-- Quantization quantization = 'product', pq_subquantizers = 8, pq_centroids = 256,
-- Sharding sharding_strategy = 'hash', shard_count = 16)Supported Options
| Option | Type | Example | Description |
|---|---|---|---|
quantization | string | 'product' | Quantization type: none, scalar, product, auto |
pq_subquantizers | number | 8 | Product quantization subquantizers |
pq_centroids | number | 256 | Product quantization centroids |
m | number | 16 | HNSW M parameter (connections per node) |
ef_construction | number | 200 | HNSW construction effort |
sharding_strategy | string | 'hash' | Sharding strategy |
shard_count | number | 16 | Number of shards |
Code Location
/home/claude/HeliosDB Nano/src/sql/planner.rs
- Line 119: Integration point
- Lines 851-950: Parser implementation
Examples
Minimal Configuration:
CREATE INDEX idx ON table USING hnsw (col) WITH (m = 16)Product Quantization:
CREATE INDEX idx ON table USING hnsw (col)WITH ( quantization = 'product', pq_subquantizers = 8, pq_centroids = 256)Sharded Index:
CREATE INDEX idx ON table USING hnsw (col)WITH ( sharding_strategy = 'hash', shard_count = 16)P1-7: AS OF Time-Travel Queries
SQL Syntax
Timestamp-Based:
SELECT * FROM orders AS OF TIMESTAMP '2025-11-15 06:00:00'WHERE id = 1Transaction-Based:
SELECT * FROM orders AS OF TRANSACTION 987654System Change Number:
SELECT * FROM orders AS OF SCN 123456789Current Time:
SELECT * FROM orders AS OF NOWCode Location
/home/claude/HeliosDB Nano/src/sql/planner.rs
- Lines 19-20, 40-43: Planner SQL storage
- Line 341: Integration point
- Lines 354-392: AS OF parser
Usage Pattern
use heliosdb_nano::sql::{Parser, Planner};
let sql = "SELECT * FROM orders AS OF TIMESTAMP '2025-11-15 06:00:00'";let parser = Parser::new();let statement = parser.parse_one(sql)?;
// Pass original SQL to planner for AS OF parsinglet planner = Planner::new() .with_catalog(&catalog) .with_sql(sql.to_string());
let plan = planner.statement_to_plan(statement)?;// Plan now includes AS OF clause in Scan nodeSupported AS OF Types
| Type | Format | Example |
|---|---|---|
| Timestamp | TIMESTAMP 'YYYY-MM-DD HH:MM:SS' | AS OF TIMESTAMP '2025-11-15 06:00:00' |
| Transaction | TRANSACTION <id> | AS OF TRANSACTION 987654 |
| SCN | SCN <number> | AS OF SCN 123456789 |
| Now | NOW | AS OF NOW |
Testing
Run All Tests
cargo test p1_todo_fixes_tests --libRun Individual Tests
# P1-5: Branch deletioncargo test test_p1_5_branch_delete_after_merge --lib
# P1-6: Index optionscargo test test_p1_6_create_index_with_options --lib
# P1-7: AS OF parsingcargo test test_p1_7_as_of_clause_parsing --lib
# Integration testcargo test test_p1_integration_all_fixes --libRun with Output
cargo test p1_todo_fixes_tests --lib -- --nocaptureCommon Issues & Solutions
P1-5: Branch Not Deleted
Symptom: Source branch still exists after merge
Possible Causes:
delete_branch_afternot set totrue- Merge had conflicts (deletion only on successful merge)
- Storage engine error
Solution:
-- Ensure option is set correctlyMERGE BRANCH source INTO targetWITH (delete_branch_after = true) -- Must be true
-- Check merge succeeded without conflicts-- If conflicts exist, resolve them firstP1-6: Index Options Not Applied
Symptom: Index created but options seem ignored
Possible Causes:
- SQL syntax error in WITH clause
- Invalid option name or value
- Option not supported by index type
Solution:
-- Check option names (case-insensitive, use underscores)WITH (m = 16) -- CorrectWITH (M = 16) -- Also correctWITH ("m" = 16) -- Wrong - don't quote option names
-- Check value typesWITH (m = 16) -- Correct (number)WITH (m = '16') -- Wrong (string)WITH (quantization = 'product') -- Correct (string)WITH (quantization = product) -- Wrong (unquoted)P1-7: AS OF Not Working
Symptom: Query doesn’t return historical data
Possible Causes:
- Planner not initialized with SQL string
- AS OF syntax incorrect
- Timestamp format invalid
Solution:
// Must call with_sql() for AS OF parsinglet planner = Planner::new() .with_catalog(&catalog) .with_sql(sql.to_string()); // Required!
// Check SQL syntax"AS OF TIMESTAMP '2025-11-15 06:00:00'" // Correct"AS OF TIMESTAMP 2025-11-15 06:00:00" // Wrong - needs quotes"ASOF TIMESTAMP '2025-11-15 06:00:00'" // Wrong - needs spaceIntegration Examples
Complete Example: Time-Travel Query with Indexed Search
-- Step 1: Create tableCREATE TABLE documents ( id SERIAL PRIMARY KEY, embedding VECTOR(1536), content TEXT)
-- Step 2: Create optimized vector indexCREATE INDEX embedding_idx ON documents USING hnsw (embedding)WITH ( m = 16, ef_construction = 200, quantization = 'product', pq_subquantizers = 8)
-- Step 3: Query historical data with vector searchSELECT id, content, embedding <-> '[1.0, 2.0, ...]'::vector AS distanceFROM documents AS OF TIMESTAMP '2025-11-15 06:00:00'ORDER BY distanceLIMIT 10Branch Workflow with Auto-Cleanup
-- Create feature branchCREATE BRANCH feature_x FROM main AS OF NOW
-- Switch to feature branchUSE BRANCH feature_x
-- Make changes...INSERT INTO documents (content, embedding) VALUES (...)
-- Merge back to main with auto-cleanupMERGE BRANCH feature_x INTO mainWITH ( conflict_resolution = 'branch_wins', delete_branch_after = true -- Auto-delete after merge)Performance Tips
P1-5: Branch Deletion
- Branch deletion is fast (single metadata operation)
- No impact on merge performance
- Safe to enable for automated workflows
P1-6: Index Options
- Choose quantization based on dataset size:
none: < 10K vectorsscalar: 10K-100K vectorsproduct: > 100K vectors
- Tune HNSW parameters:
- Higher
m: Better recall, more memory - Higher
ef_construction: Better quality, slower build
- Higher
P1-7: AS OF Queries
- AS OF parsing has negligible overhead
- Time-travel queries may be slower (historical data access)
- Use indexes on historical queries for best performance
- Consider caching frequently accessed timestamps
Error Messages
P1-5 Errors
"Merge failed: N conflicts detected. Use conflict_resolution='branch_wins', 'target_wins', or remove the option for auto resolution."Fix: Resolve conflicts or specify conflict_resolution strategy
P1-6 Errors
"Invalid quantization type: X. Expected 'none', 'scalar', 'product', or 'auto'"Fix: Use valid quantization type
"Unknown CREATE INDEX option: X"Fix: Check option name spelling
P1-7 Errors
"Invalid AS OF clause: X. Expected NOW, TIMESTAMP, TRANSACTION, or SCN"Fix: Use correct AS OF syntax
See Also
- Full implementation details:
P1_FIXES_IMPLEMENTATION_SUMMARY.md - Test suite:
tests/p1_todo_fixes_tests.rs - Phase 3 features:
docs/implementation/PHASE_3_* - Time-travel docs:
TIME_TRAVEL_IMPLEMENTATION_SUMMARY.md - Branch storage docs:
docs/BRANCH_STORAGE_GUIDE.md