Skip to content

Commit 8427ae4

Browse files
committed
fixing counting bugs and advnaced queries
1 parent 8574ef8 commit 8427ae4

File tree

12 files changed

+3315
-90
lines changed

12 files changed

+3315
-90
lines changed

CHANGELOG.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,81 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
- Issue and PR templates
1515
- Migration guide for repository split
1616

17+
## [1.0.4] - 2025-12-10
18+
19+
### Fixed
20+
- **Critical: Node/Edge Count Tracking During DETACH DELETE** - Edge counts became incorrect (negative, double-counted, or stale) during `DETACH DELETE` operations
21+
- `deleteEdgesWithPrefix()` was deleting edges but not returning count of edges actually deleted
22+
- `deleteNodeInTxn()` wasn't tracking edges deleted along with the node
23+
- `BulkDeleteNodes()` only decremented node count, not edge count for cascade-deleted edges
24+
- Unit tests showed counts going negative or remaining high after deletes, resetting to zero only on restart
25+
- Fixed by updating `deleteEdgesWithPrefix()` signature to return `(int64, []EdgeID, error)`
26+
- Fixed `deleteNodeInTxn()` to aggregate and return edges deleted with node
27+
- Fixed `BulkDeleteNodes()` to correctly decrement `edgeCount` and notify `edgeDeleted` callbacks
28+
- Added comprehensive tests in `pkg/storage/async_engine_delete_stats_test.go`
29+
- **Impact**: `/admin/stats` and Cypher `count()` queries now remain accurate during bulk delete operations
30+
31+
- **Critical: ORDER BY Ignored for Relationship Patterns** - `ORDER BY`, `SKIP`, and `LIMIT` clauses were completely ignored for queries with relationship patterns
32+
- Queries like `MATCH (p:Person)-[:WORKS_IN]->(a:Area) RETURN p.name ORDER BY p.name` returned unordered results
33+
- `executeMatchWithRelationships()` was returning immediately without applying post-processing clauses
34+
- Fixed by capturing result, applying ORDER BY/SKIP/LIMIT, then returning
35+
- Affects all queries with relationship traversal: `(a)-[:TYPE]->(b)`, `(a)<-[:TYPE]-(b)`, chained patterns
36+
- **Impact**: Fixes data integrity issues where clients relied on sorted results
37+
38+
- **Critical: Cartesian Product MATCH Returns Zero Rows** - Comma-separated node patterns returned empty results instead of cartesian product
39+
- `MATCH (p:Person), (a:Area) RETURN p.name, a.code` returned 0 rows (should return N×M combinations)
40+
- `executeMatch()` only parsed first pattern, ignoring subsequent comma-separated patterns
41+
- Fixed by detecting multiple patterns via `splitNodePatterns()` and routing to new `executeCartesianProductMatch()`
42+
- Now correctly generates all combinations of matched nodes
43+
- Supports WHERE filtering, aggregation, ORDER BY, SKIP, LIMIT on cartesian results
44+
- **Impact**: Critical for Northwind-style bulk insert patterns like `MATCH (s), (c) CREATE (p)-[:REL]->(c)`
45+
46+
- **Critical: Cartesian Product CREATE Only Creates One Relationship** - `MATCH` with multiple patterns followed by `CREATE` only created relationships for first match
47+
- `MATCH (p:Person), (a:Area) CREATE (p)-[:WORKS_IN]->(a)` created 1 relationship (should create 3 for 3 persons × 1 area)
48+
- `executeMatchCreateBlock()` was collecting only first matching node per pattern variable
49+
- Fixed by collecting ALL matching nodes and iterating through cartesian product combinations
50+
- Each CREATE now executes once per combination in the cartesian product
51+
- **Impact**: Fixes bulk relationship creation patterns used in data import workflows
52+
53+
- **UNWIND CREATE with RETURN Returns Variable Name Instead of Values** - Return clause after `UNWIND...CREATE` returned literal variable names
54+
- `UNWIND ['A','B','C'] AS name CREATE (n {name: name}) RETURN n.name` returned `["name","name","name"]` (should be `["A","B","C"]`)
55+
- `replaceVariableInQuery()` failed to handle variables inside curly braces like `{name: name}`
56+
- String splitting on spaces left `name}` which didn't match variable `name`
57+
- Fixed by properly trimming braces `{}[]()` and preserving surrounding punctuation during replacement
58+
- **Impact**: Fixes all UNWIND+CREATE+RETURN workflows, critical for bulk data ingestion with result tracking
59+
60+
### Changed
61+
- **Cartesian Product Performance** - New `executeCartesianProductMatch()` efficiently handles multi-pattern queries
62+
- Builds combinations incrementally to avoid memory explosion on large datasets
63+
- Supports early filtering with WHERE clause before building full product
64+
- Properly integrates with query optimizer (ORDER BY, SKIP, LIMIT applied after filtering)
65+
66+
### Technical Details
67+
- Modified `pkg/storage/badger.go`:
68+
- Fixed `deleteEdgesWithPrefix()` to return accurate count and edge IDs
69+
- Fixed `deleteNodeInTxn()` to track and return edges deleted with node
70+
- Fixed `BulkDeleteNodes()` to correctly decrement edge count for cascade deletes
71+
- Modified `pkg/cypher/match.go`:
72+
- Added `executeCartesianProductMatch()` for comma-separated pattern handling
73+
- Added `executeCartesianAggregation()` for aggregation over cartesian results
74+
- Added `evaluateWhereForContext()` for WHERE clause evaluation on node contexts
75+
- Fixed `executeMatch()` to detect and route multiple patterns correctly
76+
- Fixed relationship pattern path to apply ORDER BY/SKIP/LIMIT before returning
77+
- Modified `pkg/cypher/create.go`:
78+
- Updated `executeMatchCreateBlock()` to collect all pattern matches (not just first)
79+
- Added cartesian product iteration for CREATE execution
80+
- Now creates relationships for every combination in MATCH cartesian product
81+
- Modified `pkg/cypher/clauses.go`:
82+
- Fixed `replaceVariableInQuery()` to handle variables in property maps `{key: value}`
83+
- Improved punctuation preservation during variable substitution
84+
85+
### Test Coverage
86+
- All existing tests pass (100% backwards compatibility)
87+
- Added `pkg/storage/async_engine_delete_stats_test.go` with comprehensive count tracking tests
88+
- Fixed `TestWorksInRelationshipTypeAlternation` - ORDER BY now works correctly
89+
- Fixed `TestUnwindWithCreate/UNWIND_CREATE_with_RETURN` - Returns actual values, not variable names
90+
- Cartesian product patterns now pass all Northwind benchmark compatibility tests
91+
1792
## [1.0.3] - 2025-12-09
1893

1994
### Fixed

0 commit comments

Comments
 (0)