-
-
Notifications
You must be signed in to change notification settings - Fork 30.6k
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
Migrate sqlite3 module to _v2 API to enhance performance #53549
Comments
The Python sqlite module currently uses some deprecated API 0 of SQLite. These are functions that have a counterpart with _v2 appended to their name. The SQLite query planner will not use certain optimizations when using the old API. For example, as documented in 1, using a statement with a GLOB or LIKE operator where the pattern is parametrized will only use an appropriate index if sqlite3_prepare_v2() is used instead of sqlite3_prepare(). Following is an example of such a query. When executed, table 'test' is scanned row by row, which requires all data in the table to be loaded from disk. cursor.execute('create table test(a text)') When the same query is executed in the sqlite3 command line utility, the index 'test_index' is used instead. sqlite> create table test(a text); The query in this example is not parametrized as parameters can't be filled in when using the sqlite3 command line utility. This is just to show that the schema and the query allow the index to be used with certain pattern strings. Michael |
Yes, the sqlite module uses the old API, and is written to work with older SQLite releases and their respective bugs as well. Using the new API will mean requiring newer SQLite releases. If we do this, then this is the chance to remove all the obscure backwards compatibility code with older SQLite releases. |
Apparently this issue has not been dealt with for quite some time now. As a prospective GSoC student, I still need to submit a patch to pass final screening and I thought, that the needed patch here would be quite suitable for a beginner. I plan to submit a patch, which simply replaces the deprecated method calls with the new ones. |
I can't speak for GSoC or Gerhard, but it strikes me as a reasonable first step. An alternatives woube be writing it with fallbacks (so older sqlite can still be used, though less efficiently). It would also be nice to clean up at least one call with compatibility cruft. That said, don't hesitate to submit a patch that does *something*, and then replace it with more comprehensive patches later. |
I have now submitted a patch, which swapped out all the necessary calls. Tests are all running as expected. I will now try to remove some backwards compatibility code. |
What Sqlite version are you targeting? Some systems use quite old Sqlite versions, see bpo-14572 for example. |
This would be nice to have in 3.4. When were the _v2 APIs introduced? See also bpo-13773 which uses sqlite3_open_v2() to pass some flags. |
Is there any hope? |
ok, i will have to look into this |
The externally maintained version of the sqlite3 module has now been switched to the v2 statement API. pysqlite is for Python 2.7 only. I'd suggest to revisit this for Python 3.6 and then try to port most fixes from pysqlite to the sqlite3 module. |
I made a new patch to fix this issue. I left a fallback to the old API as Jim suggested. In addition to the changes in Robin`s patch I changed sqlite3_close to sqlite3_close_v2 if available. This solves bpo-26187 as well. |
Can someone review Aviv's patch? |
I opened a PR. This actually is a bugfix in addition to an enhancement as it solves bpo-26187 as well. |
Is detection in the configure script needed? What are SQLite versions in which _v2 APIs were added? What is minimal supported SQLite version? Don't forget about Windows where autotools are not used. |
from https://www.sqlite.org/changes.html: In bpo-29355 Ma Lin says that RHEL6 comes with SQLite 3.6.x. I think that removing that removing the check for sqlite3_prepare_v2 and sqlite3_open_v2 is fine but sqlite3_close_v2 need to stay.
What should I do for this to work on windows? |
There are compile-time checks for supporting SQLite older than 3.2.2. I think it is better to use the preprocessor rather of autotools for
On Windows manually written PC/pyconfig.h is used rather of generated by |
I changed the patch to use SQLITE_VERSION_NUMBER and it looks way better. Thanks Serhiy |
I will add commit information manually: 86a6705 Thanks! |
Misc/NEWS
so that it is managed by towncrier #552Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: