Skip to content

Commit

Permalink
Add UseProcedureCache option and documentation. Fixes #1175
Browse files Browse the repository at this point in the history
Signed-off-by: tarasevichvlad <[email protected]>
  • Loading branch information
tarasevichvlad committed Dec 16, 2024
1 parent ce10e20 commit d3af31e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
5 changes: 5 additions & 0 deletions docs/content/connection-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,11 @@ These are the other options that MySqlConnector supports. They are set to sensib
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>.
When set to <code>false</code>, regular MySQL transactions are used, just like Connector/NET.</td>
</tr>
<tr id="UseProcedureCache">
<td>Use Procedure Cache, UseProcedureCache</td>
<td>true</td>
<td>When <code>false</code> disables the procedure cache</td>
</tr>
</table>

## Unsupported Options
Expand Down
3 changes: 3 additions & 0 deletions src/MySqlConnector/Core/CachedProcedure.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ internal sealed class CachedProcedure
{
public static async Task<CachedProcedure?> FillAsync(IOBehavior ioBehavior, MySqlConnection connection, string schema, string component, ILogger logger, CancellationToken cancellationToken)
{
if (!connection.Session.UseProcedureCache)
return null;

// try to use mysql.proc first, as it is much faster
if (!connection.Session.ServerVersion.IsMariaDb &&
connection.Session.ServerVersion.Version < ServerVersions.RemovesMySqlProcTable &&
Expand Down
3 changes: 3 additions & 0 deletions src/MySqlConnector/Core/ConnectionSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ public ConnectionSettings(MySqlConnectionStringBuilder csb)
UseAffectedRows = csb.UseAffectedRows;
UseCompression = csb.UseCompression;
UseXaTransactions = csb.UseXaTransactions;
UseProcedureCache = csb.UseProcedureCache;

static int ToSigned(uint value) => value >= int.MaxValue ? int.MaxValue : (int) value;
}
Expand Down Expand Up @@ -245,6 +246,7 @@ private static MySqlGuidFormat GetEffectiveGuidFormat(MySqlGuidFormat guidFormat
public bool UseAffectedRows { get; }
public bool UseCompression { get; }
public bool UseXaTransactions { get; }
public bool UseProcedureCache { get; }

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

Expand Down Expand Up @@ -335,6 +337,7 @@ private ConnectionSettings(ConnectionSettings other, string host, int port, stri
UseAffectedRows = other.UseAffectedRows;
UseCompression = other.UseCompression;
UseXaTransactions = other.UseXaTransactions;
UseProcedureCache = other.UseProcedureCache;
}

private static readonly string[] s_localhostPipeServer = ["."];
Expand Down
2 changes: 2 additions & 0 deletions src/MySqlConnector/Core/ServerSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public ServerSession(ILogger logger, IConnectionPoolMetadata pool)
public bool SupportsQueryAttributes { get; private set; }
public bool SupportsSessionTrack { get; private set; }
public bool ProcAccessDenied { get; set; }
public bool UseProcedureCache { get; private set; }
public ICollection<KeyValuePair<string, object?>> ActivityTags => m_activityTags;
public MySqlDataReader DataReader { get; set; }
public MySqlConnectionOpenedConditions Conditions { get; private set; }
Expand Down Expand Up @@ -607,6 +608,7 @@ public async Task DisposeAsync(IOBehavior ioBehavior, CancellationToken cancella
}

m_payloadHandler.ByteHandler.RemainingTimeout = Constants.InfiniteTimeout;
UseProcedureCache = cs.UseProcedureCache;
return redirectionUrl;
}
catch (ArgumentException ex)
Expand Down
18 changes: 18 additions & 0 deletions src/MySqlConnector/MySqlConnectionStringBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -800,6 +800,19 @@ public bool UseXaTransactions
set => MySqlConnectionStringOption.UseXaTransactions.SetValue(this, value);
}

/// <summary>
/// Enables procedure cache.
/// </summary>
[Category("Other")]
[DefaultValue(true)]
[Description("Enables procedure cache.")]
[DisplayName("Use Procedure Cache")]
public bool UseProcedureCache
{
get => MySqlConnectionStringOption.UseProcedureCache.GetValue(this);
set => MySqlConnectionStringOption.UseProcedureCache.SetValue(this, value);
}

// Other Methods

/// <summary>
Expand Down Expand Up @@ -958,6 +971,7 @@ internal abstract partial class MySqlConnectionStringOption
public static readonly MySqlConnectionStringValueOption<bool> UseAffectedRows;
public static readonly MySqlConnectionStringValueOption<bool> UseCompression;
public static readonly MySqlConnectionStringValueOption<bool> UseXaTransactions;
public static readonly MySqlConnectionStringValueOption<bool> UseProcedureCache;

public static MySqlConnectionStringOption? TryGetOptionForKey(string key) =>
s_options.TryGetValue(key, out var option) ? option : null;
Expand Down Expand Up @@ -1262,6 +1276,10 @@ static MySqlConnectionStringOption()
AddOption(options, UseXaTransactions = new(
keys: ["Use XA Transactions", "UseXaTransactions"],
defaultValue: true));

AddOption(options, UseProcedureCache = new(
keys: ["Use Procedure Cache", "UseProcedureCache"],
defaultValue: true));
#pragma warning restore SA1118 // Parameter should not span multiple lines

#if NET8_0_OR_GREATER
Expand Down

0 comments on commit d3af31e

Please sign in to comment.