Skip to content

Commit 54a3a38

Browse files
craig[bot]Thomas Hardy
andcommitted
107893: cluster-ui: fix replicas and regions query for the database details API r=THardy98 a=THardy98 Epic: None A change in cockroachdb#105582 caused the regions/replicas query to return incorrect, unexpected results (instead of reducing the returned rows from the CTE to a single row, the cross join caused the number of rows to square, resulting in x^2 rows) causing the endpoint to never resolve properly, which in turn, caused an infinite loading state. This change fixes the regions/replicas query for the database details API. Release note (ui change): fix a broken query for the database details page that was causing an infinite loading state. Co-authored-by: Thomas Hardy <[email protected]>
2 parents 89040b4 + 8d8db98 commit 54a3a38

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

pkg/ui/workspaces/cluster-ui/src/api/databaseDetailsApi.ts

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -347,19 +347,19 @@ const getDatabaseReplicasAndRegions: DatabaseDetailsQuery<DatabaseReplicasRegion
347347
createStmt: dbName => {
348348
return {
349349
sql: Format(
350-
`WITH
351-
replicasAndRegions AS (
352-
SELECT
353-
r.replicas,
354-
ARRAY(SELECT DISTINCT split_part(split_part(unnest(replica_localities),',',1),'=',2)) AS regions
355-
FROM crdb_internal.tables AS t
356-
JOIN %1.crdb_internal.table_spans AS s ON s.descriptor_id = t.table_id
357-
JOIN crdb_internal.ranges_no_leases AS r ON s.start_key < r.end_key AND s.end_key > r.start_key
358-
WHERE t.database_name = $1
359-
),
360-
unique_replicas AS (SELECT (SELECT array_agg(distinct unnested) FROM unnest(replicas) AS unnested) AS regions FROM replicasAndRegions),
361-
unique_regions AS (SELECT (SELECT array_agg(distinct unnested) FROM unnest(regions) AS unnested) AS replicas FROM replicasAndRegions)
362-
SELECT replicas, regions FROM unique_replicas CROSS JOIN unique_regions`,
350+
`WITH replicasAndRegionsPerDbRange AS (
351+
SELECT
352+
r.replicas,
353+
ARRAY(SELECT DISTINCT split_part(split_part(unnest(replica_localities), ',', 1), '=', 2)) AS regions
354+
FROM crdb_internal.tables AS t
355+
JOIN %1.crdb_internal.table_spans AS s ON s.descriptor_id = t.table_id
356+
JOIN crdb_internal.ranges_no_leases AS r ON s.start_key < r.end_key AND s.end_key > r.start_key
357+
WHERE t.database_name = $1
358+
)
359+
SELECT
360+
array_agg(DISTINCT replica_val) AS replicas,
361+
array_agg(DISTINCT region_val) AS regions
362+
FROM replicasAndRegionsPerDbRange, unnest(replicas) AS replica_val, unnest(regions) AS region_val`,
363363
[new Identifier(dbName)],
364364
),
365365
arguments: [dbName],

0 commit comments

Comments
 (0)