hawdb 0.16.0

An embedded Rust graph database for local data-plane workloads
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
// Copyright 2026 Nowledge
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

use crate::analytics::{ProjectionLayout, ProjectionMemoryBudget};
#[cfg(test)]
use crate::cypher::RelationshipDirection;
#[cfg(test)]
use crate::error::HawDBError;
use crate::error::Result;
use crate::optimizer::PhysicalPlan;
#[cfg(test)]
use crate::planner::GraphAlgorithmKind;
#[cfg(test)]
use crate::planner::Predicate;
#[cfg(test)]
use crate::planner::{SetNodePropertiesReturnMode, SetValue};
use crate::schema::Catalog;
use crate::store::{GraphStore, MutationLimits, ProjectedGraphDefinition, ScanPruningReport};
use crate::value::Value;
use hawdb_core::RuntimeTaskContext;
use hawdb_executor::ExecutionLimit;
use std::collections::BTreeMap;

pub(crate) fn unsupported_scoring_input_error() -> crate::error::HawDBError {
    crate::error::HawDBError::Semantic("scoring requires a batch-capable candidate query".into())
}

#[cfg(test)]
use std::num::NonZeroU64;
#[cfg(test)]
use std::num::NonZeroUsize;

/// Umbrella bound for the engine a root executor entry may drive.
#[allow(private_bounds)]
pub trait ExecutionStore:
    hawdb_storage::graph_engine::GraphReadEngine
    + hawdb_storage::graph_engine::GraphMutationEngine
    + hawdb_executor::store::GraphExecutionWrite
    + crate::store::InternalGraphEngine
    + hawdb_relational::row_runtime::RelationalRowStoreReader
    + hawdb_relational::index_runtime::RelationalIndexStoreReader
{
}

impl<T> ExecutionStore for T where
    T: hawdb_storage::graph_engine::GraphReadEngine
        + hawdb_storage::graph_engine::GraphMutationEngine
        + hawdb_executor::store::GraphExecutionWrite
        + crate::store::InternalGraphEngine
        + hawdb_relational::row_runtime::RelationalRowStoreReader
        + hawdb_relational::index_runtime::RelationalIndexStoreReader
{
}

#[cfg(test)]
use crate::planner::{Aggregation, Projection, RelationshipCountLeg, SortItem};
#[cfg(test)]
use crate::store::{NodeId, NodeRecord};

mod batch;
mod columnar;
mod entrypoint;
mod expression;
mod mutation;
mod observer;
mod read;
mod scan;
#[cfg(test)]
mod traversal;
mod vector;

use batch::*;
use entrypoint::*;
#[cfg(test)]
use expression::*;
#[cfg(feature = "tokio-runtime")]
pub(crate) use hawdb_executor::binding::map_memory_bytes;
#[cfg(test)]
pub(crate) use hawdb_executor::binding::map_payload_bytes;
use hawdb_executor::binding::Binding;
pub use hawdb_executor::execution_request::ExecutionRequest;
pub use hawdb_executor::external::NoExternalReadOperator;
#[cfg(test)]
use hawdb_executor::memory::enforced_result_memory_budget;
pub(crate) use hawdb_executor::memory::{
    enforced_result_memory_budget_with_option, estimated_execution_memory,
    estimated_mutation_memory_bytes, max_external_read_parallelism,
};
pub(crate) use hawdb_executor::mutation::execute_mutation_with_store_output_limits;
use hawdb_executor::pipeline::{runtime_checkpoint, BatchControl};
use hawdb_executor::QueryMemoryLedger;
#[cfg(test)]
use hawdb_executor::{pipeline::BindingBatch, QueryMemoryClass};
pub use hawdb_executor::{ExecutionMemoryConfig, SpillPoolSnapshot};
pub use hawdb_executor::{
    ExternalReadOperator, ExternalReadResourceContract, ExternalReadResultBudget,
    GroupedEvidenceExecutionReport, OperatorCardinalityProfile, TextSeedExecutionOutput,
    TextSeedExecutionReport, TextSeedExecutionRequest, TextSeedExecutionRow, TextSeedSourceReport,
    VectorCompressionMode, VectorExecutionBackend, VectorExecutionReport, VectorScoreSource,
    VectorSeedExecutionOutput, VectorSeedExecutionRequest, VectorSeedExecutionRow,
};
pub(crate) use mutation::project_staged_mutation_return_rows;
pub use mutation::{
    execute_mutation_with_limits, is_mutation_plan, materialize_unwind_mutations, mutation_command,
};
use observer::*;
use read::*;
#[cfg(test)]
use scan::*;
#[cfg(test)]
use traversal::*;
use vector::*;

