You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by wu...@apache.org on 2021/07/27 07:51:30 UTC
[skywalking] branch master updated: Avoid "select *" query (#7372)
This is an automated email from the ASF dual-hosted git repository.
wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking.git
The following commit(s) were added to refs/heads/master by this push:
new ea76335 Avoid "select *" query (#7372)
ea76335 is described below
commit ea76335527d7c4deebb9e5016e510d24f7275029
Author: LEE <99...@qq.com>
AuthorDate: Tue Jul 27 15:50:55 2021 +0800
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 a7d8e79..2296942 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 18971ec..7838371 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();