You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
**Structure**: Single edge table with type discriminator column
95
107
@@ -137,110 +149,170 @@ WHERE r.interaction_type IN ('FOLLOWS', 'LIKES')
137
149
138
150
---
139
151
152
+
## Dimension 2: Coupled Edge Optimization
153
+
154
+
### What Are Coupled Edges?
155
+
156
+
**Coupled edges** occur when **two or more edges** share the same physical table AND connect through common **coupling nodes**. This creates an opportunity for alias unification and self-join elimination.
157
+
158
+
**Key insight**: This is ORTHOGONAL to the three edge storage patterns above, but most commonly occurs with denormalized schemas.
159
+
160
+
### 2.1 Coupled Edges on Denormalized Tables (Most Common)
161
+
162
+
When multiple edges in the same pattern use the same denormalized table AND connect through a common node, they're "coupled" through that node.
**Note**: Polymorphic schemas require explicit node labels because the edge doesn't have
259
+
static `from_node`/`to_node` values - node types are determined at runtime via
260
+
`from_label_column`/`to_label_column`.
261
+
262
+
### Coupled Edge Optimization
263
+
264
+
| Pattern | Denormalized (with coupled edges) |
265
+
|---------|-----------------------------------|
266
+
| Multi-hop alias unification | ✅ |
267
+
| Self-join elimination | ✅ |
268
+
| Bidirectional coupled | ⚠️ Untested |
175
269
176
270
---
177
271
178
-
## The Polymorphic Multi-Type JOIN Bug
179
-
180
-
**Current Behavior** (buggy):
181
-
```sql
182
-
-- CTE correctly uses IN
183
-
WITH rel_a_b AS (
184
-
SELECT ... FROM interactions WHERE interaction_type IN ('FOLLOWS', 'LIKES')
185
-
)
186
-
-- But JOIN incorrectly uses only first type!
187
-
INNER JOIN interactions AS r ON ... AND r.interaction_type = 'FOLLOWS'
188
-
```
189
-
190
-
**Root Cause**: In `graph_join_inference.rs`, the `pre_filter` is generated correctly via `generate_polymorphic_edge_filter()` with all types, but somewhere the JOIN generation only uses the first type.
272
+
## Optimization Summary
191
273
192
-
**Fix Location**: Need to trace where the JOIN `pre_filter` gets overwritten or where only `rel_types[0]` is used.
274
+
| Optimization | When Applied | Benefit |
275
+
|--------------|--------------|---------|
276
+
| Polymorphic IN clause | `[:A\|B]` on polymorphic edge | Avoid UNION ALL |
277
+
| Denormalized property access | Node property on denormalized edge | Avoid JOIN to node |
278
+
| Coupled edge alias unification | 2+ edges on same denormalized table with coupling node | Eliminate self-JOINs |
3. **Polymorphic multi-type**: `[:FOLLOWS|LIKES]`with single polymorphic table ⚠️
245
-
4. **Mixed schemas**: Some edges standard, some polymorphic
246
-
5. **Wildcard with each schema type**: `[r]`pattern
318
+
This is a specialized optimization for denormalized schemas where a single physical table (like `dns_logs` or `flights`) contains multiple logical relationships.
0 commit comments