pub type Row = hawdb_executor::Row;
pub type RowRef<'a> = hawdb_executor::RowRef<'a>;
pub type ProjectedRowRef<'a> = hawdb_executor::ProjectedRowRef<'a>;
pub type QueryRow = hawdb_executor::QueryRow;
pub type QueryRowRef<'a> = hawdb_executor::QueryRowRef<'a>;
pub type QueryRows = hawdb_executor::QueryRows;
pub type QueryRowsBuilder = hawdb_executor::QueryRowsBuilder;
pub type QueryValueRows<'a> = hawdb_executor::QueryValueRows<'a>;
pub type QuerySchema = hawdb_executor::QuerySchema;
pub type ReadExecutionProfile = hawdb_executor::ReadExecutionProfile<ScanPruningReport>;
pub type ProfiledQueryRows = hawdb_executor::ProfiledQueryRows<ScanPruningReport>;
pub type ProfiledQueryStream = hawdb_executor::ProfiledQueryStream<ScanPruningReport>;
pub(crate) use hawdb_executor::batch::SOURCE_SEGMENT_SCAN_IO_DEPTH;
pub(crate) use hawdb_executor::numeric::MAX_MORSEL_PARALLELISM;
pub(crate) use hawdb_executor::result_delivery::StreamDelivery;

pub use entrypoint::ExecutionResources;

/// Storage side effects are separate from execution/report classification.
/// ProjectGraph is a procedure, but registering its definition appends WAL.
pub(crate) fn requires_write_access(plan: &PhysicalPlan) -> bool {
    let mut writes = false;
    hawdb_plan_cypher::visit_plan(plan, &mut |node| {
        writes |= matches!(node, PhysicalPlan::ProjectGraph { .. })
            || matches!(
                node.class(),
                hawdb_plan_cypher::PhysicalPlanClass::Schema
                    | hawdb_plan_cypher::PhysicalPlanClass::Mutation
            );
    });
    writes
}

/// Executes one request through the public embedded-library execution contract.
///
/// The request owns query-specific inputs while [`ExecutionResources`] makes
/// host-owned mutable state explicit. Output limits are validated before a
/// materialized result is returned.
pub fn execute_with_request<S: ExecutionStore>(
    request: ExecutionRequest<'_>,
    resources: ExecutionResources<'_, S>,
) -> Result<ProfiledQueryRows> {
    execute_profiled_rows(request, resources)
}

/// Executes one request and delivers rows only after result limits validate.
///
/// This entrypoint deliberately retains output until validation completes so a
/// late row or payload limit failure cannot expose a partial consumer result.
pub fn execute_with_request_consumer<S: ExecutionStore>(
    request: ExecutionRequest<'_>,
    resources: ExecutionResources<'_, S>,
    consumer: &mut dyn FnMut(Row) -> Result<()>,
) -> Result<ProfiledQueryStream> {
    execute_profiled_consumer(
        request,
        resources,
        ConsumerMemoryMode::DeferredUntilValidated,
        consumer,
    )
}

pub(crate) enum QueryStreamConsumer<'a> {
    Owned(&'a mut dyn FnMut(Row) -> Result<()>),
    Borrowed(&'a mut hawdb_executor::result_delivery::BorrowedRowConsumer<'a>),
}

pub(crate) fn execute_with_request_stream<S: ExecutionStore>(
    request: ExecutionRequest<'_>,
    resources: ExecutionResources<'_, S>,
    delivery: StreamDelivery,
    consumer: QueryStreamConsumer<'_>,
) -> Result<ProfiledQueryStream> {
    match consumer {
        QueryStreamConsumer::Owned(consumer) => {
            let limits = request.output_limits();
            let bounded = limits.max_rows.is_some() || limits.max_payload_bytes.is_some();
            execute_profiled_consumer(
                request,
                resources,
                delivery.consumer_memory_mode(bounded),
                consumer,
            )
        }
        QueryStreamConsumer::Borrowed(consumer) => {
            execute_profiled_borrowed_consumer(request, resources, delivery, consumer)
        }
    }
}

pub(crate) fn supports_default_morsel_parallelism(plan: &PhysicalPlan, catalog: &Catalog) -> bool {
    columnar::supports_parallel_morsel_execution(plan, catalog)
}

pub(crate) fn default_morsel_parallelism(
    plan: &PhysicalPlan,
    catalog: &Catalog,
    store: &dyn hawdb_executor::store::GraphExecutionRead,
    memory: &ExecutionMemoryConfig,
) -> usize {
    columnar::default_morsel_parallelism(plan, catalog, store, memory)
}

