Skip to content

Commit

Permalink
optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
RekGRpth committed Dec 20, 2024
1 parent 87b8e2e commit e5e7d28
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 22 deletions.
2 changes: 0 additions & 2 deletions src/diskquota.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "postgres.h"
#include "port/atomics.h"

#include "access/htup.h"
#include "catalog/pg_class.h"
#include "lib/ilist.h"
#include "lib/stringinfo.h"
Expand Down Expand Up @@ -322,5 +321,4 @@ extern HASHACTION check_hash_fullness(HTAB *hashp, int max_size, const char *war
TimestampTz *last_overflow_report);
bool SPI_connect_if_not_yet(void);
void SPI_finish_if(bool connected_in_this_function);
Datum SPI_getbinval_wrapper(HeapTuple tuple, TupleDesc tupdesc, const char *fname, bool allow_null, Oid typeid);
#endif
15 changes: 0 additions & 15 deletions src/diskquota_utility.c
Original file line number Diff line number Diff line change
Expand Up @@ -1714,18 +1714,3 @@ SPI_finish_if(bool connected_in_calling_function)
(errcode(ERRCODE_INTERNAL_ERROR), errmsg("[diskquota] SPI_finish failed"),
errdetail("%s", SPI_result_code_string(rc))));
}

Datum
SPI_getbinval_wrapper(HeapTuple tuple, TupleDesc tupdesc, const char *fname, bool allow_null, Oid typeid)
{
bool isnull;
Datum datum;
int fnumber = SPI_fnumber(tupdesc, fname);
if (SPI_gettypeid(tupdesc, fnumber) != typeid)
ereport(ERROR, (errcode(ERRCODE_MOST_SPECIFIC_TYPE_MISMATCH),
errmsg("type of column \"%s\" must be \"%i\"", fname, typeid)));
datum = SPI_getbinval(tuple, tupdesc, fnumber, &isnull);
if (isnull && !allow_null)
ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("column \"%s\" must not be null", fname)));
return datum;
}
39 changes: 34 additions & 5 deletions src/gp_activetable.c
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,30 @@ get_active_tables_oid(void)
return local_active_table_stats_map;
}

static int
SPI_fnumber_wrapper(TupleDesc tupdesc, const char *fname, Oid typeid)
{
int fnumber = SPI_fnumber(tupdesc, fname);

if (SPI_gettypeid(tupdesc, fnumber) != typeid)
ereport(ERROR, (errcode(ERRCODE_MOST_SPECIFIC_TYPE_MISMATCH),
errmsg("type of column \"%s\" must be \"%d\"", fname, typeid)));

return fnumber;
}

static Datum
SPI_getbinval_wrapper(HeapTuple tuple, TupleDesc tupdesc, int fnumber, bool allow_null)
{
bool isnull;
Datum datum = SPI_getbinval(tuple, tupdesc, fnumber, &isnull);

if (isnull && !allow_null)
ereport(ERROR, (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED), errmsg("column %d must not be null", fnumber)));

return datum;
}

/*
* Load table size info from diskquota.table_size table.
* This is called when system startup, disk quota rejectmap
Expand All @@ -936,13 +960,18 @@ load_table_size(StringInfoData *active_oids)
do
{
SPI_cursor_fetch(portal, true, 10000);

TupleDesc tupdesc = SPI_tuptable->tupdesc;
int tableid_num = SPI_fnumber_wrapper(tupdesc, "tableid", OIDOID);
int size_num = SPI_fnumber_wrapper(tupdesc, "size", INT8OID);
int segid_num = SPI_fnumber_wrapper(tupdesc, "segid", INT2OID);

for (uint64 row = 0; row < SPI_processed; row++)
{
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));
HeapTuple val = SPI_tuptable->vals[row];
Oid oid = DatumGetObjectId(SPI_getbinval_wrapper(val, tupdesc, tableid_num, false));
int64 size = DatumGetObjectId(SPI_getbinval_wrapper(val, tupdesc, size_num, false));
int16 segid = DatumGetObjectId(SPI_getbinval_wrapper(val, tupdesc, segid_num, false));

update_active_table_size(oid, size, segid);

Expand Down

0 comments on commit e5e7d28

Please sign in to comment.