Skip to content

enhancement: expose query complexity limits via OpenOptions #76

Closed

Description

@adityamukho

Summary

PR #57 introduced hardcoded query-complexity limits to prevent runaway recursive rules:

// src/query/datalog/evaluator.rs (or similar)
const DEFAULT_MAX_DERIVED_FACTS: usize = 100_000;
const DEFAULT_MAX_RESULTS: usize = 1_000_000;

These constants are not exposed through any public API. Embedders with large graphs or legitimate deep recursive queries have no way to raise (or lower) them without patching the source.

Expected behaviour

OpenOptions (in src/db.rs) gains two optional builder methods:

impl OpenOptions {
    pub fn max_derived_facts(mut self, n: usize) -> Self { ... }
    pub fn max_results(mut self, n: usize) -> Self { ... }
}

When not set, the existing defaults apply unchanged. The configured limits are threaded through to the evaluator at query time.

Files to change

  • src/db.rs — OpenOptions struct + builder methods
  • src/query/datalog/evaluator.rs (or wherever the constants live) — replace compile-time constants with per-query values drawn from OpenOptions
  • Potentially src/query/datalog/executor.rs — if limits are enforced there

Test

Add a test that:

  1. Opens a database with a very low max_derived_facts limit (e.g. 5)
  2. Runs a recursive rule that would produce more than 5 derived facts
  3. Asserts the query returns an error mentioning the limit
  4. Confirms the same query succeeds when the limit is raised to a larger value

Do NOT use {:?} on Result in test assert messages (see CLAUDE.md Testing Conventions).

Philosophy note

This is consistent with Minigraf's zero-configuration philosophy: the defaults work out of the box, but power users can tune them. It does not add external dependencies or server-side configuration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requeststabilityStability/panic issue

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions