From ea76335527d7c4deebb9e5016e510d24f7275029 Mon Sep 17 00:00:00 2001 From: LEE <995362096@qq.com> Date: Tue, 27 Jul 2021 15:50:55 +0800 Subject: [PATCH] Avoid "select *" query (#7372) --- CHANGES.md | 1 + .../plugin/jdbc/h2/dao/H2TraceQueryDAO.java | 22 ++++++++++++++++--- 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index a7d8e7917..2296942cf 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -120,6 +120,7 @@ Release Notes. * Fix PrometheusMetricConverter may throw an `IllegalArgumentException` when convert metrics to SampleFamily * Filtering NaN value samples when build SampleFamily * Add Thread and ClassLoader Metrics for the self-observability and otel-oc-rules +* Simple optimization of trace sql query statement. Avoid "select *" query method #### UI diff --git a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2TraceQueryDAO.java b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2TraceQueryDAO.java index 18971ec9d..7838371ba 100644 --- a/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2TraceQueryDAO.java +++ b/oap-server/server-storage-plugin/storage-jdbc-hikaricp-plugin/src/main/java/org/apache/skywalking/oap/server/storage/plugin/jdbc/h2/dao/H2TraceQueryDAO.java @@ -177,7 +177,13 @@ public class H2TraceQueryDAO implements ITraceQueryDAO { buildLimit(sql, from, limit); try (ResultSet resultSet = h2Client.executeQuery( - connection, "select * " + sql.toString(), parameters.toArray(new Object[0]))) { + connection, "select " + + SegmentRecord.SEGMENT_ID + ", " + + SegmentRecord.START_TIME + ", " + + SegmentRecord.ENDPOINT_NAME + ", " + + SegmentRecord.LATENCY + ", " + + SegmentRecord.IS_ERROR + ", " + + SegmentRecord.TRACE_ID + " " + sql, parameters.toArray(new Object[0]))) { while (resultSet.next()) { BasicTrace basicTrace = new BasicTrace(); @@ -213,8 +219,18 @@ public class H2TraceQueryDAO implements ITraceQueryDAO { try (Connection connection = h2Client.getConnection()) { try (ResultSet resultSet = h2Client.executeQuery( - connection, "select * from " + SegmentRecord.INDEX_NAME + " where " + SegmentRecord.TRACE_ID + " = ?", - traceId + connection, "select " + SegmentRecord.SEGMENT_ID + ", " + + SegmentRecord.TRACE_ID + ", " + + SegmentRecord.SERVICE_ID + ", " + + SegmentRecord.SERVICE_INSTANCE_ID + ", " + + SegmentRecord.ENDPOINT_NAME + ", " + + SegmentRecord.START_TIME + ", " + + SegmentRecord.END_TIME + ", " + + SegmentRecord.LATENCY + ", " + + SegmentRecord.IS_ERROR + ", " + + SegmentRecord.DATA_BINARY + ", " + + SegmentRecord.VERSION + " from " + + SegmentRecord.INDEX_NAME + " where " + SegmentRecord.TRACE_ID + " = ?", traceId )) { while (resultSet.next()) { SegmentRecord segmentRecord = new SegmentRecord();