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
When calling Cursor.executemany with an INSERT or REPLACE SQL statement, aiomysql compares the statement against a regular expression RE_INSERT_VALUES and if there is a match, a different, fast-track execution path is taken as opposed to expanding executemany into a series of execute statements.
Unfortunately, the regular expression tests against the older INSERT or REPLACE syntax in MySQL versions prior to 8.0.19 only. For example, the following is a match:
INSERT INTO t1 (a,b,c) VALUES (1,2,3),(4,5,6)
ON DUPLICATE KEY UPDATE c=VALUES(a)+VALUES(b);
This causes a warning message to be emitted with MySQL 8.0.20 and later:
/usr/local/lib/python3.11/site-packages/aiomysql/cursors.py:239: Warning: 'VALUES function' is deprecated and will be removed in a future release. Please use an alias (INSERT INTO ... VALUES (...) AS alias) and replace VALUES(col) in the ON DUPLICATE KEY UPDATE clause with alias.col instead
However, if the new recommended syntax is adopted, the fast-track course is not longer chosen, and execution significantly slows down. This is because the new syntax is no longer a match for RE_INSERT_VALUES:
INSERT INTO t1 (a,b,c) VALUES (1,2,3),(4,5,6) AS new(m,n,p)
ON DUPLICATE KEY UPDATE c = m+n;
On the contrary, execution speed is restored if we slightly modify the regular expression that SQL statements are tested against:
INSERT INTO "DataTable"
("id", "data") VALUES (%s, %s)
ON DUPLICATE KEY UPDATE
"data" = VALUES("data")
A warning message is emitted in MySQL 8.0.20 and later.
Try a bulk INSERT statement with the new syntax (MySQL 8.0.19 and later):
INSERT INTO "DataTable"
("id", "data") VALUES (%s, %s) AS EXCLUDED
ON DUPLICATE KEY UPDATE
"data" = EXCLUDED."data"
Execution significantly slows down.
Expected behavior
Execution speed does not diminish when using the new MySQL 8.0.20 syntax for INSERT.
Logs/tracebacks
n/a
Python Version
Python 3.11.5
aiomysql Version
Name: aiomysqlVersion: 0.2.0Summary: MySQL driver for asyncio.Home-page: https://github.com/aio-libs/aiomysqlAuthor: Nikolay NovikAuthor-email: [email protected]License: MITLocation: /usr/local/lib/python3.11/site-packagesRequires: PyMySQLRequired-by:
PyMySQL Version
Name: PyMySQLVersion: 1.1.0Summary: Pure Python MySQL DriverHome-page: Author: Author-email: Inada Naoki <[email protected]>, Yutaka Matsubara <[email protected]>License: MIT LicenseLocation: /usr/local/lib/python3.11/site-packagesRequires: Required-by: aiomysql
SQLAlchemy Version
No response
OS
macOS 13.5.2
Database type and version
MySQL 8.1.0
Additional context
No response
Code of Conduct
I agree to follow the aio-libs Code of Conduct
The text was updated successfully, but these errors were encountered:
Describe the bug
When calling
Cursor.executemany
with anINSERT
orREPLACE
SQL statement,aiomysql
compares the statement against a regular expressionRE_INSERT_VALUES
and if there is a match, a different, fast-track execution path is taken as opposed to expandingexecutemany
into a series ofexecute
statements.Unfortunately, the regular expression tests against the older
INSERT
orREPLACE
syntax in MySQL versions prior to 8.0.19 only. For example, the following is a match:This causes a warning message to be emitted with MySQL 8.0.20 and later:
However, if the new recommended syntax is adopted, the fast-track course is not longer chosen, and execution significantly slows down. This is because the new syntax is no longer a match for
RE_INSERT_VALUES
:On the contrary, execution speed is restored if we slightly modify the regular expression that SQL statements are tested against:
This will make both old-style and new-style syntax pass.
To Reproduce
Try a bulk INSERT statement with the old syntax:
A warning message is emitted in MySQL 8.0.20 and later.
Try a bulk INSERT statement with the new syntax (MySQL 8.0.19 and later):
Execution significantly slows down.
Expected behavior
Execution speed does not diminish when using the new MySQL 8.0.20 syntax for
INSERT
.Logs/tracebacks
Python Version
Python 3.11.5
aiomysql Version
PyMySQL Version
SQLAlchemy Version
No response
OS
macOS 13.5.2
Database type and version
MySQL 8.1.0
Additional context
No response
Code of Conduct
The text was updated successfully, but these errors were encountered: