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