pub fn execute(
    plan: &PhysicalPlan,
    catalog: &mut Catalog,
    store: &mut GraphStore,
) -> Result<Vec<Row>> {
    execute_with_row_limit_internal(plan, catalog, store, None, None)
}

#[deprecated(note = "use execute_with_request")]
pub fn execute_with_row_limit(
    plan: &PhysicalPlan,
    catalog: &mut Catalog,
    store: &mut impl ExecutionStore,
    max_rows: Option<usize>,
) -> Result<Vec<Row>> {
    execute_with_row_limit_internal(plan, catalog, store, max_rows, None)
}

#[deprecated(note = "use execute_with_request")]
pub fn execute_with_row_limit_and_context(
    plan: &PhysicalPlan,
    catalog: &mut Catalog,
    store: &mut impl ExecutionStore,
    max_rows: Option<usize>,
    task_context: &RuntimeTaskContext,
) -> Result<Vec<Row>> {
    execute_with_row_limit_internal(plan, catalog, store, max_rows, Some(task_context))
}

fn execute_with_row_limit_internal(
    plan: &PhysicalPlan,
    catalog: &mut Catalog,
    store: &mut impl ExecutionStore,
    max_rows: Option<usize>,
    task_context: Option<&RuntimeTaskContext>,
) -> Result<Vec<Row>> {
    let parameters = BTreeMap::new();
    let mut external = NoExternalReadOperator;
    let memory = ExecutionMemoryConfig::default();
    let mut rows = Vec::new();
    execute_profiled_consumer(
        ExecutionRequest::new(plan, &parameters, &memory)
            .with_output_limits(max_rows, None)
            .with_optional_task_context(task_context),
        ExecutionResources::new(catalog, store, &mut external),
        ConsumerMemoryMode::Retained,
        &mut |row| {
            rows.push(row);
            Ok(())
        },
    )?;
    Ok(rows)
}

#[deprecated(note = "use execute_with_request")]
pub fn execute_with_row_limit_profile(
    plan: &PhysicalPlan,
    catalog: &mut Catalog,
    store: &mut impl ExecutionStore,
    max_rows: Option<usize>,
) -> Result<ProfiledQueryRows> {
    let mut external = NoExternalReadOperator;
    let parameters = BTreeMap::new();
    let memory = ExecutionMemoryConfig::default();
    execute_profiled_rows(
        ExecutionRequest::new(plan, &parameters, &memory).with_output_limits(max_rows, None),
        ExecutionResources::new(catalog, store, &mut external),
    )
}

#[deprecated(note = "use execute_with_request")]
pub fn execute_with_row_limit_profile_and_external(
    plan: &PhysicalPlan,
    catalog: &mut Catalog,
    store: &mut impl ExecutionStore,
    parameters: &BTreeMap<String, Value>,
    external: &mut dyn ExternalReadOperator,
    max_rows: Option<usize>,
) -> Result<ProfiledQueryRows> {
    let memory = ExecutionMemoryConfig::default();
    execute_profiled_rows(
        ExecutionRequest::new(plan, parameters, &memory).with_output_limits(max_rows, None),
        ExecutionResources::new(catalog, store, external),
    )
}

#[deprecated(note = "use execute_with_request")]
pub fn execute_with_output_limits_profile_and_external(
    plan: &PhysicalPlan,
    catalog: &mut Catalog,
    store: &mut impl ExecutionStore,
    parameters: &BTreeMap<String, Value>,
    external: &mut dyn ExternalReadOperator,
    max_rows: Option<usize>,
    max_payload_bytes: Option<usize>,
) -> Result<ProfiledQueryRows> {
    let memory = ExecutionMemoryConfig::default();
    execute_profiled_rows(
        ExecutionRequest::new(plan, parameters, &memory)
            .with_output_limits(max_rows, max_payload_bytes),
        ExecutionResources::new(catalog, store, external),
    )
}

#[deprecated(note = "use execute_with_request")]
#[allow(clippy::too_many_arguments)]
pub fn execute_with_output_limits_profile_and_external_and_memory(
    plan: &PhysicalPlan,
    catalog: &mut Catalog,
    store: &mut impl ExecutionStore,
    parameters: &BTreeMap<String, Value>,
    external: &mut dyn ExternalReadOperator,
    max_rows: Option<usize>,
    max_payload_bytes: Option<usize>,
    memory: &ExecutionMemoryConfig,
) -> Result<ProfiledQueryRows> {
    execute_with_request(
        ExecutionRequest::new(plan, parameters, memory)
            .with_output_limits(max_rows, max_payload_bytes),
        ExecutionResources::new(catalog, store, external),
    )
}

