{"record":{"id":"baf2155ef8f0935f","repo":"SigNoz/signoz","slug":"error-while-executing-query-s","errorCode":null,"errorMessage":"error while executing query: %s","messagePattern":"error while executing query: (.+?)","errorType":"exception","errorClass":null,"httpStatus":500,"severity":"error","filePath":"pkg/query-service/app/clickhouseReader/reader.go","lineNumber":3121,"sourceCode":"\tvar err error\n\tvar rows driver.Rows\n\tvar response v3.FilterAttributeKeyResponse\n\n\treductionEnabled := r.fl.BooleanOrEmpty(ctx, flagger.FeatureEnableMetricsReduction, featuretypes.NewFlaggerEvaluationContext(orgID))\n\n\t// skips the internal attributes i.e attributes starting with __\n\tif reductionEnabled {\n\t\tquery = fmt.Sprintf(\"SELECT arrayJoin(tagKeys) AS distinctTagKey FROM (SELECT JSONExtractKeys(labels) AS tagKeys FROM %s.%s WHERE metric_name=$1 AND unix_milli >= $2 GROUP BY tagKeys UNION ALL SELECT JSONExtractKeys(labels) AS tagKeys FROM %s.%s WHERE metric_name=$1 AND unix_milli >= $2 GROUP BY tagKeys) WHERE distinctTagKey ILIKE $3 AND distinctTagKey NOT LIKE '\\\\_\\\\_%%' GROUP BY distinctTagKey\", signozMetricDBName, signozTSTableNameV41Day, signozMetricDBName, signozTSTableNameV4Reduced)\n\t} else {\n\t\tquery = fmt.Sprintf(\"SELECT arrayJoin(tagKeys) AS distinctTagKey FROM (SELECT JSONExtractKeys(labels) AS tagKeys FROM %s.%s WHERE metric_name=$1 AND unix_milli >= $2 GROUP BY tagKeys) WHERE distinctTagKey ILIKE $3 AND distinctTagKey NOT LIKE '\\\\_\\\\_%%' GROUP BY distinctTagKey\", signozMetricDBName, signozTSTableNameV41Day)\n\t}\n\tif req.Limit != 0 {\n\t\tquery = query + fmt.Sprintf(\" LIMIT %d;\", req.Limit)\n\t}\n\trows, err = r.db.Query(ctx, query, req.AggregateAttribute, common.PastDayRoundOff(), fmt.Sprintf(\"%%%s%%\", req.SearchText))\n\tif err != nil {\n\t\tr.logger.Error(\"Error while executing query\", errorsV2.Attr(err))\n\t\treturn nil, fmt.Errorf(\"error while executing query: %s\", err.Error())\n\t}\n\tdefer rows.Close()\n\n\tvar attributeKey string\n\tfor rows.Next() {\n\t\tif err := rows.Scan(&attributeKey); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error while scanning rows: %s\", err.Error())\n\t\t}\n\t\tkey := v3.AttributeKey{\n\t\t\tKey:      attributeKey,\n\t\t\tDataType: v3.AttributeKeyDataTypeString, // https://github.com/OpenObservability/OpenMetrics/blob/main/proto/openmetrics_data_model.proto#L64-L72.\n\t\t\tType:     v3.AttributeKeyTypeTag,\n\t\t\tIsColumn: false,\n\t\t}\n\t\tresponse.AttributeKeys = append(response.AttributeKeys, key)\n\t}\n\n\treturn &response, nil","sourceCodeStart":3103,"sourceCodeEnd":3139,"githubUrl":"https://github.com/SigNoz/signoz/blob/5069bf80b08f1f00d7e014eccc09902f9871004f/pkg/query-service/app/clickhouseReader/reader.go#L3103-L3139","documentation":"In the metric attribute-keys lookup, the db.Query with parameters (AggregateAttribute, PastDayRoundOff, %SearchText%) failed to execute. This query lists tag keys associated with a chosen metric over the last day; failure means ClickHouse rejected or could not run it, with the raw error embedded in %s.","triggerScenarios":"Building a query-builder filter UI for metrics: user selects an aggregate attribute and the backend fetches available tag keys, but the time_series/attributes table is missing, unreachable, or the parameter binding fails.","commonSituations":"Fresh clusters with no metric data; signoz_metrics schema not created; special characters in SearchText breaking the LIKE pattern; ClickHouse overload.","solutions":["Inspect the %s suffix for the underlying ClickHouse error","Verify the metrics attribute tables exist and have data within the last day (the query filters on PastDayRoundOff)","Sanitize/limit SearchText length on the API boundary","Retry when ClickHouse is healthy; the query is read-only"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// validate inputs before calling\nif req.AggregateAttribute == \"\" || len(req.SearchText) > 100 { return empty, nil }","typeGuard":null,"tryCatchPattern":"if err != nil {\n  if strings.Contains(err.Error(), \"UNKNOWN_TABLE\") { return emptyKeys(), nil }\n  if isTransientClickhouseErr(err) { return retry(ctx) }\n  return nil, err\n}","preventionTips":["Ensure metrics were ingested in the last day before querying attribute keys (past-day filter)","Limit SearchText length; validate AggregateAttribute non-empty"],"tags":["clickhouse","metrics","attributes","query-execution"],"backgroundTag":"database-query-failed","analyzedSha":"5069bf80b08f1f00d7e014eccc09902f9871004f","analyzedAt":"2026-08-28T06:22:12.824Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}