mirror of
https://git.mirrors.martin98.com/https://github.com/SigNoz/signoz
synced 2025-08-15 03:55:53 +08:00
* fix(query): #5861 Changes query which improves performance * fix(test): fixed all the build test * fix(test): fixed all the build test * fix(test): fixed all the build test * fix(test): fixed all the build test * fix(test): fixed all the build test * fix(test): fixed all the build test
This commit is contained in:
parent
64feff3539
commit
679b5db5a2
@ -358,12 +358,13 @@ func buildTracesQuery(start, end, step int64, mq *v3.BuilderQuery, _ string, pan
|
|||||||
case v3.AggregateOperatorNoOp:
|
case v3.AggregateOperatorNoOp:
|
||||||
var query string
|
var query string
|
||||||
if panelType == v3.PanelTypeTrace {
|
if panelType == v3.PanelTypeTrace {
|
||||||
withSubQuery := fmt.Sprintf(constants.TracesExplorerViewSQLSelectWithSubQuery, constants.SIGNOZ_TRACE_DBNAME, constants.SIGNOZ_SPAN_INDEX_TABLENAME, spanIndexTableTimeFilter, filterSubQuery)
|
withSubQuery := fmt.Sprintf(constants.TracesExplorerViewSQLSelectWithSubQuery, constants.SIGNOZ_TRACE_DBNAME, constants.SIGNOZ_SPAN_INDEX_LOCAL_TABLENAME, spanIndexTableTimeFilter, filterSubQuery)
|
||||||
withSubQuery = addLimitToQuery(withSubQuery, mq.Limit)
|
withSubQuery = addLimitToQuery(withSubQuery, mq.Limit)
|
||||||
if mq.Offset != 0 {
|
if mq.Offset != 0 {
|
||||||
withSubQuery = addOffsetToQuery(withSubQuery, mq.Offset)
|
withSubQuery = addOffsetToQuery(withSubQuery, mq.Offset)
|
||||||
}
|
}
|
||||||
query = withSubQuery + ") " + fmt.Sprintf(constants.TracesExplorerViewSQLSelectQuery, constants.SIGNOZ_TRACE_DBNAME, constants.SIGNOZ_SPAN_INDEX_TABLENAME, constants.SIGNOZ_SPAN_INDEX_TABLENAME)
|
// query = withSubQuery + ") " + fmt.Sprintf(constants.TracesExplorerViewSQLSelectQuery, constants.SIGNOZ_TRACE_DBNAME, constants.SIGNOZ_SPAN_INDEX_TABLENAME, constants.SIGNOZ_SPAN_INDEX_TABLENAME)
|
||||||
|
query = fmt.Sprintf(constants.TracesExplorerViewSQLSelectBeforeSubQuery, constants.SIGNOZ_TRACE_DBNAME, constants.SIGNOZ_SPAN_INDEX_TABLENAME) + withSubQuery + ") " + fmt.Sprintf(constants.TracesExplorerViewSQLSelectAfterSubQuery, constants.SIGNOZ_TRACE_DBNAME, constants.SIGNOZ_SPAN_INDEX_TABLENAME, spanIndexTableTimeFilter)
|
||||||
} else if panelType == v3.PanelTypeList {
|
} else if panelType == v3.PanelTypeList {
|
||||||
if len(mq.SelectColumns) == 0 {
|
if len(mq.SelectColumns) == 0 {
|
||||||
return "", fmt.Errorf("select columns cannot be empty for panelType %s", panelType)
|
return "", fmt.Errorf("select columns cannot be empty for panelType %s", panelType)
|
||||||
|
@ -1162,13 +1162,14 @@ var testBuildTracesQueryData = []struct {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
ExpectedQuery: "WITH subQuery AS (SELECT distinct on (traceID) traceID, durationNano, serviceName," +
|
ExpectedQuery: "SELECT subQuery.serviceName, subQuery.name, count() AS span_count, subQuery.durationNano, subQuery.traceID" +
|
||||||
" name FROM signoz_traces.distributed_signoz_index_v2 WHERE parentSpanID = '' AND (timestamp >= '1680066360726210000' AND " +
|
" AS traceID FROM signoz_traces.distributed_signoz_index_v2 INNER JOIN" +
|
||||||
"timestamp <= '1680066458000000000') AND stringTagMap['method'] = 'GET' ORDER BY durationNano DESC LIMIT 100)" +
|
" ( SELECT * FROM (SELECT traceID, durationNano, serviceName, name " +
|
||||||
" SELECT subQuery.serviceName, subQuery.name, count() AS span_count, subQuery.durationNano, traceID" +
|
"FROM signoz_traces.signoz_index_v2 WHERE parentSpanID = '' AND (timestamp >= '1680066360726210000' AND timestamp <= '1680066458000000000') " +
|
||||||
" FROM signoz_traces.distributed_signoz_index_v2 GLOBAL INNER JOIN subQuery ON distributed_signoz_index_v2.traceID" +
|
"AND stringTagMap['method'] = 'GET' ORDER BY durationNano DESC LIMIT 1 BY traceID LIMIT 100)" +
|
||||||
" = subQuery.traceID GROUP BY traceID, subQuery.durationNano, subQuery.name, subQuery.serviceName " +
|
" AS inner_subquery ) AS subQuery " +
|
||||||
"ORDER BY subQuery.durationNano desc;",
|
"ON signoz_traces.distributed_signoz_index_v2.traceID = subQuery.traceID WHERE (timestamp >= '1680066360726210000' AND timestamp <= '1680066458000000000') " +
|
||||||
|
"GROUP BY subQuery.traceID, subQuery.durationNano, subQuery.name, subQuery.serviceName ORDER BY subQuery.durationNano desc LIMIT 1 BY subQuery.traceID;",
|
||||||
PanelType: v3.PanelTypeTrace,
|
PanelType: v3.PanelTypeTrace,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -224,6 +224,7 @@ const (
|
|||||||
SIGNOZ_SAMPLES_V4_TABLENAME = "distributed_samples_v4"
|
SIGNOZ_SAMPLES_V4_TABLENAME = "distributed_samples_v4"
|
||||||
SIGNOZ_TRACE_DBNAME = "signoz_traces"
|
SIGNOZ_TRACE_DBNAME = "signoz_traces"
|
||||||
SIGNOZ_SPAN_INDEX_TABLENAME = "distributed_signoz_index_v2"
|
SIGNOZ_SPAN_INDEX_TABLENAME = "distributed_signoz_index_v2"
|
||||||
|
SIGNOZ_SPAN_INDEX_LOCAL_TABLENAME = "signoz_index_v2"
|
||||||
SIGNOZ_TIMESERIES_v4_LOCAL_TABLENAME = "time_series_v4"
|
SIGNOZ_TIMESERIES_v4_LOCAL_TABLENAME = "time_series_v4"
|
||||||
SIGNOZ_TIMESERIES_v4_6HRS_LOCAL_TABLENAME = "time_series_v4_6hrs"
|
SIGNOZ_TIMESERIES_v4_6HRS_LOCAL_TABLENAME = "time_series_v4_6hrs"
|
||||||
SIGNOZ_TIMESERIES_v4_1DAY_LOCAL_TABLENAME = "time_series_v4_1day"
|
SIGNOZ_TIMESERIES_v4_1DAY_LOCAL_TABLENAME = "time_series_v4_1day"
|
||||||
@ -322,8 +323,12 @@ const (
|
|||||||
"attributes_number, " +
|
"attributes_number, " +
|
||||||
"attributes_bool, " +
|
"attributes_bool, " +
|
||||||
"resources_string "
|
"resources_string "
|
||||||
TracesExplorerViewSQLSelectWithSubQuery = "WITH subQuery AS (SELECT distinct on (traceID) traceID, durationNano, " +
|
TracesExplorerViewSQLSelectWithSubQuery = "(SELECT traceID, durationNano, " +
|
||||||
"serviceName, name FROM %s.%s WHERE parentSpanID = '' AND %s %s ORDER BY durationNano DESC "
|
"serviceName, name FROM %s.%s WHERE parentSpanID = '' AND %s %s ORDER BY durationNano DESC LIMIT 1 BY traceID "
|
||||||
|
TracesExplorerViewSQLSelectBeforeSubQuery = "SELECT subQuery.serviceName, subQuery.name, count() AS " +
|
||||||
|
"span_count, subQuery.durationNano, subQuery.traceID AS traceID FROM %s.%s INNER JOIN ( SELECT * FROM "
|
||||||
|
TracesExplorerViewSQLSelectAfterSubQuery = "AS inner_subquery ) AS subQuery ON %s.%s.traceID = subQuery.traceID WHERE %s " +
|
||||||
|
"GROUP BY subQuery.traceID, subQuery.durationNano, subQuery.name, subQuery.serviceName ORDER BY subQuery.durationNano desc LIMIT 1 BY subQuery.traceID;"
|
||||||
TracesExplorerViewSQLSelectQuery = "SELECT subQuery.serviceName, subQuery.name, count() AS " +
|
TracesExplorerViewSQLSelectQuery = "SELECT subQuery.serviceName, subQuery.name, count() AS " +
|
||||||
"span_count, subQuery.durationNano, traceID FROM %s.%s GLOBAL INNER JOIN subQuery ON %s.traceID = subQuery.traceID GROUP " +
|
"span_count, subQuery.durationNano, traceID FROM %s.%s GLOBAL INNER JOIN subQuery ON %s.traceID = subQuery.traceID GROUP " +
|
||||||
"BY traceID, subQuery.durationNano, subQuery.name, subQuery.serviceName ORDER BY subQuery.durationNano desc;"
|
"BY traceID, subQuery.durationNano, subQuery.name, subQuery.serviceName ORDER BY subQuery.durationNano desc;"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user