Bug #95348 MySQL Connector/NET using a inefficient way when running procedures.
Submitted: 13 May 2019 9:47 Modified: 14 May 2019 12:34
Reporter: Bill Guo Email Updates:
Status: Verified Impact on me:
None 
Category:Connector / NET Severity:S5 (Performance)
Version:8.0.16 OS:Windows
Assigned to: CPU Architecture:Any

[13 May 2019 9:47] Bill Guo
Description:
Connector/NET goes with a SQL below when running procedure in C# code. 
SELECT * 
FROM mysql.proc 
WHERE 1 = 1 
AND db LIKE 'xxxx' 
AND NAME LIKE 'xxxxx' 

This SQL uses range scanning and most of rows in mysql.proc are scanned. And this caused performance issue in our environment: Above query took 94.01% of total execution time while number of executions were only 2.53% among total.

How to repeat:
Here is C# snippt where calling procedure: 

MySqlConnection conn = new MySqlConnection(); 
conn.ConnectionString = "server=localhost;user=root;database=test;port=3306;password=******"; 
MySqlCommand cmd = new MySqlCommand(); 
conn.Open(); 
cmd.Connection = conn; 
cmd.CommandText = "test_proc"; 
cmd.CommandType = CommandType.StoredProcedure; 
cmd.Parameters.AddWithValue("@param_1", "test"); 
cmd.Parameters["@param_1"].Direction = ParameterDirection.Input; 
cmd.ExecuteNonQuery();

Suggested fix:
Is it possible to use SQL below instead in Connector/NET? 
SELECT * 
FROM mysql.proc 
WHERE 1 = 1 
AND db = 'xxxx' 
AND NAME = 'xxxxx' 

This SQL uses ref scanning and the only matched row is scanned. In my test, it's 10 times faster than using 'Like'.
[14 May 2019 12:34] MySQL Verification Team
Hello Bill Guo,

Thank you for report and feedback.

Thanks,
Umesh