#[deprecated(note = "use execute_with_request")]
pub fn execute_with_row_limit_profile_and_external_and_memory(
    plan: &PhysicalPlan,
    catalog: &mut Catalog,
    store: &mut impl ExecutionStore,
    parameters: &BTreeMap<String, Value>,
    external: &mut dyn ExternalReadOperator,
    max_rows: Option<usize>,
    memory: &ExecutionMemoryConfig,
) -> Result<ProfiledQueryRows> {
    execute_with_request(
        ExecutionRequest::new(plan, parameters, memory).with_output_limits(max_rows, None),
        ExecutionResources::new(catalog, store, external),
    )
}

#[deprecated(note = "use execute_with_request")]
pub fn execute_with_row_limit_profile_and_external_and_context(
    plan: &PhysicalPlan,
    catalog: &mut Catalog,
    store: &mut impl ExecutionStore,
    parameters: &BTreeMap<String, Value>,
    external: &mut dyn ExternalReadOperator,
    max_rows: Option<usize>,
    task_context: &RuntimeTaskContext,
) -> Result<ProfiledQueryRows> {
    let memory = ExecutionMemoryConfig::default();
    execute_with_request(
        ExecutionRequest::new(plan, parameters, &memory)
            .with_output_limits(max_rows, None)
            .with_task_context(task_context),
        ExecutionResources::new(catalog, store, external),
    )
}

#[deprecated(note = "use execute_with_request")]
#[allow(clippy::too_many_arguments)]
pub fn execute_with_output_limits_profile_and_external_and_context(
    plan: &PhysicalPlan,
    catalog: &mut Catalog,
    store: &mut impl ExecutionStore,
    parameters: &BTreeMap<String, Value>,
    external: &mut dyn ExternalReadOperator,
    max_rows: Option<usize>,
    max_payload_bytes: Option<usize>,
    task_context: &RuntimeTaskContext,
) -> Result<ProfiledQueryRows> {
    let memory = ExecutionMemoryConfig::default();
    execute_with_request(
        ExecutionRequest::new(plan, parameters, &memory)
            .with_output_limits(max_rows, max_payload_bytes)
            .with_task_context(task_context),
        ExecutionResources::new(catalog, store, external),
    )
}

#[deprecated(note = "use execute_with_request")]
#[allow(clippy::too_many_arguments)]
pub fn execute_with_output_limits_profile_and_external_and_context_and_memory(
    plan: &PhysicalPlan,
    catalog: &mut Catalog,
    store: &mut impl ExecutionStore,
    parameters: &BTreeMap<String, Value>,
    external: &mut dyn ExternalReadOperator,
    max_rows: Option<usize>,
    max_payload_bytes: Option<usize>,
    task_context: &RuntimeTaskContext,
    memory: &ExecutionMemoryConfig,
) -> Result<ProfiledQueryRows> {
    execute_with_request(
        ExecutionRequest::new(plan, parameters, memory)
            .with_output_limits(max_rows, max_payload_bytes)
            .with_task_context(task_context),
        ExecutionResources::new(catalog, store, external),
    )
}

/// Executes a read plan and transfers ownership of each output row to a
/// consumer. When either output limit is present, rows remain query-owned
/// until execution validates the complete result against both limits. With
/// both limits disabled, rows are transferred as they are produced.
#[deprecated(note = "use execute_with_request_consumer")]
pub fn execute_with_row_consumer_profile(
    plan: &PhysicalPlan,
    catalog: &mut Catalog,
    store: &mut impl ExecutionStore,
    parameters: &BTreeMap<String, Value>,
    max_rows: Option<usize>,
    max_payload_bytes: Option<usize>,
    consumer: &mut dyn FnMut(Row) -> Result<()>,
) -> Result<ProfiledQueryStream> {
    let mut external = NoExternalReadOperator;
    let memory = ExecutionMemoryConfig::default();
    execute_with_row_consumer_profile_with_delivery(
        plan,
        catalog,
        store,
        parameters,
        &mut external,
        max_rows,
        max_payload_bytes,
        consumer,
        None,
        &memory,
        StreamDelivery::Validated,
    )
}

