1use crate::store::{
18 AdjacencyReadMemory, GraphExecutionRead, GraphExecutionWrite, PrunedNodeScan,
19 PrunedRelationshipScan, ScanControl, SourceScanCandidateRow, SourceScanCandidateVisit,
20 SourceScanReadLimits,
21};
22use crate::QueryMemoryLease;
23use hawdb_core::error::Result;
24use hawdb_core::schema::Catalog;
25use hawdb_core::{LabelId, RelTypeId};
26use hawdb_plan_cypher::NodeProjectionAccess;
27use hawdb_storage::store::{GraphScanControl, GraphStore};
28use hawdb_storage::{
29 adjacency::{AdjacencyDirection, OrderedAdjacencyEntry},
30 mutation::{GraphMutation, MutationLimits, MutationSummary, NodeSetAssignment, PropertyFilter},
31 NodeId, NodeRecord, ProjectedNodeRecord, RelId, RelRecord,
32};
33use std::collections::BTreeSet;
34
35fn to_store_control(control: ScanControl) -> GraphScanControl {
36 match control {
37 ScanControl::Continue => GraphScanControl::Continue,
38 ScanControl::Stop => GraphScanControl::Stop,
39 }
40}
41
42fn to_execution_control(control: GraphScanControl) -> ScanControl {
43 match control {
44 GraphScanControl::Continue => ScanControl::Continue,
45 GraphScanControl::Stop => ScanControl::Stop,
46 }
47}
48
49fn adapt_node_consumer(
50 consumer: &mut dyn FnMut(NodeRecord) -> Result<ScanControl>,
51 visit: impl FnOnce(&mut dyn FnMut(NodeRecord) -> GraphScanControl) -> Result<GraphScanControl>,
52) -> Result<ScanControl> {
53 let mut consumer_error = None;
54 let control = visit(&mut |node| match consumer(node) {
55 Ok(control) => to_store_control(control),
56 Err(error) => {
57 consumer_error = Some(error);
58 GraphScanControl::Stop
59 }
60 })?;
61 match consumer_error {
62 Some(error) => Err(error),
63 None => Ok(to_execution_control(control)),
64 }
65}
66
67impl hawdb_storage::read_view::GraphReadAllocation for QueryMemoryLease {
68 fn bytes(&self) -> usize {
69 self.bytes()
70 }
71 fn grow(&mut self, bytes: usize) -> hawdb_core::Result<()> {
72 QueryMemoryLease::grow(self, bytes)
73 }
74}
75
76impl GraphExecutionRead for GraphStore {
77 fn file_descriptor_context(&self) -> Option<hawdb_storage::file_descriptors::FileOpenContext> {
78 GraphStore::file_descriptor_context(self)
79 }
80
81 fn is_out_of_core(&self) -> bool {
82 GraphStore::is_out_of_core(self)
83 }
84
85 fn projected_node_owned_admitted(
86 &self,
87 id: NodeId,
88 label_ids: Option<&[LabelId]>,
89 required_properties: &BTreeSet<String>,
90 admit: &mut dyn FnMut(usize) -> Result<()>,
91 ) -> Result<Option<ProjectedNodeRecord>> {
92 GraphStore::projected_node_for_labels_owned_admitted(
93 self,
94 id,
95 label_ids,
96 required_properties,
97 admit,
98 )
99 }
100
101 fn node_owned(&self, id: NodeId) -> Result<Option<NodeRecord>> {
102 GraphStore::node_owned(self, id)
103 }
104
105 fn relationship_owned(&self, id: RelId) -> Result<Option<RelRecord>> {
106 GraphStore::relationship_owned(self, id)
107 }
108
109 fn node_with_allocation(
110 &self,
111 id: NodeId,
112 label_ids: Option<&[LabelId]>,
113 admit: &mut hawdb_storage::read_view::ControlledGraphReadAllocator<'_>,
114 ) -> Result<hawdb_storage::read_view::AdmittedNodeRead> {
115 GraphStore::node_with_allocation(self, id, label_ids, admit)
116 }
117
118 fn relationship_property_endpoint_candidates(
119 &self,
120 rel_type: RelTypeId,
121 constraints: hawdb_storage::store::RelationshipSeedConstraints<'_>,
122 endpoints: hawdb_storage::store::RelationshipEndpoints,
123 max_relationships: usize,
124 admit: &mut dyn FnMut(
125 usize,
126 ) -> Result<
127 Option<Box<dyn hawdb_storage::read_view::GraphReadAllocation>>,
128 >,
129 ) -> Result<Option<hawdb_storage::store::EndpointCandidates>> {
130 GraphStore::relationship_property_endpoint_candidates(
131 self,
132 rel_type,
133 constraints,
134 endpoints,
135 max_relationships,
136 admit,
137 )
138 }
139
140 fn relationship_with_allocation(
141 &self,
142 id: RelId,
143 admit: &mut hawdb_storage::read_view::ControlledGraphReadAllocator<'_>,
144 ) -> Result<hawdb_storage::read_view::AdmittedRelationshipRead> {
145 GraphStore::relationship_with_allocation(self, id, admit)
146 }
147
148 fn projected_relationship_with_allocation(
149 &self,
150 id: RelId,
151 required_properties: &BTreeSet<String>,
152 admit: &mut hawdb_storage::read_view::ControlledGraphReadAllocator<'_>,
153 ) -> Result<hawdb_storage::read_view::AdmittedRelationshipRead> {
154 GraphStore::projected_relationship_with_allocation(self, id, required_properties, admit)
155 }
156
157 fn scan_nodes_borrowed<'a>(
158 &'a self,
159 label_id: Option<LabelId>,
160 ) -> Box<dyn Iterator<Item = &'a NodeRecord> + 'a> {
161 Box::new(GraphStore::scan_nodes(self, label_id))
162 }
163
164 fn scan_indexed_nodes_borrowed<'a>(
165 &'a self,
166 label_id: LabelId,
167 property: &str,
168 value: &hawdb_core::Value,
169 ) -> Option<Box<dyn Iterator<Item = &'a NodeRecord> + 'a>> {
170 Some(Box::new(GraphStore::seek_nodes_by_property(
171 self, label_id, property, value,
172 )))
173 }
174
175 fn node_count_for_label(&self, label_id: Option<LabelId>) -> usize {
176 GraphStore::node_count_for_label(self, label_id)
177 }
178
179 fn visit_indexed_projected_nodes_by_property_admitted(
180 &self,
181 label_id: LabelId,
182 property: &str,
183 values: &[hawdb_core::Value],
184 properties: &BTreeSet<String>,
185 admit: &mut hawdb_storage::read_view::GraphReadAllocator<'_>,
186 consumer: &mut dyn FnMut(ProjectedNodeRecord) -> Result<ScanControl>,
187 ) -> Result<Option<ScanControl>> {
188 GraphStore::visit_indexed_projected_nodes_by_property_admitted(
189 self,
190 label_id,
191 property,
192 values,
193 properties,
194 admit,
195 &mut |node| consumer(node).map(to_store_control),
196 )
197 .map(|control| control.map(to_execution_control))
198 }
199
200 fn relationship_count_for_type(&self, rel_type: Option<RelTypeId>) -> usize {
201 GraphStore::relationship_count_for_type(self, rel_type)
202 }
203
204 fn visit_nodes_owned(
205 &self,
206 label_id: Option<LabelId>,
207 consumer: &mut dyn FnMut(NodeRecord) -> Result<ScanControl>,
208 ) -> Result<ScanControl> {
209 GraphStore::try_visit_nodes_owned(self, label_id, |node| {
210 consumer(node).map(to_store_control)
211 })
212 .map(to_execution_control)
213 }
214
215 fn visit_relationships_with_allocation(
216 &self,
217 rel_type: Option<RelTypeId>,
218 admit: &mut hawdb_storage::read_view::ControlledGraphReadAllocator<'_>,
219 consumer: &mut dyn FnMut(
220 hawdb_storage::read_view::AdmittedRelationshipRecord,
221 ) -> Result<ScanControl>,
222 ) -> Result<ScanControl> {
223 GraphStore::visit_relationships_with_allocation(self, rel_type, admit, &mut |record| {
224 consumer(record).map(to_store_control)
225 })
226 .map(to_execution_control)
227 }
228
229 fn visit_nodes_with_allocation(
230 &self,
231 label_id: Option<LabelId>,
232 admit: &mut hawdb_storage::read_view::ControlledGraphReadAllocator<'_>,
233 consumer: &mut dyn FnMut(
234 hawdb_storage::read_view::AdmittedNodeRecord,
235 ) -> Result<ScanControl>,
236 ) -> Result<ScanControl> {
237 GraphStore::visit_nodes_with_allocation(self, label_id, admit, &mut |node| {
238 consumer(node).map(to_store_control)
239 })
240 .map(to_execution_control)
241 }
242
243 fn visit_nodes_by_access_with_allocation(
244 &self,
245 label_id: LabelId,
246 access: &NodeProjectionAccess,
247 admit: &mut hawdb_storage::read_view::ControlledGraphReadAllocator<'_>,
248 consumer: &mut dyn FnMut(
249 hawdb_storage::read_view::AdmittedNodeRecord,
250 ) -> Result<ScanControl>,
251 ) -> Result<ScanControl> {
252 GraphStore::visit_nodes_by_access_with_allocation(
253 self,
254 label_id,
255 access,
256 admit,
257 &mut |node| consumer(node).map(to_store_control),
258 )
259 .map(to_execution_control)
260 }
261
262 fn visit_projected_nodes_admitted(
263 &self,
264 label_id: Option<LabelId>,
265 properties: &BTreeSet<String>,
266 admit: &mut hawdb_storage::read_view::GraphReadAllocator<'_>,
267 consumer: &mut dyn FnMut(ProjectedNodeRecord) -> Result<ScanControl>,
268 ) -> Result<ScanControl> {
269 GraphStore::visit_projected_nodes_admitted(self, label_id, properties, admit, &mut |node| {
270 consumer(node).map(to_store_control)
271 })
272 .map(to_execution_control)
273 }
274
275 fn visit_projected_nodes_with_allocation(
276 &self,
277 label_id: Option<LabelId>,
278 properties: &BTreeSet<String>,
279 admit: &mut hawdb_storage::read_view::ControlledGraphReadAllocator<'_>,
280 consumer: &mut dyn FnMut(
281 hawdb_storage::read_view::AdmittedProjectedNode,
282 ) -> Result<ScanControl>,
283 ) -> Result<ScanControl> {
284 GraphStore::visit_projected_nodes_with_allocation(
285 self,
286 label_id,
287 properties,
288 admit,
289 &mut |node| consumer(node).map(to_store_control),
290 )
291 .map(to_execution_control)
292 }
293
294 fn visit_projected_nodes_by_access_admitted(
295 &self,
296 label_id: LabelId,
297 access: &NodeProjectionAccess,
298 properties: &BTreeSet<String>,
299 admit: &mut hawdb_storage::read_view::GraphReadAllocator<'_>,
300 consumer: &mut dyn FnMut(ProjectedNodeRecord) -> Result<ScanControl>,
301 ) -> Result<ScanControl> {
302 GraphStore::visit_projected_nodes_by_access_admitted(
303 self,
304 label_id,
305 access,
306 properties,
307 admit,
308 &mut |node| consumer(node).map(to_store_control),
309 )
310 .map(to_execution_control)
311 }
312
313 fn visit_projected_nodes_by_property_admitted(
314 &self,
315 label_id: LabelId,
316 property: &str,
317 values: &[hawdb_core::Value],
318 properties: &BTreeSet<String>,
319 admit: &mut hawdb_storage::read_view::GraphReadAllocator<'_>,
320 consumer: &mut dyn FnMut(ProjectedNodeRecord) -> Result<ScanControl>,
321 ) -> Result<ScanControl> {
322 GraphStore::visit_projected_nodes_by_property_admitted(
323 self,
324 label_id,
325 property,
326 values,
327 properties,
328 admit,
329 &mut |node| consumer(node).map(to_store_control),
330 )
331 .map(to_execution_control)
332 }
333
334 fn visit_projected_nodes_owned(
335 &self,
336 label_id: Option<LabelId>,
337 required_properties: &BTreeSet<String>,
338 consumer: &mut dyn FnMut(ProjectedNodeRecord) -> Result<ScanControl>,
339 ) -> Result<ScanControl> {
340 let mut consumer_error = None;
341 let control =
342 GraphStore::visit_projected_nodes_owned(self, label_id, required_properties, |node| {
343 match consumer(node) {
344 Ok(control) => to_store_control(control),
345 Err(error) => {
346 consumer_error = Some(error);
347 GraphScanControl::Stop
348 }
349 }
350 })?;
351 match consumer_error {
352 Some(error) => Err(error),
353 None => Ok(to_execution_control(control)),
354 }
355 }
356
357 fn visit_projected_nodes_by_access_owned(
358 &self,
359 label_id: LabelId,
360 access: &NodeProjectionAccess,
361 required_properties: &BTreeSet<String>,
362 consumer: &mut dyn FnMut(ProjectedNodeRecord) -> Result<ScanControl>,
363 ) -> Result<ScanControl> {
364 let mut consumer_error = None;
365 let control = GraphStore::visit_projected_nodes_by_access_owned(
366 self,
367 label_id,
368 access,
369 required_properties,
370 |node| match consumer(node) {
371 Ok(control) => to_store_control(control),
372 Err(error) => {
373 consumer_error = Some(error);
374 GraphScanControl::Stop
375 }
376 },
377 )?;
378 match consumer_error {
379 Some(error) => Err(error),
380 None => Ok(to_execution_control(control)),
381 }
382 }
383
384 fn visit_projected_nodes_by_property_owned(
385 &self,
386 label_id: LabelId,
387 property: &str,
388 values: &[hawdb_core::Value],
389 required_properties: &BTreeSet<String>,
390 consumer: &mut dyn FnMut(ProjectedNodeRecord) -> Result<ScanControl>,
391 ) -> Result<ScanControl> {
392 let mut consumer_error = None;
393 let control = GraphStore::visit_projected_nodes_by_property_owned(
394 self,
395 label_id,
396 property,
397 values,
398 required_properties,
399 |node| match consumer(node) {
400 Ok(control) => to_store_control(control),
401 Err(error) => {
402 consumer_error = Some(error);
403 GraphScanControl::Stop
404 }
405 },
406 )?;
407 match consumer_error {
408 Some(error) => Err(error),
409 None => Ok(to_execution_control(control)),
410 }
411 }
412
413 fn visit_nodes_by_property_owned(
414 &self,
415 label_id: LabelId,
416 property: &str,
417 values: &[hawdb_core::Value],
418 consumer: &mut dyn FnMut(NodeRecord) -> Result<ScanControl>,
419 ) -> Result<ScanControl> {
420 let mut consumer_error = None;
421 let control =
422 GraphStore::visit_nodes_by_property_owned(self, label_id, property, values, |node| {
423 match consumer(node) {
424 Ok(control) => to_store_control(control),
425 Err(error) => {
426 consumer_error = Some(error);
427 GraphScanControl::Stop
428 }
429 }
430 })?;
431 match consumer_error {
432 Some(error) => Err(error),
433 None => Ok(to_execution_control(control)),
434 }
435 }
436
437 fn visit_nodes_by_composite_property_owned(
438 &self,
439 label_id: LabelId,
440 predicates: &[(String, hawdb_core::Value)],
441 consumer: &mut dyn FnMut(NodeRecord) -> Result<ScanControl>,
442 ) -> Result<ScanControl> {
443 adapt_node_consumer(consumer, |consumer| {
444 GraphStore::visit_nodes_by_composite_property_owned(
445 self, label_id, predicates, consumer,
446 )
447 })
448 }
449
450 fn visit_nodes_by_composite_range_owned(
451 &self,
452 label_id: LabelId,
453 seek: &hawdb_plan_cypher::CompositeRangeSeek,
454 consumer: &mut dyn FnMut(NodeRecord) -> Result<ScanControl>,
455 ) -> Result<ScanControl> {
456 adapt_node_consumer(consumer, |consumer| {
457 GraphStore::visit_nodes_by_composite_range_owned(self, label_id, seek, consumer)
458 })
459 }
460
461 fn visit_nodes_by_property_range_owned(
462 &self,
463 label_id: LabelId,
464 property: &str,
465 lower: Option<&(hawdb_core::Value, bool)>,
466 upper: Option<&(hawdb_core::Value, bool)>,
467 consumer: &mut dyn FnMut(NodeRecord) -> Result<ScanControl>,
468 ) -> Result<ScanControl> {
469 adapt_node_consumer(consumer, |consumer| {
470 GraphStore::visit_nodes_by_property_range_owned(
471 self, label_id, property, lower, upper, consumer,
472 )
473 })
474 }
475
476 fn visit_nodes_by_full_text_property_owned(
477 &self,
478 label_id: LabelId,
479 property: &str,
480 query: &str,
481 consumer: &mut dyn FnMut(NodeRecord) -> Result<ScanControl>,
482 ) -> Result<ScanControl> {
483 adapt_node_consumer(consumer, |consumer| {
484 GraphStore::visit_nodes_by_full_text_property_owned(
485 self, label_id, property, query, consumer,
486 )
487 })
488 }
489
490 fn projected_graph_definition(
491 &self,
492 name: &str,
493 ) -> Option<hawdb_storage::projection::ProjectedGraphDefinition> {
494 GraphStore::projected_graph_definition(self, name).cloned()
495 }
496
497 fn visit_source_scan_candidates(
498 &self,
499 predicate: &hawdb_storage::scan::ScanPredicate,
500 limits: SourceScanReadLimits,
501 task_context: Option<&hawdb_core::RuntimeTaskContext>,
502 consumer: &mut dyn FnMut(SourceScanCandidateRow) -> Result<ScanControl>,
503 ) -> Result<SourceScanCandidateVisit> {
504 let mut consumer_error = None;
505 let visit = GraphStore::visit_published_source_scan_candidates_bounded(
506 self,
507 predicate,
508 hawdb_storage::store::SourceScanCandidateLimits::bounded(
509 limits.io_depth,
510 limits.max_coalesced_bytes,
511 limits.max_wave_bytes,
512 limits.max_live_candidate_bytes,
513 ),
514 task_context,
515 &mut |row| match consumer(SourceScanCandidateRow {
516 node_id: row.node_id,
517 properties: row.properties,
518 }) {
519 Ok(control) => Ok(to_store_control(control)),
520 Err(error) => {
521 consumer_error = Some(error);
522 Ok(hawdb_storage::store::GraphScanControl::Stop)
523 }
524 },
525 )?;
526 if let Some(error) = consumer_error {
527 return Err(error);
528 }
529 Ok(match visit {
530 hawdb_storage::store::SourceScanCandidateVisit::Rows {
531 graph_epoch,
532 skipped_segment_count,
533 report,
534 candidate_count,
535 } => SourceScanCandidateVisit::Rows {
536 graph_epoch,
537 skipped_segment_count,
538 report,
539 candidate_count,
540 },
541 hawdb_storage::store::SourceScanCandidateVisit::Fallback(reason) => {
542 SourceScanCandidateVisit::Fallback(reason)
543 }
544 })
545 }
546
547 fn visit_adjacent_relationships_owned(
548 &self,
549 node_id: NodeId,
550 rel_type: Option<RelTypeId>,
551 direction: AdjacencyDirection,
552 consumer: &mut dyn FnMut(RelRecord) -> Result<ScanControl>,
553 ) -> Result<ScanControl> {
554 GraphStore::try_visit_adjacent_relationships_owned(
555 self,
556 node_id,
557 rel_type,
558 direction,
559 |relationship| consumer(relationship).map(to_store_control),
560 )
561 .map(to_execution_control)
562 }
563
564 fn visit_ordered_adjacent_relationships_owned(
565 &self,
566 node_id: NodeId,
567 rel_type: Option<RelTypeId>,
568 direction: AdjacencyDirection,
569 memory: AdjacencyReadMemory<'_>,
570 consumer: &mut dyn FnMut(RelRecord) -> Result<ScanControl>,
571 ) -> Result<ScanControl> {
572 GraphExecutionRead::visit_ordered_adjacent_relationships_with_allocation(
573 self,
574 node_id,
575 rel_type,
576 direction,
577 memory,
578 &mut hawdb_storage::read_view::ControlledGraphReadAllocator::new(
579 &mut |bytes| memory.admit_node(bytes, 0, None).map(Some),
580 None,
581 ),
582 &mut |relationship| {
583 let (relationship, _allocation) = relationship.into_parts();
584 consumer(relationship)
585 },
586 )
587 }
588
589 fn visit_ordered_adjacent_relationships_with_allocation(
590 &self,
591 node_id: NodeId,
592 rel_type: Option<RelTypeId>,
593 direction: AdjacencyDirection,
594 memory: AdjacencyReadMemory<'_>,
595 admit: &mut hawdb_storage::read_view::ControlledGraphReadAllocator<'_>,
596 consumer: &mut dyn FnMut(
597 hawdb_storage::read_view::AdmittedRelationshipRecord,
598 ) -> Result<ScanControl>,
599 ) -> Result<ScanControl> {
600 GraphStore::visit_ordered_adjacent_relationships_with_allocation(
601 self,
602 node_id,
603 rel_type,
604 direction,
605 memory.budget_bytes,
606 admit,
607 |relationship| consumer(relationship).map(to_store_control),
608 )
609 .map(to_execution_control)
610 }
611
612 fn visit_ordered_projected_relationships_with_allocation(
613 &self,
614 adjacency: (NodeId, Option<RelTypeId>, AdjacencyDirection),
615 required_properties: &BTreeSet<String>,
616 memory: AdjacencyReadMemory<'_>,
617 admit: &mut hawdb_storage::read_view::ControlledGraphReadAllocator<'_>,
618 consumer: &mut dyn FnMut(
619 hawdb_storage::read_view::AdmittedRelationshipRecord,
620 ) -> Result<ScanControl>,
621 ) -> Result<ScanControl> {
622 GraphStore::visit_ordered_projected_relationships_with_allocation(
623 self,
624 adjacency,
625 required_properties,
626 memory.budget_bytes,
627 admit,
628 |relationship| consumer(relationship).map(to_store_control),
629 )
630 .map(to_execution_control)
631 }
632
633 fn visit_ordered_adjacency_entries_with_allocation(
634 &self,
635 adjacency: (NodeId, Option<RelTypeId>, AdjacencyDirection),
636 memory: AdjacencyReadMemory<'_>,
637 admit: &mut hawdb_storage::read_view::ControlledGraphReadAllocator<'_>,
638 consumer: &mut dyn FnMut(OrderedAdjacencyEntry) -> Result<ScanControl>,
639 ) -> Result<ScanControl> {
640 GraphStore::visit_ordered_adjacency_entries_with_allocation(
641 self,
642 adjacency,
643 memory.budget_bytes,
644 admit,
645 |entry| consumer(entry).map(to_store_control),
646 )
647 .map(to_execution_control)
648 }
649
650 fn visit_filtered_ordered_relationships_with_allocation(
651 &self,
652 adjacency: (NodeId, Option<RelTypeId>, AdjacencyDirection),
653 filter: &PropertyFilter,
654 memory: AdjacencyReadMemory<'_>,
655 admit: &mut hawdb_storage::read_view::ControlledGraphReadAllocator<'_>,
656 consumer: &mut dyn FnMut(
657 hawdb_storage::read_view::AdmittedRelationshipRecord,
658 ) -> Result<ScanControl>,
659 ) -> Result<(ScanControl, Option<hawdb_storage::scan::ScanPruningReport>)> {
660 GraphStore::visit_filtered_ordered_relationships_with_allocation(
661 self,
662 adjacency,
663 filter,
664 memory.budget_bytes,
665 admit,
666 |row| consumer(row).map(to_store_control),
667 )
668 .map(|(control, report)| (to_execution_control(control), report))
669 }
670
671 fn visit_adjacent_relationships_with_filter_owned(
672 &self,
673 node_id: NodeId,
674 rel_type: Option<RelTypeId>,
675 direction: AdjacencyDirection,
676 filter: &PropertyFilter,
677 consumer: &mut dyn FnMut(RelRecord) -> Result<ScanControl>,
678 ) -> Result<(ScanControl, Option<hawdb_storage::scan::ScanPruningReport>)> {
679 let mut consumer_error = None;
680 let (control, report) = GraphStore::visit_adjacent_relationships_with_filter_owned(
681 self,
682 node_id,
683 rel_type,
684 direction,
685 filter,
686 |relationship| match consumer(relationship) {
687 Ok(control) => to_store_control(control),
688 Err(error) => {
689 consumer_error = Some(error);
690 GraphScanControl::Stop
691 }
692 },
693 )?;
694 match consumer_error {
695 Some(error) => Err(error),
696 None => Ok((to_execution_control(control), report)),
697 }
698 }
699
700 fn visit_ordered_adjacent_relationships_with_filter_owned(
701 &self,
702 node_id: NodeId,
703 rel_type: Option<RelTypeId>,
704 direction: AdjacencyDirection,
705 filter: &PropertyFilter,
706 memory: AdjacencyReadMemory<'_>,
707 consumer: &mut dyn FnMut(RelRecord) -> Result<ScanControl>,
708 ) -> Result<(ScanControl, Option<hawdb_storage::scan::ScanPruningReport>)> {
709 GraphStore::visit_filtered_ordered_relationships_with_allocation(
710 self,
711 (node_id, rel_type, direction),
712 filter,
713 memory.budget_bytes,
714 &mut hawdb_storage::read_view::ControlledGraphReadAllocator::new(
715 &mut |bytes| memory.admit_node(bytes, 0, None).map(Some),
716 None,
717 ),
718 |row| {
719 let (relationship, _allocation) = row.into_parts();
720 consumer(relationship).map(to_store_control)
721 },
722 )
723 .map(|(control, report)| (to_execution_control(control), report))
724 }
725
726 fn visit_relationships_owned(
727 &self,
728 rel_type: Option<RelTypeId>,
729 consumer: &mut dyn FnMut(RelRecord) -> Result<ScanControl>,
730 ) -> Result<ScanControl> {
731 GraphStore::try_visit_relationships_owned(self, rel_type, |relationship| {
732 consumer(relationship).map(to_store_control)
733 })
734 .map(to_execution_control)
735 }
736
737 fn scan_relationships_with_filter_pruning<'a>(
738 &'a self,
739 rel_type: Option<RelTypeId>,
740 filter: Option<&PropertyFilter>,
741 ) -> Result<PrunedRelationshipScan<'a>> {
742 let scan = GraphStore::scan_relationships_with_filter_pruning(self, rel_type, filter);
743 Ok(PrunedRelationshipScan {
744 relationships: Box::new(scan.relationships.into_iter().cloned()),
745 report: scan.report,
746 })
747 }
748
749 fn scan_nodes_with_filter_pruning<'a>(
750 &'a self,
751 catalog: &Catalog,
752 label_id: Option<LabelId>,
753 filter: Option<&PropertyFilter>,
754 ) -> Result<PrunedNodeScan<'a>> {
755 let scan = GraphStore::scan_nodes_with_filter_pruning(self, catalog, label_id, filter);
756 Ok(PrunedNodeScan {
757 nodes: Box::new(scan.nodes.into_iter().map(std::borrow::Cow::Borrowed)),
758 report: scan.report,
759 })
760 }
761
762 fn scan_nodes_with_filter_pruning_admitted<'a>(
763 &'a self,
764 catalog: &Catalog,
765 label_id: Option<LabelId>,
766 filter: Option<&PropertyFilter>,
767 admit: &mut dyn FnMut(
768 usize,
769 )
770 -> Result<Box<dyn hawdb_storage::read_view::GraphReadAllocation>>,
771 ) -> Result<PrunedNodeScan<'a>> {
772 let (scan, allocation) = GraphStore::scan_nodes_with_filter_pruning_admitted(
773 self, catalog, label_id, filter, admit,
774 )?;
775 Ok(PrunedNodeScan {
776 nodes: Box::new(scan.nodes.into_iter().map(move |node| {
777 let _retained_allocation = &allocation;
778 std::borrow::Cow::Borrowed(node)
779 })),
780 report: scan.report,
781 })
782 }
783}
784
785impl GraphExecutionWrite for GraphStore {
786 fn commit_mutation_with_limits(
787 &mut self,
788 catalog: &mut Catalog,
789 mutation: GraphMutation,
790 limits: MutationLimits,
791 ) -> Result<MutationSummary> {
792 GraphStore::commit_mutation_with_limits(self, catalog, mutation, limits)
793 }
794
795 fn commit_mutations_with_limits(
796 &mut self,
797 catalog: &mut Catalog,
798 mutations: Vec<GraphMutation>,
799 limits: MutationLimits,
800 ) -> Result<MutationSummary> {
801 GraphStore::commit_mutations_with_limits(self, catalog, mutations, limits)
802 }
803
804 fn set_node_properties_by_ids_with_limits(
805 &mut self,
806 catalog: &mut Catalog,
807 ids: &[NodeId],
808 assignments: &[NodeSetAssignment],
809 limits: MutationLimits,
810 ) -> Result<Vec<NodeId>> {
811 GraphStore::set_node_properties_by_ids_with_limits(self, catalog, ids, assignments, limits)
812 }
813
814 fn delete_node_ids_with_limits(
815 &mut self,
816 catalog: &mut Catalog,
817 ids: &[NodeId],
818 detach: bool,
819 limits: MutationLimits,
820 ) -> Result<Vec<NodeId>> {
821 GraphStore::delete_node_ids_with_limits(self, catalog, ids, detach, limits)
822 }
823
824 fn commit_mutation_with_output(
825 &mut self,
826 catalog: &mut Catalog,
827 mutation: GraphMutation,
828 limits: MutationLimits,
829 project: &mut crate::store::MutationOutputProjector<'_>,
830 ) -> Result<Vec<crate::Row>> {
831 let mut transaction = self.begin_mutation_transaction(catalog);
834 let summary = transaction.stage_mutation_without_commit_rows(mutation, limits)?;
835 let rows = project(
836 transaction.catalog(),
837 crate::store::MutationReturnStores {
838 before: self,
839 after: transaction.store(),
840 },
841 &summary,
842 )?;
843 self.commit_mutation_transaction_and_relational(
844 catalog,
845 transaction,
846 hawdb_storage::relational::RelationalTransaction::default(),
847 limits,
848 )?;
849 Ok(rows)
850 }
851}