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
As you can see MySqlConnection is creating in every request to DB. That leads to recreate Dictionary m_cachedProcedures with cached stored procedures every time. As a result: every query MySqlConnector does query to information_schema.parameters table.
If there are thousands or even hundred stored procederes into database and many parallel connection it works not so pretty well.
Oracle's connector solve this problem through quering of mysql.proc table. mysql.proc unlike of information_schema.parameters has indexes
This is show create table mysql.proc.
CREATETABLE `proc` (
`db`char(64) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL DEFAULT '',
`name`char(64) NOT NULL DEFAULT '',
`type` enum('FUNCTION','PROCEDURE') NOT NULL,
...
`db_collation`char(32) CHARACTER SET utf8 COLLATE utf8_bin DEFAULT NULL,
`body_utf8` longblob,
PRIMARY KEY (`db`,`name`,`type`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Stored Procedures'Primary key exists here.
But it's not a good way to use this table because:
This table use MyISAM engine (no locks, obsolete etc),
With a local MySQL server, I'm seeing about 3ms to get the procedure schema and 0.2ms to execute the stored procedure itself. Increasing the lifetime of that cache will have obvious performance benefits.
As per my comments on #416, I'm considering implementing this as a cache in the ConnectionPool class. (Thus, non-cached connections will not benefit, but there's already a huge performance overhead for not pooling connections that I'm not overly concerned about that use case.)
Regarding cache eviction, I plan to make that manual, and a side-effect of ClearPoolAsync; that is, if you are using connection pooling and change the definition of a stored procedure after executing it at least once, you must call MySqlConnection.ClearPoolAsync(connection) to manually clear the procedure cache.
If we have a lot of stored procedures in MySql database, it's will be a performance problems.
Typicaly using stored in our code:
As you can see MySqlConnection is creating in every request to DB. That leads to recreate Dictionary
m_cachedProcedures
with cached stored procedures every time. As a result: every query MySqlConnector does query toinformation_schema.parameters
table.If there are thousands or even hundred stored procederes into database and many parallel connection it works not so pretty well.
Oracle's connector solve this problem through quering of mysql.proc table. mysql.proc unlike of
information_schema.parameters
has indexesThis is
show create table mysql.proc
.But it's not a good way to use this table because:
https://ocelot.ca/blog/blog/2017/08/22/no-more-mysql-proc-in-mysql-8-0/
and
https://www.percona.com/live/plam16/sites/default/files/slides/PLAM16-NewDD-final.pdf
So, we should not use
mysql.proc
.I suggest move
m_cachedProcedures
(https://github.com/mysql-net/MySqlConnector/blob/master/src/MySqlConnector/MySql.Data.MySqlClient/MySqlConnection.cs#L449) to static variable into classMySqlConnection
and do nothing withinformation_schema.parameters
ormysql.proc
.I dont have good performance test for this solution, but this should be more efficiently.
#416
The text was updated successfully, but these errors were encountered: