Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: use TypeInfo getPGArrayType instead of munging type name (#913
) The purpose of the getPGArrayType method is to get the array type for a given element type. Let the TypeInfo implementation figure out how to do that rather than appending "[]" to the element type name in PgPreparedStatement setArray.
- Loading branch information
Showing
2 changed files
with
99 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
ubenchmark/src/main/java/org/postgresql/benchmark/statement/BindArray.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,97 @@ | |||
/* | |||
* Copyright (c) 2017, PostgreSQL Global Development Group | |||
* See the LICENSE file in the project root for more information. | |||
*/ | |||
|
|||
package org.postgresql.benchmark.statement; | |||
|
|||
import org.postgresql.benchmark.profilers.FlightRecorderProfiler; | |||
import org.postgresql.util.ConnectionUtil; | |||
|
|||
import org.openjdk.jmh.annotations.Benchmark; | |||
import org.openjdk.jmh.annotations.BenchmarkMode; | |||
import org.openjdk.jmh.annotations.Fork; | |||
import org.openjdk.jmh.annotations.Level; | |||
import org.openjdk.jmh.annotations.Measurement; | |||
import org.openjdk.jmh.annotations.Mode; | |||
import org.openjdk.jmh.annotations.OutputTimeUnit; | |||
import org.openjdk.jmh.annotations.Param; | |||
import org.openjdk.jmh.annotations.Scope; | |||
import org.openjdk.jmh.annotations.Setup; | |||
import org.openjdk.jmh.annotations.State; | |||
import org.openjdk.jmh.annotations.TearDown; | |||
import org.openjdk.jmh.annotations.Warmup; | |||
import org.openjdk.jmh.profile.GCProfiler; | |||
import org.openjdk.jmh.runner.Runner; | |||
import org.openjdk.jmh.runner.RunnerException; | |||
import org.openjdk.jmh.runner.options.Options; | |||
import org.openjdk.jmh.runner.options.OptionsBuilder; | |||
|
|||
import java.sql.Array; | |||
import java.sql.Connection; | |||
import java.sql.DriverManager; | |||
import java.sql.PreparedStatement; | |||
import java.sql.SQLException; | |||
import java.sql.Statement; | |||
import java.sql.Types; | |||
import java.util.Properties; | |||
import java.util.concurrent.TimeUnit; | |||
|
|||
@Fork(value = 1, jvmArgsPrepend = "-Xmx128m") | |||
@Measurement(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS) | |||
@Warmup(iterations = 10, time = 1, timeUnit = TimeUnit.SECONDS) | |||
@State(Scope.Thread) | |||
@BenchmarkMode(Mode.AverageTime) | |||
@OutputTimeUnit(TimeUnit.NANOSECONDS) | |||
public class BindArray { | |||
private Connection connection; | |||
private PreparedStatement ps; | |||
|
|||
Integer[] ints; | |||
|
|||
@Param({"1", "5", "10", "50", "100", "1000"}) | |||
int arraySize; | |||
|
|||
@Setup(Level.Trial) | |||
public void setUp() throws SQLException { | |||
Properties props = ConnectionUtil.getProperties(); | |||
|
|||
connection = DriverManager.getConnection(ConnectionUtil.getURL(), props); | |||
ps = connection.prepareStatement("SELECT ?"); | |||
ints = new Integer[arraySize]; | |||
for (int i = 0; i < arraySize; i++) { | |||
ints[i] = i + 1; | |||
} | |||
} | |||
|
|||
@TearDown(Level.Trial) | |||
public void tearDown() throws SQLException { | |||
ps.close(); | |||
connection.close(); | |||
} | |||
|
|||
@Benchmark | |||
public Statement setObject() throws SQLException { | |||
Array sqlInts = connection.createArrayOf("int", ints); | |||
ps.setObject(1, sqlInts, Types.ARRAY); | |||
return ps; | |||
} | |||
|
|||
@Benchmark | |||
public Statement setArray() throws SQLException { | |||
Array sqlInts = connection.createArrayOf("int", ints); | |||
ps.setArray(1, sqlInts); | |||
return ps; | |||
} | |||
|
|||
public static void main(String[] args) throws RunnerException { | |||
Options opt = new OptionsBuilder() | |||
.include(BindArray.class.getSimpleName()) | |||
.addProfiler(GCProfiler.class) | |||
.addProfiler(FlightRecorderProfiler.class) | |||
.detectJvmArgs() | |||
.build(); | |||
|
|||
new Runner(opt).run(); | |||
} | |||
} |