Repository navigation
Conversation
|
Hi @roji There might be a resource leak at the PR. PersistentPreparedStatements dictionary at NpgsqlConnector does not seem to be cleaned properly. I think the PreparedStatementInfo should be removed from the dictionary when Unpersist()/ClosePreparedStatements() is used. |
|
@MarkusSintonen thanks for your useful review notes, have fixed. Like I said there's still a few things left I'd like to do, let me know if you run into any other problems. |
|
And yes, there's now a test which catches the leak you found. |
|
Good to hear that the comments were helpful. What you think what is the intended behaviour when user first calls Prepare(true) and after that Prepare(false) for the same command object. Should the already persisted command be freed? How about if user first calls Prepare(true) but afterwards for different command instance (with same SQL) Prepare(false), what is the intended behaviour here? Should behaviour for these cases also be covered by the unit tests? Furthermore could it be allowed to unpersist commands without first Preparing them? For example user could free persisted command statements without first callind Prepare: using (var cmd = new NpgsqlCommand("INSERT INTO data (first_name, last_name) VALUES ($1, $2)", conn))
{
cmd.Prepare(true);
// execute cmd etc.
}
// And somewhere else free the persistent command, without first calling Prepare
using (var cmd = new NpgsqlCommand("INSERT INTO data (first_name, last_name) VALUES ($1, $2)", conn))
{
cmd.Unpersist();
}These were the last few thoughts about the new API. |
Prepared statements can now be made to persist across pooled connection Close/Open. This can provide a significant performance boost in applications with short-lived connections and complex queries that take long to plan. Based on significant work by @MarkusSintonen in npgsql#1084 (thanks!) Fixes npgsql#483
|
@MarkusSintonen, those are very good questions.
I wondered about that for a bit. I ended up deciding that persistent statements should only be explicitly unpersisted by calling It is possible for the
I've modified the code to allow this. Internally Thanks again for all the comments! I'll wait a bit more before merging in case you think of something else. |
| /// </summary> | ||
| public void Unpersist() | ||
| { | ||
| // We want to allow users to unpersist without having to persist first |
There was a problem hiding this comment.
This will cause unnecessary command preparing and immediate deallocation on PostgreSQL in a case where user calls Unpersist on a command SQL that has not yet been prepared and persisted. Probably in this case the Unpersist should not do anything. Of course fixing this would require some logic changes with Prepare and Unpersist. Easiest would be to document the intended behaviour but I could also suggest a fix.
There was a problem hiding this comment.
Yes, that's true, but it doesn't seem very important. Remember this is just Unpersist, which is supposed to be called once in the application lifecycle mostly. Also, it's within the programmer's ability (and responsibility) to avoid this scenario by making sure they call Unpersist() only for SQL that has been persisted before. Even if they don't, the consequences are minimal (prepare/unprepare)...
|
Looks good to me |
|
Merged via adf1c0b |
Implements #483