Skip to content

Commit

Permalink
optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
RekGRpth committed Dec 17, 2024
1 parent 5031028 commit c0346cb
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions src/gp_activetable.c
Original file line number Diff line number Diff line change
Expand Up @@ -923,16 +923,11 @@ load_table_size(StringInfoData *active_oids)
{
SPIPlanPtr plan;
Portal portal;
int16 typlen;
bool typbyval;
char typalign;

static const char *sql = "select tableid, array_agg(size order by segid) size from diskquota.table_size group by 1";
static const char *sql = "select tableid, size, segid from diskquota.table_size";

bool connected_in_this_function = SPI_connect_if_not_yet();

get_typlenbyvalalign(INT8OID, &typlen, &typbyval, &typalign);

if ((plan = SPI_prepare(sql, 0, NULL)) == NULL)
ereport(ERROR, (errmsg("[diskquota] SPI_prepare(\"%s\") failed", sql)));
if ((portal = SPI_cursor_open(NULL, plan, NULL, NULL, true)) == NULL)
Expand All @@ -943,20 +938,19 @@ load_table_size(StringInfoData *active_oids)
SPI_cursor_fetch(portal, true, 10000);
for (uint64 row = 0; row < SPI_processed; row++)
{
HeapTuple val = SPI_tuptable->vals[row];
TupleDesc tupdesc = SPI_tuptable->tupdesc;
Oid tableid = DatumGetObjectId(SPI_getbinval_wrapper(val, tupdesc, "tableid", false, OIDOID));
ArrayType *array =
DatumGetArrayTypePwrapper(SPI_getbinval_wrapper(val, tupdesc, "size", false, INT8ARRAYOID));
Datum *sizes;
int nelems;
if (active_oids->len > 0) appendStringInfoString(active_oids, ",");
appendStringInfo(active_oids, "%d", tableid);
deconstruct_array(array, ARR_ELEMTYPE(array), typlen, typbyval, typalign, &sizes, NULL, &nelems);
Assert(nelems == SEGCOUNT + 1);
for (int16 segid = -1; segid < SEGCOUNT; segid++)
update_active_table_size(tableid, DatumGetInt64(sizes[segid + 1]), segid);
pfree(sizes);
HeapTuple val = SPI_tuptable->vals[row];
TupleDesc tupdesc = SPI_tuptable->tupdesc;
Oid oid = DatumGetObjectId(SPI_getbinval_wrapper(val, tupdesc, "tableid", false, OIDOID));
int64 size = DatumGetObjectId(SPI_getbinval_wrapper(val, tupdesc, "size", false, INT8OID));
int16 segid = DatumGetObjectId(SPI_getbinval_wrapper(val, tupdesc, "segid", false, INT2OID));

update_active_table_size(oid, size, segid);

if (segid == -1)
{
if (active_oids->len > 0) appendStringInfoString(active_oids, ",");
appendStringInfo(active_oids, "%d", oid);
}
}
SPI_freetuptable(SPI_tuptable);
} while (SPI_processed);
Expand Down

0 comments on commit c0346cb

Please sign in to comment.