Skip to content

feat: Optimize PG source_kind, relation deletion using indices - BED-8832#2942

Open
StephenHinck wants to merge 2 commits into
mainfrom
BED-8832
Open

feat: Optimize PG source_kind, relation deletion using indices - BED-8832#2942
StephenHinck wants to merge 2 commits into
mainfrom
BED-8832

Conversation

@StephenHinck

@StephenHinck StephenHinck commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Description

Implements the new DeleteNodesByKinds/DeleteRelationshipsByKinds functions supported optionally on DAWGS drivers to execute rapid deletion of objects by kind. Initially, this is supported on PostgreSQL drivers.

Requires SpecterOps/DAWGS#101

Note: this was run with the expectation that SpecterOps/DAWGS#100 has already merged. The timings for source_kind deletion include this change.

Motivation and Context

Resolves BED-8832

Why is this change required? What problem does it solve?

How Has This Been Tested?

Validated locally and confirmed existing tests continue to pass.

Screenshots (optional):

Tested using large OGGen payloads for validation:

Delete by source_kind:
Before:

time=2026-06-30T16:15:45.448Z level=INFO message=DeleteCollectedGraphData delete_all_data=false delete_sourceless_data=false delete_source_kinds=OggenBase delete_relationships="" measurement_id=129 elapsed=1m21.810004664s

After:

time=2026-06-30T16:21:37.337Z level=INFO message=DeleteCollectedGraphData delete_all_data=false delete_sourceless_data=false delete_source_kinds=OggenBase delete_relationships="" measurement_id=129 elapsed=1m14.96949745s

Delete by relationship:
Before:

time=2026-06-30T17:17:54.052Z level=INFO message=DeleteCollectedGraphData delete_all_data=false delete_sourceless_data=false delete_source_kinds="" delete_relationships=HasSession measurement_id=129 elapsed=10.140349088s

After:

time=2026-06-30T17:07:53.310Z level=INFO message=DeleteCollectedGraphData delete_all_data=false delete_sourceless_data=false delete_source_kinds="" delete_relationships=HasSession measurement_id=129 elapsed=453.611584ms

Types of changes

  • New feature (non-breaking change which adds functionality)

Checklist:

Summary by CodeRabbit

  • Performance
    • Graph data deletion now uses faster bulk operations when supported, which can significantly speed up large deletions.
  • Bug Fixes
    • Improved deletion handling for different graph data types, making cleanup more reliable across backends.
    • Preserved existing deletion behavior as a fallback when bulk deletion is not available.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

DeleteCollectedGraphData is refactored to wrap execution in measure.ContextLogAndMeasure and branch between two deletion strategies: set-based deletes via new nodesByKindDeleter/relationshipsByKindDeleter capability interfaces when the driver supports them, or streaming row-by-row fallback helpers extracted from the prior inline logic.

Graph Data Deletion Refactor

Layer / File(s) Summary
Orchestration and logging
cmd/api/src/daemons/datapipe/delete.go
DeleteCollectedGraphData replaces slog.InfoContext with a deferred measure.ContextLogAndMeasure wrapper and conditionally dispatches to set-based or streaming helpers for both nodes and relationships.
Set-based capability interfaces
cmd/api/src/daemons/datapipe/delete.go
Defines nodesByKindDeleter and relationshipsByKindDeleter interfaces; deleteNodesByKindsSetBased maps DeleteAllGraph/DeleteSourcelessGraph/DeleteSourceKinds flags to DeleteNodesByKinds calls while preserving common.MigrationData.
Streaming fallback helpers
cmd/api/src/daemons/datapipe/delete.go
deleteNodesByOperation and deleteRelationshipsByOperation encapsulate the prior inline streaming logic: building an operation, reading filtered IDs, and deleting row-by-row via the writer.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 75.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly matches the PR's main change: optimizing PostgreSQL kind-based graph deletion.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description check ✅ Passed The PR description follows the template and includes the required sections, issue reference, testing notes, screenshots, type, and checklist.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch BED-8832

Comment @coderabbitai help to get the list of available commands.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant