Avoid "select *" query (#7372)

This commit is contained in:
LEE 2021-07-27 15:50:55 +08:00 committed by GitHub
parent 7ada0096ad
commit ea76335527
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 3 deletions

View File

@ -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

View File

@ -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();