Skip to content

Commit d3af31e

Browse files
Add UseProcedureCache option and documentation. Fixes mysql-net#1175
Signed-off-by: tarasevichvlad <[email protected]>
1 parent ce10e20 commit d3af31e

File tree

5 files changed

+31
-0
lines changed

5 files changed

+31
-0
lines changed

docs/content/connection-options.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,11 @@ These are the other options that MySqlConnector supports. They are set to sensib
451451
distributed transactions, but may not be compatible with server replication; there are <a href="https://dev.mysql.com/doc/refman/8.0/en/xa-restrictions.html">other limitations</a>.
452452
When set to <code>false</code>, regular MySQL transactions are used, just like Connector/NET.</td>
453453
</tr>
454+
<tr id="UseProcedureCache">
455+
<td>Use Procedure Cache, UseProcedureCache</td>
456+
<td>true</td>
457+
<td>When <code>false</code> disables the procedure cache</td>
458+
</tr>
454459
</table>
455460

456461
## Unsupported Options

src/MySqlConnector/Core/CachedProcedure.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ internal sealed class CachedProcedure
1212
{
1313
public static async Task<CachedProcedure?> FillAsync(IOBehavior ioBehavior, MySqlConnection connection, string schema, string component, ILogger logger, CancellationToken cancellationToken)
1414
{
15+
if (!connection.Session.UseProcedureCache)
16+
return null;
17+
1518
// try to use mysql.proc first, as it is much faster
1619
if (!connection.Session.ServerVersion.IsMariaDb &&
1720
connection.Session.ServerVersion.Version < ServerVersions.RemovesMySqlProcTable &&

src/MySqlConnector/Core/ConnectionSettings.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ public ConnectionSettings(MySqlConnectionStringBuilder csb)
147147
UseAffectedRows = csb.UseAffectedRows;
148148
UseCompression = csb.UseCompression;
149149
UseXaTransactions = csb.UseXaTransactions;
150+
UseProcedureCache = csb.UseProcedureCache;
150151

151152
static int ToSigned(uint value) => value >= int.MaxValue ? int.MaxValue : (int) value;
152153
}
@@ -245,6 +246,7 @@ private static MySqlGuidFormat GetEffectiveGuidFormat(MySqlGuidFormat guidFormat
245246
public bool UseAffectedRows { get; }
246247
public bool UseCompression { get; }
247248
public bool UseXaTransactions { get; }
249+
public bool UseProcedureCache { get; }
248250

249251
public byte[]? ConnectionAttributes { get; set; }
250252

@@ -335,6 +337,7 @@ private ConnectionSettings(ConnectionSettings other, string host, int port, stri
335337
UseAffectedRows = other.UseAffectedRows;
336338
UseCompression = other.UseCompression;
337339
UseXaTransactions = other.UseXaTransactions;
340+
UseProcedureCache = other.UseProcedureCache;
338341
}
339342

340343
private static readonly string[] s_localhostPipeServer = ["."];

src/MySqlConnector/Core/ServerSession.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public ServerSession(ILogger logger, IConnectionPoolMetadata pool)
6363
public bool SupportsQueryAttributes { get; private set; }
6464
public bool SupportsSessionTrack { get; private set; }
6565
public bool ProcAccessDenied { get; set; }
66+
public bool UseProcedureCache { get; private set; }
6667
public ICollection<KeyValuePair<string, object?>> ActivityTags => m_activityTags;
6768
public MySqlDataReader DataReader { get; set; }
6869
public MySqlConnectionOpenedConditions Conditions { get; private set; }
@@ -607,6 +608,7 @@ public async Task DisposeAsync(IOBehavior ioBehavior, CancellationToken cancella
607608
}
608609

609610
m_payloadHandler.ByteHandler.RemainingTimeout = Constants.InfiniteTimeout;
611+
UseProcedureCache = cs.UseProcedureCache;
610612
return redirectionUrl;
611613
}
612614
catch (ArgumentException ex)

src/MySqlConnector/MySqlConnectionStringBuilder.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -800,6 +800,19 @@ public bool UseXaTransactions
800800
set => MySqlConnectionStringOption.UseXaTransactions.SetValue(this, value);
801801
}
802802

803+
/// <summary>
804+
/// Enables procedure cache.
805+
/// </summary>
806+
[Category("Other")]
807+
[DefaultValue(true)]
808+
[Description("Enables procedure cache.")]
809+
[DisplayName("Use Procedure Cache")]
810+
public bool UseProcedureCache
811+
{
812+
get => MySqlConnectionStringOption.UseProcedureCache.GetValue(this);
813+
set => MySqlConnectionStringOption.UseProcedureCache.SetValue(this, value);
814+
}
815+
803816
// Other Methods
804817

805818
/// <summary>
@@ -958,6 +971,7 @@ internal abstract partial class MySqlConnectionStringOption
958971
public static readonly MySqlConnectionStringValueOption<bool> UseAffectedRows;
959972
public static readonly MySqlConnectionStringValueOption<bool> UseCompression;
960973
public static readonly MySqlConnectionStringValueOption<bool> UseXaTransactions;
974+
public static readonly MySqlConnectionStringValueOption<bool> UseProcedureCache;
961975

962976
public static MySqlConnectionStringOption? TryGetOptionForKey(string key) =>
963977
s_options.TryGetValue(key, out var option) ? option : null;
@@ -1262,6 +1276,10 @@ static MySqlConnectionStringOption()
12621276
AddOption(options, UseXaTransactions = new(
12631277
keys: ["Use XA Transactions", "UseXaTransactions"],
12641278
defaultValue: true));
1279+
1280+
AddOption(options, UseProcedureCache = new(
1281+
keys: ["Use Procedure Cache", "UseProcedureCache"],
1282+
defaultValue: true));
12651283
#pragma warning restore SA1118 // Parameter should not span multiple lines
12661284

12671285
#if NET8_0_OR_GREATER

0 commit comments

Comments
 (0)