-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
bpo-9303: Migrate sqlite3 module to _v2 API to enhance performance #359
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can also avoid calling sqlite3_reset
in _pysqlite_seterror
if the v2 API is available.
I haven't checked yet, but I also think that the check for cpython/Modules/_sqlite/cursor.c Line 553 in c92e604
|
Modules/_sqlite/connection.c
Outdated
@@ -118,8 +118,13 @@ int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject | |||
return -1; | |||
} | |||
Py_BEGIN_ALLOW_THREADS | |||
#ifdef HAVE_SQLITE3_OPEN_V2 | |||
rc = sqlite3_open_v2(database, &self->db, | |||
SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Style nitpick: FOO|BAR
is more common than FOO | BAR
in sqlite3 code base.
Modules/_sqlite/connection.c
Outdated
@@ -118,8 +118,13 @@ int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject | |||
return -1; | |||
} | |||
Py_BEGIN_ALLOW_THREADS | |||
#ifdef HAVE_SQLITE3_OPEN_V2 | |||
rc = sqlite3_open_v2(database, &self->db, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that there is an opportunity to simplify this whole SQLITE_OPEN_URI
and HAVE_SQLITE3_OPEN_V2
dance.
(The use of Py_BEGIN_ALLOW_THREADS
is a bit weird in line 111 and line 120.)
done
I don't think we should do this because we can get |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks pretty good to me. We just need an entry in Misc/NEWS
(please add "Patch by Aviv Palivoda." too)
Modules/_sqlite/util.c
Outdated
if (st != NULL) { | ||
(void)sqlite3_reset(st); | ||
} | ||
#endif | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: Please remove extra empty line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Modules/_sqlite/connection.c
Outdated
@@ -118,6 +118,8 @@ int pysqlite_connection_init(pysqlite_Connection* self, PyObject* args, PyObject | |||
return -1; | |||
} | |||
Py_BEGIN_ALLOW_THREADS | |||
/* No need to use sqlite3_open_v2 as sqlite3_open(filename, db) is the | |||
same as sqlite3_open_v2(filename, db, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL)*/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpick: FOO|BAR
syntax instead of FOO | BAR
.
Also, finish the line with a full stop and space:
/* [...] NULL). */
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Right, we can still get |
I have removed the reset but I left the recompile because we should recompile before calling sqlite3_step again. |
Modules/_sqlite/util.c
Outdated
@@ -49,10 +49,13 @@ int _pysqlite_seterror(sqlite3* db, sqlite3_stmt* st) | |||
{ | |||
int errorcode; | |||
|
|||
/* SQLite often doesn't report anything useful, unless you reset the statement first */ | |||
#if SQLITE_VERSION_NUMBER >= 3003009 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't >=
be <
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix an error found by @berkerpeksag.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, Aviv! I will wait for Serhiy's approval and merge this.
Use the _v2 API when possible.