You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Do PREPARED-Statements make any sense with the current implementation of NpgsqlConnection? #434
PREPARED statements are lost after executing DEALLOCATE. If I understand correctly, DEALLOCATE is executed when connection is closed/disposed or moved to the Npgsql connection pool.
However, in the most cases Npgsql is used for websites and connections are very short-living (1-3 commands).
So I suggest that supporting PREPARED statements does not provide any benefits and just makes the Npgsql-code more complicated.
Well, that might be true. But it is the same for all ADO.NET providers. We can't "leak" state between connections.
I think the PostgreSQL backend itself should have a better system for reusing queries between connections. All other PostgreSQL providers for different languages probably have the same problem.
The thing you can do is have connections that are not created and destroyed for every web request, if the performance is very important.
MS SQL "solves" this by having a better query plan cache that lasts between connections.
Note that there are still non-websites that uses long-lasting connections that benefit from prepared statements.
I agree with @Emill - and at the end of the day not everyone is a website with very short connection times - in many cases connections are long-lived and prepared statements there are crucial.
We could in theory think about a special mechanism for not deallocating prepared statements when they are returned to the pool. One way to do this, is to track which prepared statements are open on which connection, and if a user tries to prepare query text which has already been prepared - reuse that. It doesn't seem very hard to implement, what do you think @Emill?
It seems people from php would like to have something like that with support from the server itself. But from the discussion this feature wasn't implemented :(
One of the server side implementation ideas is exactly what @roji said: hash the query (without the parameters) and check if it is already prepared.
Activity
Emill commentedon Dec 19, 2014
Well, that might be true. But it is the same for all ADO.NET providers. We can't "leak" state between connections.
I think the PostgreSQL backend itself should have a better system for reusing queries between connections. All other PostgreSQL providers for different languages probably have the same problem.
The thing you can do is have connections that are not created and destroyed for every web request, if the performance is very important.
MS SQL "solves" this by having a better query plan cache that lasts between connections.
Note that there are still non-websites that uses long-lasting connections that benefit from prepared statements.
roji commentedon Dec 20, 2014
I agree with @Emill - and at the end of the day not everyone is a website with very short connection times - in many cases connections are long-lived and prepared statements there are crucial.
We could in theory think about a special mechanism for not deallocating prepared statements when they are returned to the pool. One way to do this, is to track which prepared statements are open on which connection, and if a user tries to prepare query text which has already been prepared - reuse that. It doesn't seem very hard to implement, what do you think @Emill?
franciscojunior commentedon Dec 24, 2014
I looked for that in postgresql and found this thread from 2008:
http://postgresql.nabble.com/Cached-Query-Plans-was-global-prepared-statements-td1981260.html
It seems people from php would like to have something like that with support from the server itself. But from the discussion this feature wasn't implemented :(
One of the server side implementation ideas is exactly what @roji said: hash the query (without the parameters) and check if it is already prepared.
roji commentedon Feb 12, 2015
Opened #483 for keeping prepared statements across connections.