[issue44041] [sqlite3] optimisation: only call sqlite3_column_count when needed

Erlend Egeberg Aasland report at bugs.python.org
Tue May 4 18:33:34 EDT 2021


New submission from Erlend Egeberg Aasland <erlend.aasland at innova.no>:

Pr. now, we call sqlite3_column_count() for every iteration in the _pysqlite_query_execute() loop. If detect_types is set, we call it twice for every loop.

Suggesting to move it out of the loop and into the pysqlite_Statement object. In pysqlite_statement_create(), after sqlite3_prepare_v2(), if self->is_dml == 0 we fetch the column count: self->column_count = sqlite3_column_count(). Else, it's 0.


# SQLite API interaction examples (pseudo-code), as diffs
--- now
+++ patched

## Create table
 sqlite3_prepare_v2
+sqlite3_column_count
 sqlite3_bind_blob_parameter_count
 sqlite3_step
-sqlite3_column_count
 sqlite3_last_insert_rowid
 sqlite3_reset

## Triple insert (executemany)
 sqlite3_prepare_v2
 sqlite3_get_autocommit
 sqlite3_bind_blob_parameter_count
 sqlite3_bind_int64
 sqlite3_step
-sqlite3_column_count
 sqlite3_changes
 sqlite3_reset
 sqlite3_bind_blob_parameter_count
 sqlite3_bind_int64
 sqlite3_step
-sqlite3_column_count
 sqlite3_changes
 sqlite3_reset
 sqlite3_bind_blob_parameter_count
 sqlite3_bind_int64
 sqlite3_step
-sqlite3_column_count
 sqlite3_changes
 sqlite3_reset

----------
components: Extension Modules
messages: 392964
nosy: berker.peksag, erlendaasland, serhiy.storchaka
priority: normal
severity: normal
status: open
type: enhancement
versions: Python 3.11

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue44041>
_______________________________________


More information about the Python-bugs-list mailing list