* Gets the index sizes of indexes for shards located on the current node * for a given table and array of shard OIDs. */
| 329 | * for a given table and array of shard OIDs. |
| 330 | */ |
| 331 | static int64 |
| 332 | GetIndexSizesWorker(ArrayType *relationIds) |
| 333 | { |
| 334 | const char *query = |
| 335 | "SELECT pg_catalog.pg_relation_size(indexrelid)::int8 FROM pg_catalog.pg_index " |
| 336 | " WHERE indrelid = ANY ($1)"; |
| 337 | |
| 338 | int nargs = 1; |
| 339 | Oid argTypes[1] = { OIDARRAYOID }; |
| 340 | Datum argValues[1] = { PointerGetDatum(relationIds) }; |
| 341 | |
| 342 | bool readOnly = true; |
| 343 | SPI_connect(); |
| 344 | |
| 345 | Portal statsPortal = SPI_cursor_open_with_args("workerIndexSizeStats", query, nargs, |
| 346 | argTypes, argValues, |
| 347 | NULL, readOnly, 0); |
| 348 | bool hasData = true; |
| 349 | int64 indexesSize = 0; |
| 350 | while (hasData) |
| 351 | { |
| 352 | SPI_cursor_fetch(statsPortal, true, INT_MAX); |
| 353 | |
| 354 | hasData = SPI_processed >= 1; |
| 355 | if (!hasData) |
| 356 | { |
| 357 | break; |
| 358 | } |
| 359 | |
| 360 | if (SPI_tuptable) |
| 361 | { |
| 362 | for (int tupleNumber = 0; tupleNumber < (int) SPI_processed; tupleNumber++) |
| 363 | { |
| 364 | bool isNull; |
| 365 | AttrNumber sizeAttribute = 1; |
| 366 | Datum resultDatum = SPI_getbinval(SPI_tuptable->vals[tupleNumber], |
| 367 | SPI_tuptable->tupdesc, sizeAttribute, |
| 368 | &isNull); |
| 369 | if (isNull) |
| 370 | { |
| 371 | continue; |
| 372 | } |
| 373 | |
| 374 | indexesSize += DatumGetInt64(resultDatum); |
| 375 | } |
| 376 | } |
| 377 | else |
| 378 | { |
| 379 | ereport(ERROR, (errmsg( |
| 380 | "DbStats tuple table was null for index size stats."))); |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | SPI_cursor_close(statsPortal); |
| 385 | SPI_finish(); |
| 386 | |
| 387 | return indexesSize; |
| 388 | } |