{"record":{"id":"de1199062f0778f3","repo":"SigNoz/signoz","slug":"multiple-orderby-criteria-are-not-supported-for-tr","errorCode":null,"errorMessage":"multiple orderBy criteria are not supported for trace queries","messagePattern":"multiple orderBy criteria are not supported for trace queries","errorType":"validation","errorClass":null,"httpStatus":400,"severity":"error","filePath":"pkg/query-service/app/traces/v4/query_builder.go","lineNumber":314,"sourceCode":"\t\tfilterSubQuery = filterSubQuery + \" AND \" + spanScopeSubQuery\n\t}\n\n\t// timerange will be sent in epoch millisecond\n\tselectLabels := getSelectLabels(mq.GroupBy)\n\tif selectLabels != \"\" {\n\t\tselectLabels = selectLabels + \",\"\n\t}\n\n\torderBy := orderByAttributeKeyTags(panelType, mq.OrderBy, mq.GroupBy)\n\tif orderBy != \"\" {\n\t\torderBy = \" order by \" + orderBy\n\t}\n\n\tif mq.AggregateOperator == v3.AggregateOperatorNoOp {\n\t\tvar query string\n\t\tif panelType == v3.PanelTypeTrace {\n\t\t\tif len(mq.OrderBy) > 1 {\n\t\t\t\treturn \"\", fmt.Errorf(\"multiple orderBy criteria are not supported for trace queries\")\n\t\t\t}\n\t\t\torderBySpanCount := false\n\n\t\t\t// Check if orderBy contains a specific reference to span_count\n\t\t\tif len(mq.OrderBy) == 1 && mq.OrderBy[0].ColumnName == constants.OrderBySpanCount {\n\t\t\t\torderBySpanCount = true\n\t\t\t}\n\t\t\tif !orderBySpanCount {\n\t\t\t\twithSubQuery := fmt.Sprintf(constants.TracesExplorerViewSQLSelectWithSubQuery, constants.SIGNOZ_TRACE_DBNAME, constants.SIGNOZ_SPAN_INDEX_V3_LOCAL_TABLENAME, timeFilter)\n\t\t\t\tafterSubQuery := tracesV3.AddLimitToQuery(constants.TracesExplorerViewSQLSelectAfterSubQuery, mq.Limit)\n\t\t\t\tif mq.Offset != 0 {\n\t\t\t\t\tafterSubQuery = tracesV3.AddOffsetToQuery(afterSubQuery, mq.Offset)\n\t\t\t\t}\n\t\t\t\tquery = fmt.Sprintf(constants.TracesExplorerViewSQLSelectBeforeSubQuery, constants.SIGNOZ_TRACE_DBNAME, constants.SIGNOZ_SPAN_INDEX_V3, timeFilter, filterSubQuery) + withSubQuery + \")\" + afterSubQuery\n\t\t\t} else {\n\t\t\t\twithSubQueryWithLimits := tracesV3.AddLimitToQuery(constants.TracesExplorerSpanCountWithSubQuery, mq.Limit)\n\t\t\t\twithSubQuery := fmt.Sprintf(withSubQueryWithLimits, constants.SIGNOZ_TRACE_DBNAME, constants.SIGNOZ_SPAN_INDEX_V3_LOCAL_TABLENAME, timeFilter, filterSubQuery)\n\t\t\t\tafterSubQuery := tracesV3.AddLimitToQuery(constants.TraceExplorerSpanCountAfterSubQuery, mq.Limit)","sourceCodeStart":296,"sourceCodeEnd":332,"githubUrl":"https://github.com/SigNoz/signoz/blob/5069bf80b08f1f00d7e014eccc09902f9871004f/pkg/query-service/app/traces/v4/query_builder.go#L296-L332","documentation":"buildTracesQuery (v4) with AggregateOperator=no-op and panelType=trace builds a single ORDER BY clause for the trace list SQL; more than one orderBy entry cannot be expressed and is rejected.","triggerScenarios":"A traces list (PanelTypeTrace) no-op query whose mq.OrderBy array contains 2 or more items.","commonSituations":"UI sends default timestamp ordering plus a user-added sort; copying a list panel's orderBy from another panel type that allows multi-sort.","solutions":["Reduce orderBy to a single column for trace list queries","Keep only the user's primary sort and drop secondary sorts client-side"],"exampleFix":"// before\nmq.OrderBy = []v3.OrderBy{{ColumnName:\"timestamp\", Order:\"desc\"},{ColumnName:\"duration_ns\", Order:\"desc\"}}\n\n// after\nmq.OrderBy = []v3.OrderBy{{ColumnName:\"timestamp\", Order:\"desc\"}}","handlingStrategy":"validation","validationCode":"if panelType == v3.PanelTypeTrace && mq.AggregateOperator == v3.AggregateOperatorNoOp && len(mq.OrderBy) > 1 {\n    mq.OrderBy = mq.OrderBy[:1] // keep primary sort\n}","typeGuard":"func isSingleOrderBy(mq *v3.BuilderQuery) bool { return len(mq.OrderBy) <= 1 }","tryCatchPattern":null,"preventionTips":["Enforce single-sort UI for trace list panels","Trim secondary sorts before serializing the query"],"tags":["signoz","traces","v4","order-by","validation"],"backgroundTag":"query-validation-failed","analyzedSha":"5069bf80b08f1f00d7e014eccc09902f9871004f","analyzedAt":"2026-08-28T06:22:12.824Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}