Skip to content

Cache prepared statements #258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from
Open

Cache prepared statements #258

wants to merge 8 commits into from

Conversation

unageek
Copy link

@unageek unageek commented Apr 20, 2025

This PR resolves #257.

@unageek
Copy link
Author

unageek commented Apr 20, 2025

Ready for review. 🙏

@coveralls
Copy link

coveralls commented Apr 20, 2025

Pull Request Test Coverage Report for Build 14602424605

Details

  • 91 of 95 (95.79%) changed or added relevant lines in 3 files are covered.
  • 1 unchanged line in 1 file lost coverage.
  • Overall coverage increased (+0.02%) to 89.849%

Changes Missing Coverage Covered Lines Changed/Added Lines %
DuckDB.NET.Data/DuckDBDataReader.cs 33 34 97.06%
DuckDB.NET.Data/PreparedStatement/PreparedStatement.cs 10 11 90.91%
DuckDB.NET.Data/DuckDBCommand.cs 48 50 96.0%
Files with Coverage Reduction New Missed Lines %
DuckDB.NET.Data/DuckDBDataReader.cs 1 96.45%
Totals Coverage Status
Change from base Build 14595775821: 0.02%
Covered Lines: 2152
Relevant Lines: 2358

💛 - Coveralls

Copy link

@unageek unageek deployed to external April 22, 2025 18:53 — with GitHub Actions Active
@Giorgi Giorgi requested a review from Copilot April 23, 2025 07:26
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR addresses issue #257 by caching prepared statements and updating resource management across the codebase. Key updates include:

  • Refactoring tests to consistently use using‑blocks when handling DbDataReader instances.
  • Enhancing the prepared statement caching logic and its disposal in command execution.
  • Modifying internal resource disposal patterns in both the data reader and command classes.

Reviewed Changes

Copilot reviewed 20 out of 20 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
README.md Updated usage of ExecuteReader with using‑block for proper disposal.
DuckDB.NET.Test/Parameters/*.cs Wrapped ExecuteReader calls in using‑blocks or ensured explicit disposal in test cases.
DuckDB.NET.Data/PreparedStatement/PreparedStatement.cs Refactored prepared statement creation and parameter binding to support caching.
DuckDB.NET.Data/DuckDBDataReader.cs Updated disposal logic and managed switching from legacy enumerator to cached statement enumerator.
DuckDB.NET.Data/DuckDBCommand.cs Introduced caching of prepared statements and improved disposal of cached statements to manage resources.
Comments suppressed due to low confidence (1)

DuckDB.NET.Data/DuckDBCommand.cs:51

  • [nitpick] The error message 'no open reader must exist' may be unclear; consider rewording it to 'Cannot change CommandText while a reader is open.' for improved clarity.
if (DataReader != null) throw new InvalidOperationException("no open reader must exist");

@unageek
Copy link
Author

unageek commented Apr 23, 2025

I've completed addressing the detected issues. 🙏

@Giorgi
Copy link
Owner

Giorgi commented Apr 23, 2025

Out of curiosity, did you see any performance improvements from caching?

@unageek
Copy link
Author

unageek commented Apr 23, 2025

No. In practice, I only use Appender + CTAS, and do not reuse commands, so there is no performance gain.

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.

Cache PreparedStatements in DuckDBCommand
3 participants