Skip to content
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

Automatically prepare statements based on use #1237

Closed
roji opened this issue Aug 9, 2016 · 2 comments
Closed

Automatically prepare statements based on use #1237

roji opened this issue Aug 9, 2016 · 2 comments
Assignees
Milestone

Comments

@roji
Copy link
Member

roji commented Aug 9, 2016

Triggered by @vlsi's comment: #1227 (comment)

Basically, keep track of often-executed queries and implicitly prepare them once an execution threshold is reached. Manage these implicitly-prepared statements with an LRU cache to prevent explosion.

Think more about what exactly this means.

@roji
Copy link
Member Author

roji commented Aug 9, 2016

FYI (unrelated) the idea of persisting prepared connections across close/open in pooled connections has been implemented in #483. It's a huge performance optimization and our conversation on the pgsql-hackers list is making me think that it should be on by default (it's currently opt-in).

However, Npgsql doesn't have any sort of mechanism for automatically preparing statements, similar to what you do in pgjdbc. The approach up to now has been to leave this up to the user - if the user chooses to, they can definitely prepare, but Npgsql won't do it implicitly for them. I can definitely see the merit of automatic preparation, the only objection I have right now is a general aversion of implicit/magical mechanisms like this - in general I prefer APIs to be very simple and do exactly what they mean, with a minimum of under-the-hood logic. But I'll definitely think about this.

@vlsi
Copy link

vlsi commented Aug 9, 2016

our conversation on the pgsql-hackers list is making me think that it should be on by default (it's currently opt-in)

good

But I'll definitely think about this.

Just in case, there are caveats:

  1. If application is doing "alter table ... add column", a server-prepared statement that does "select * from ..." would fail with "not implemented" / "cached plan must not change result type"

  2. If application does "deallocate all" (why?), all server-prepared statements will require re-preparation. Unfortunately, there are applications that do "deallocate all" for some unknown reason.

Here's relevant pgjdbc fix: https://github.com/pgjdbc/pgjdbc/pull/451/files

@roji roji closed this as completed in 7be0ec3 Jan 4, 2017
NateBrady23 pushed a commit to TechEmpower/FrameworkBenchmarks that referenced this issue Jan 10, 2017
* aspnetcore: Remove dependency on net451 and mono

* aspnetcore: Update PostgreSQL connection string for latest npgsql
- Prepared statements are now persisted by default, so the PersistPrepared option has been removed.
- npgsql/npgsql#1237

* aspnetcore: Make shell scripts executable

* aspnetcore: Change scripts to use `dotnet Benchmarks.dll`
- Scripts currently use `dotnet run` which is intended for iterative development rather than production.
- Should not cause a measurable change in performance.

* aspnetcore: Add DB scenarios to README.md

* aspnetcore: Update framework and packages to 1.1

* aspnetcore: Remove unnecessary import from project.json

* aspnetcore: Make dotnetcore.sh executable

* aspnetcore: Update dotnetcore.sh to 1.1
NateBrady23 pushed a commit to NateBrady23/FrameworkBenchmarks that referenced this issue Jan 13, 2017
* aspnetcore: Remove dependency on net451 and mono

* aspnetcore: Update PostgreSQL connection string for latest npgsql
- Prepared statements are now persisted by default, so the PersistPrepared option has been removed.
- npgsql/npgsql#1237

* aspnetcore: Make shell scripts executable

* aspnetcore: Change scripts to use `dotnet Benchmarks.dll`
- Scripts currently use `dotnet run` which is intended for iterative development rather than production.
- Should not cause a measurable change in performance.

* aspnetcore: Add DB scenarios to README.md

* aspnetcore: Update framework and packages to 1.1

* aspnetcore: Remove unnecessary import from project.json

* aspnetcore: Make dotnetcore.sh executable

* aspnetcore: Update dotnetcore.sh to 1.1
zloster pushed a commit to zloster/FrameworkBenchmarks that referenced this issue Mar 21, 2017
* aspnetcore: Remove dependency on net451 and mono

* aspnetcore: Update PostgreSQL connection string for latest npgsql
- Prepared statements are now persisted by default, so the PersistPrepared option has been removed.
- npgsql/npgsql#1237

* aspnetcore: Make shell scripts executable

* aspnetcore: Change scripts to use `dotnet Benchmarks.dll`
- Scripts currently use `dotnet run` which is intended for iterative development rather than production.
- Should not cause a measurable change in performance.

* aspnetcore: Add DB scenarios to README.md

* aspnetcore: Update framework and packages to 1.1

* aspnetcore: Remove unnecessary import from project.json

* aspnetcore: Make dotnetcore.sh executable

* aspnetcore: Update dotnetcore.sh to 1.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants