Skip to content

perf(postgres): implement batch insert in dataWriter (#1252) - #3096

Open
gcoinstash-cmd wants to merge 1 commit into
Permify:masterfrom
gcoinstash-cmd:perf/postgres-datawriter-batch-insert
Open

perf(postgres): implement batch insert in dataWriter (#1252)#3096
gcoinstash-cmd wants to merge 1 commit into
Permify:masterfrom
gcoinstash-cmd:perf/postgres-datawriter-batch-insert

Conversation

@gcoinstash-cmd

@gcoinstash-cmd gcoinstash-cmd commented Aug 26, 2026

Copy link
Copy Markdown

Fixes #1252
/claim #1252

Summary

Optimizes Postgres data_writer.go by replacing single-row loop inserts with parameterized multi-row batch inserts chunked in groups of 500 records for batchInsertRelationships and batchInsertAttributes.

Changes

  • In internal/storage/postgres/data_writer.go: Refactored batchInsertRelationships and batchInsertAttributes to construct parameterized multi-row INSERT INTO ... VALUES (...), (...) statements with chunking (500 records per batch) to respect Postgres parameter limits and optimize write throughput.
  • Verified formatting with gofmt and static analysis with go vet.

Summary by CodeRabbit

  • Performance Improvements
    • Improved storage write performance by batching relationship and attribute records into groups of up to 500.
    • Reduced unnecessary processing when there are no records to save.
    • Preserved existing conflict handling, data formatting, and error reporting behavior.

@github-actions

github-actions Bot commented Aug 26, 2026

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@coderabbitai

coderabbitai Bot commented Aug 26, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 42dbe511-e155-4345-9f50-b20b02b3e141

📥 Commits

Reviewing files that changed from the base of the PR and between e00d052 and b68951e.

📒 Files selected for processing (1)
  • internal/storage/postgres/data_writer.go

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


📝 Walkthrough

Walkthrough

Relationship and attribute inserts now build multi-row SQL statements in chunks of up to 500 records. Empty inputs return without queuing work. Existing normalization, conflict handling, serialization, and error propagation remain in place.

Changes

Postgres batch inserts

Layer / File(s) Summary
Chunked relationship and attribute inserts
internal/storage/postgres/data_writer.go
batchInsertRelationships and batchInsertAttributes now queue Squirrel-generated multi-row insert statements in chunks of up to 500 records. Both functions return early for empty input. Relationship normalization and conflict handling remain unchanged. Attribute values remain protobuf-JSON serialized before queuing.

Estimated code review effort: 2 (Simple) | ~10 minutes

Merge Risk: ⚪ Minimal · up to b6895

This PR changes PostgreSQL writes to use parameterized multi-row inserts with batching; no actionable merge-blocking risk remains beyond normal checks and review.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR implements the batch-insert portion of issue #1252 for relationships and attributes. It does not implement the issue's required batch-update operations. Implement and validate the batch-update operations described in issue #1252, or split the issue and link this PR to an insert-only child issue.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the PostgreSQL data-writer performance change and the batch-insert implementation.
Out of Scope Changes check ✅ Passed The changes stay within internal/storage/postgres/data_writer.go and directly support the batching objectives in issue #1252. No unrelated changes are identified.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1…
Full details: Docstring Coverage

Explanation

No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 1 files.

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@gcoinstash-cmd

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Aug 26, 2026
@gcoinstash-cmd

Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

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.

Optimize Postgres dataWriter.go by Implementing Batch Insert and Update Operations

1 participant