diff --git a/src/BenchmarksApps/TechEmpower/PlatformBenchmarks/Data/BatchUpdateString.cs b/src/BenchmarksApps/TechEmpower/PlatformBenchmarks/Data/BatchUpdateString.cs index 782f56a98..04cf83ebb 100644 --- a/src/BenchmarksApps/TechEmpower/PlatformBenchmarks/Data/BatchUpdateString.cs +++ b/src/BenchmarksApps/TechEmpower/PlatformBenchmarks/Data/BatchUpdateString.cs @@ -1,8 +1,7 @@ -// Copyright (c) .NET Foundation. All rights reserved. -// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. +// Copyright (c) .NET Foundation. All rights reserved. +// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. using System; -using System.Linq; namespace PlatformBenchmarks { @@ -10,10 +9,6 @@ internal class BatchUpdateString { private const int MaxBatch = 500; - public static DatabaseServer DatabaseServer; - - internal static readonly string[] ParamNames = Enumerable.Range(0, MaxBatch * 2).Select(i => $"@p{i}").ToArray(); - private static string[] _queries = new string[MaxBatch + 1]; public static string Query(int batchSize) @@ -31,23 +26,15 @@ private static string CreateBatch(int batchSize) Func paramNameGenerator = i => "@p" + i; #endif - sb.AppendLine("UPDATE world SET randomNumber = CASE id"); - for (var i = 0; i < batchSize * 2;) - { - sb.AppendLine($"when {paramNameGenerator(++i)} then {paramNameGenerator(++i)}"); - } - sb.AppendLine("else randomnumber"); - sb.AppendLine("end"); - sb.Append("where id in ("); - for (var i = 1; i < batchSize * 2; i += 2) + sb.Append("UPDATE world SET randomNumber = temp.randomNumber FROM (VALUES "); + var c = 1; + for (var i = 0; i < batchSize; i++) { - sb.Append(paramNameGenerator(i)); - if (i < batchSize * 2 - 1) - { - sb.AppendLine(", "); - } + if (i > 0) + sb.Append(", "); + sb.Append($"({paramNameGenerator(c++)}, {paramNameGenerator(c++)})"); } - sb.Append(")"); + sb.Append(" ORDER BY 1) AS temp(id, randomNumber) WHERE temp.id = world.id"); return _queries[batchSize] = StringBuilderCache.GetStringAndRelease(sb); } diff --git a/src/BenchmarksApps/TechEmpower/PlatformBenchmarks/Program.cs b/src/BenchmarksApps/TechEmpower/PlatformBenchmarks/Program.cs index 35889e774..fd2a81db7 100644 --- a/src/BenchmarksApps/TechEmpower/PlatformBenchmarks/Program.cs +++ b/src/BenchmarksApps/TechEmpower/PlatformBenchmarks/Program.cs @@ -37,8 +37,6 @@ public static async Task Main(string[] args) DateHeader.SyncDateTimer(); var host = BuildWebHost(args); - var config = (IConfiguration)host.Services.GetService(typeof(IConfiguration)); - BatchUpdateString.DatabaseServer = config.Get().Database; #if DATABASE await BenchmarkApplication.RawDb.PopulateCache(); #endif