-
Notifications
You must be signed in to change notification settings - Fork 242
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
db.insert is significantly slower than simple enity creation #84
Comments
Fixed, now db.insert() works about 2.5 times faster then entity creation |
Whta was the cause of that? did not understand by your commit...As I understand, each insert was done in separate transaction... |
A database connection can be opened in transactional mode or in autocommit mode. When the connection is in transactional mode, then the first SQL command starts a new transaction, and the subsequent SQL commands belongs to the same transaction, until Some ORMs (such as Django) use autocommit mode by default. But in autocommit mode each UPDATE performs in a separate transaction, and with Pony we want that all UPDATEs which are executed within the same But if the For PostgreSQL this is beneficial because this way we can save round-trips to the database on For SQLite the Pony behavior is beneficial because it allows other processes read from the database concurrently. If the Pony would use transactional mode from the very beginning of the In order to maintain this logic, Pony database session internally have The transactional logic in Pony is pretty complex, but this is just because the topic is hard. For example. when connection to the database is lost, Pony analyzes the current state of the transaction. If only SELECTs were performed earlier in this transaction, and the connection uses the default database isolation level, then Pony silently open new connection and continues its operation. But if some UPDATEs were already sent through old connection, then Pony understands that it does not make sense to continue operations on new connection, because the content of previous UPDATEs was lost. In this case, Pony trows appropriate exception. The end result is that Pony tries to work with the database in the most intelligent and efficient way possible. |
You definitely should write this (and other "internal" things) to documentation. Text you are writing is clear and simple for understanding. Very good! |
Example code:
Documentation say that this should be faster. http://doc.ponyorm.com/database.html?highlight=insert
The text was updated successfully, but these errors were encountered: