{"record":{"id":"b4d16f4b25bc4ee0","repo":"cockroachdb/cockroach","slug":"error-while-retrieving-statements-information-s-b4d16f","errorCode":null,"errorMessage":"Error while retrieving statements information: ${sqlApiErrorMessage(stmtQueriesResponse.error.message)}","messagePattern":"Error while retrieving statements information: (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"pkg/ui/workspaces/cluster-ui/src/api/contentionApi.ts","lineNumber":393,"sourceCode":"\n  const stmtFingerprintIDs = new Set<string>();\n  txnsWithStmtFingerprints.forEach(txnFingerprint =>\n    txnFingerprint.queryIDs.forEach(id => stmtFingerprintIDs.add(id)),\n  );\n\n  // Request query string from stmt fingerprint ids.\n  let stmtQueriesResponse: SqlExecutionResponse<FingerprintStmtsResponseColumns> | null =\n    null;\n\n  if (stmtFingerprintIDs.size) {\n    stmtQueriesResponse =\n      await executeInternalSql<FingerprintStmtsResponseColumns>(\n        makeInsightsSqlRequest([\n          fingerprintStmtsQuery(Array.from(stmtFingerprintIDs)),\n        ]),\n      );\n    if (stmtQueriesResponse.error) {\n      throw new Error(\n        `Error while retrieving statements information: ${sqlApiErrorMessage(\n          stmtQueriesResponse.error.message,\n        )}`,\n      );\n    }\n  }\n\n  return buildTxnContentionInsightDetails(\n    contentionDetails,\n    txnsWithStmtFingerprints,\n    createStmtFingerprintToQueryMap(stmtQueriesResponse),\n  );\n}\n","sourceCodeStart":375,"sourceCodeEnd":407,"githubUrl":"https://github.com/cockroachdb/cockroach/blob/8812064a015d2faf99d3fc7e15880f94042954b0/pkg/ui/workspaces/cluster-ui/src/api/contentionApi.ts#L375-L407","documentation":"Second failure point in getTxnContentionInsightDetails: after statement fingerprint IDs are extracted from the txn fingerprints, the query strings are fetched via fingerprintStmtsQuery (crdb_internal.statement_statistics) and any response error is thrown with the same 'retrieving statements information' context. The query only runs when stmtFingerprintIDs.size > 0, so the txn-fingerprint step must have succeeded first.","triggerScenarios":"A contention insight where blocking txns resolved to at least one stmt fingerprint id, and the fingerprintStmtsQuery SQL API request returns an error (query failure, permission denial, gateway error, or oversized result).","commonSituations":"Same class as the txn-fingerprint step: very large statement statistics tables exceeding the SQL API result limit, console user without access to crdb_internal.statement_statistics, or version skew on the internal table schema during rolling upgrades.","solutions":["Inspect the sqlApiErrorMessage suffix for the concrete SQL error","For max-size errors, shrink the request: fewer blocking fingerprints or a narrower contention time window","Execute the fingerprintStmtsQuery output by hand as the console user to check privileges and result size","Verify the cluster version supports the statement_statistics columns the query selects"],"exampleFix":"// before\nif (stmtQueriesResponse.error) {\n  throw new Error(`Error while retrieving statements information: ${sqlApiErrorMessage(stmtQueriesResponse.error.message)}`);\n}\n\n// after: degrade instead of failing the whole insight when queries cannot be resolved\nconst stmtMaxSize = isMaxSizeError(stmtQueriesResponse.error?.message);\nif (stmtQueriesResponse.error && !stmtMaxSize) {\n  getLogger().warn(`Error while resolving statement queries: ${sqlApiErrorMessage(stmtQueriesResponse.error.message)}`);\n}\nreturn buildTxnContentionInsightDetails(\n  contentionDetails,\n  txnsWithStmtFingerprints,\n  createStmtFingerprintToQueryMap(stmtQueriesResponse),\n);","handlingStrategy":"try-catch","validationCode":"// Only request query strings for a bounded set of fingerprint ids\nconst ids = Array.from(stmtFingerprintIDs).slice(0, 500);\nif (ids.length === 0) {\n  return buildTxnContentionInsightDetails(\n    contentionDetails,\n    txnsWithStmtFingerprints,\n    new Map(),\n  );\n}","typeGuard":"const hasSqlApiError = (\n  r: SqlExecutionResponse<unknown> | null,\n): r is SqlExecutionResponse<unknown> & { error: SqlExecutionErrorMessage } =>\n  !!r?.error;","tryCatchPattern":"try {\n  stmtQueriesResponse = await executeInternalSql<FingerprintStmtsResponseColumns>(\n    makeInsightsSqlRequest([fingerprintStmtsQuery(Array.from(stmtFingerprintIDs))]),\n  );\n} catch (e) {\n  getLogger().warn(`Failed to resolve statement queries: ${e}`);\n  stmtQueriesResponse = null; // buildTxnContentionInsightDetails tolerates null\n}","preventionTips":["Bound the fingerprint id list before querying","Treat query-string resolution as best-effort: names can be dropped without losing the contention insight","Monitor SQL API errors on crdb_internal.statement_statistics for permission drift"],"tags":["cluster-ui","sql-api","contention","insights","typescript"],"backgroundTag":null,"analyzedSha":"8812064a015d2faf99d3fc7e15880f94042954b0","analyzedAt":"2026-08-15T16:34:17.351Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}