Skip to content

Commit 79d4847

Browse files
committed
Fix values[] assignment order in yb_tablet_metadata_sizes
1 parent 2eb26ed commit 79d4847

File tree

1 file changed

+17
-21
lines changed

1 file changed

+17
-21
lines changed

src/postgres/src/backend/utils/misc/pg_yb_utils.c

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -8578,11 +8578,23 @@ yb_get_tablet_metadata(PG_FUNCTION_ARGS)
85788578
/* The last replica is the leader. */
85798579
values[7] = CStringGetTextDatum(tablet->replicas[nreplicas - 1]);
85808580

8581-
/*
8582-
* Build JSONB attributes before sorting replicas, because the
8583-
* parallel size arrays must stay aligned with the replica order.
8584-
* JSONB does not preserve key order so sorting is unnecessary.
8585-
*/
8581+
/* Convert char ** to List * */
8582+
{
8583+
List *replicas_list = NIL;
8584+
8585+
for (size_t idx = 0; idx < nreplicas; idx++)
8586+
replicas_list = lappend(replicas_list,
8587+
(char *) tablet->replicas[idx]);
8588+
8589+
/*
8590+
* Sort the list lexicographically for consistency, so that
8591+
* all rows with same replicas have same entries.
8592+
*/
8593+
list_sort(replicas_list, string_list_compare);
8594+
values[8] = PointerGetDatum(strlist_to_textarray(replicas_list));
8595+
}
8596+
8597+
/* Build JSONB attributes with per-replica size metrics. */
85868598
{
85878599
JsonbParseState *jb_state = NULL;
85888600
JsonbValue jb_result;
@@ -8644,22 +8656,6 @@ yb_get_tablet_metadata(PG_FUNCTION_ARGS)
86448656

86458657
values[9] = JsonbPGetDatum(JsonbValueToJsonb(&jb_result));
86468658
}
8647-
8648-
/* Convert char ** to List * */
8649-
{
8650-
List *replicas_list = NIL;
8651-
8652-
for (size_t idx = 0; idx < nreplicas; idx++)
8653-
replicas_list = lappend(replicas_list,
8654-
(char *) tablet->replicas[idx]);
8655-
8656-
/*
8657-
* Sort the list lexicographically for consistency, so that
8658-
* all rows with same replicas have same entries.
8659-
*/
8660-
list_sort(replicas_list, string_list_compare);
8661-
values[8] = PointerGetDatum(strlist_to_textarray(replicas_list));
8662-
}
86638659
}
86648660
else
86658661
{

0 commit comments

Comments
 (0)