{"record":{"id":"1463853c7d1691cb","repo":"SigNoz/signoz","slug":"couldn-t-query-attrib-values-for-suggestions-w","errorCode":null,"errorMessage":"couldn't query attrib values for suggestions: %w","messagePattern":"couldn't query attrib values for suggestions: %w","errorType":"exception","errorClass":"model.ApiError","httpStatus":500,"severity":"error","filePath":"pkg/query-service/app/clickhouseReader/filter_suggestions.go","lineNumber":188,"sourceCode":"\t\t\tselect tag_key, string_value, number_value\n\t\t\tfrom %s.%s\n\t\t\twhere tag_key = $%d and (\n\t\t\t\tstring_value != '' or number_value is not null\n\t\t\t) and tag_type != 'logfield'\n\t\t\tlimit %d\n\t\t)`, r.logsDB, r.logsTagAttributeTableV2, idx+1, limit))\n\n\t\ttagKeyQueryArgs = append(tagKeyQueryArgs, attrib.Key)\n\t}\n\n\tquery := fmt.Sprintf(`select * from (\n\t\t%s\n\t) settings max_threads=2`, strings.Join(tagQueries, \" UNION DISTINCT \"))\n\n\trows, err := r.db.Query(ctx, query, tagKeyQueryArgs...)\n\tif err != nil {\n\t\tr.logger.ErrorContext(ctx, \"couldn't query attrib values for suggestions\", errorsV2.Attr(err))\n\t\treturn nil, model.InternalError(fmt.Errorf(\n\t\t\t\"couldn't query attrib values for suggestions: %w\", err,\n\t\t))\n\t}\n\tdefer rows.Close()\n\n\tresult := make([][]any, len(attributes))\n\n\t// Helper for getting hold of the result slice to append to for each scanned row\n\tresultIdxForAttrib := func(key string, dataType v3.AttributeKeyDataType) int {\n\t\treturn slices.IndexFunc(attributes, func(attrib v3.AttributeKey) bool {\n\t\t\treturn attrib.Key == key && attrib.DataType == dataType\n\t\t})\n\t}\n\n\t// Scan rows and append to result\n\tfor rows.Next() {\n\t\tvar tagKey string\n\t\tvar stringValue string","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/SigNoz/signoz/blob/5069bf80b08f1f00d7e014eccc09902f9871004f/pkg/query-service/app/clickhouseReader/filter_suggestions.go#L170-L206","documentation":"InternalError from getValuesForLogAttributes when the UNION DISTINCT tag-value query against ClickHouse fails while building log filter suggestions. The query is built per requested attribute and executed with max_threads=2; any DB-level failure (timeout, missing column, overload) triggers it.","triggerScenarios":"GetQBFilterSuggestionsForLogs with one or more string/number attributes whose UNION-ed SELECT against the tag value tables fails: unknown column (renamed/missing attribute key), ClickHouse timeout, or packet/protocol errors under load.","commonSituations":"Attribute keys that no longer exist in the schema, mixed schema versions after upgrade, ClickHouse under memory pressure, very high-cardinality attributes making the UNION DISTINCT query slow/aborted.","solutions":["Check server logs for the logged ClickHouse error (it is logged just before returning)","Validate the requested attribute keys actually exist as columns in the log tables","Reduce the number/range of attributes requested or add time bounds","Scale/optimize ClickHouse (marks, memory limits) or retry when load drops"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Validate requested attributes exist before asking for values\nfor _, k := range req.AttributeKeys {\n    if !attributeKeyExists(ctx, ch, k) { return fmt.Errorf(\"unknown attribute %s\", k) }\n}","typeGuard":"func isChQueryErr(err error) bool {\n    var apiErr *model.ApiError\n    return errors.As(err, &apiErr) && apiErr.Typ == model.ErrorInternal && strings.Contains(err.Error(), \"attrib values\")\n}","tryCatchPattern":"vals, err := reader.GetQBFilterSuggestionsForLogs(ctx, req)\nif err != nil && isChQueryErr(err) {\n    // transient CH failures are common; retry once with smaller attribute set\n    req.AttributeKeys = req.AttributeKeys[:1]\n    vals, err = reader.GetQBFilterSuggestionsForLogs(ctx, req)\n}","preventionTips":["Limit attributes per suggestions request","Add time-range bounds to value queries","Monitor ClickHouse query latencies/kill counts"],"tags":["clickhouse","logs","filter-suggestions","database"],"backgroundTag":"database-query-failed","analyzedSha":"5069bf80b08f1f00d7e014eccc09902f9871004f","analyzedAt":"2026-08-28T06:22:12.824Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}