#[deprecated(note = "use execute_with_request_consumer")]
#[allow(clippy::too_many_arguments)]
pub fn execute_with_row_consumer_profile_and_external(
    plan: &PhysicalPlan,
    catalog: &mut Catalog,
    store: &mut impl ExecutionStore,
    parameters: &BTreeMap<String, Value>,
    external: &mut dyn ExternalReadOperator,
    max_rows: Option<usize>,
    max_payload_bytes: Option<usize>,
    consumer: &mut dyn FnMut(Row) -> Result<()>,
) -> Result<ProfiledQueryStream> {
    let memory = ExecutionMemoryConfig::default();
    execute_with_row_consumer_profile_with_delivery(
        plan,
        catalog,
        store,
        parameters,
        external,
        max_rows,
        max_payload_bytes,
        consumer,
        None,
        &memory,
        StreamDelivery::Validated,
    )
}

#[deprecated(note = "use execute_with_request_consumer")]
#[allow(clippy::too_many_arguments)]
pub fn execute_with_row_consumer_profile_and_external_and_memory(
    plan: &PhysicalPlan,
    catalog: &mut Catalog,
    store: &mut impl ExecutionStore,
    parameters: &BTreeMap<String, Value>,
    external: &mut dyn ExternalReadOperator,
    max_rows: Option<usize>,
    max_payload_bytes: Option<usize>,
    consumer: &mut dyn FnMut(Row) -> Result<()>,
    memory: &ExecutionMemoryConfig,
) -> Result<ProfiledQueryStream> {
    execute_with_row_consumer_profile_with_delivery(
        plan,
        catalog,
        store,
        parameters,
        external,
        max_rows,
        max_payload_bytes,
        consumer,
        None,
        memory,
        StreamDelivery::Validated,
    )
}

#[deprecated(note = "use execute_with_request_consumer")]
#[allow(clippy::too_many_arguments)]
pub fn execute_with_row_consumer_profile_and_external_and_context(
    plan: &PhysicalPlan,
    catalog: &mut Catalog,
    store: &mut impl ExecutionStore,
    parameters: &BTreeMap<String, Value>,
    external: &mut dyn ExternalReadOperator,
    max_rows: Option<usize>,
    max_payload_bytes: Option<usize>,
    consumer: &mut dyn FnMut(Row) -> Result<()>,
    task_context: &RuntimeTaskContext,
) -> Result<ProfiledQueryStream> {
    let memory = ExecutionMemoryConfig::default();
    execute_with_row_consumer_profile_with_delivery(
        plan,
        catalog,
        store,
        parameters,
        external,
        max_rows,
        max_payload_bytes,
        consumer,
        Some(task_context),
        &memory,
        StreamDelivery::Validated,
    )
}

#[deprecated(note = "use execute_with_request_consumer")]
#[allow(clippy::too_many_arguments)]
pub fn execute_with_row_consumer_profile_and_external_and_context_and_memory(
    plan: &PhysicalPlan,
    catalog: &mut Catalog,
    store: &mut impl ExecutionStore,
    parameters: &BTreeMap<String, Value>,
    external: &mut dyn ExternalReadOperator,
    max_rows: Option<usize>,
    max_payload_bytes: Option<usize>,
    consumer: &mut dyn FnMut(Row) -> Result<()>,
    task_context: &RuntimeTaskContext,
    memory: &ExecutionMemoryConfig,
) -> Result<ProfiledQueryStream> {
    execute_with_row_consumer_profile_with_delivery(
        plan,
        catalog,
        store,
        parameters,
        external,
        max_rows,
        max_payload_bytes,
        consumer,
        Some(task_context),
        memory,
        StreamDelivery::Validated,
    )
}

#[allow(clippy::too_many_arguments)]
pub(crate) fn execute_with_row_consumer_profile_with_delivery(
    plan: &PhysicalPlan,
    catalog: &mut Catalog,
    store: &mut impl ExecutionStore,
    parameters: &BTreeMap<String, Value>,
    external: &mut dyn ExternalReadOperator,
    max_rows: Option<usize>,
    max_payload_bytes: Option<usize>,
    consumer: &mut dyn FnMut(Row) -> Result<()>,
    task_context: Option<&RuntimeTaskContext>,
    memory: &ExecutionMemoryConfig,
    delivery: StreamDelivery,
) -> Result<ProfiledQueryStream> {
    let bounded = max_rows.is_some() || max_payload_bytes.is_some();
    execute_profiled_consumer(
        ExecutionRequest::new(plan, parameters, memory)
            .with_output_limits(max_rows, max_payload_bytes)
            .with_optional_task_context(task_context),
        ExecutionResources::new(catalog, store, external),
        delivery.consumer_memory_mode(bounded),
        consumer,
    )
}

pub use hawdb_executor::observer::read_execution_profile;

#[cfg(test)]
#[path = "executor/tests.rs"]
mod tests;