Skip to content

Commit

Permalink
optimize
Browse files Browse the repository at this point in the history
  • Loading branch information
RekGRpth committed Oct 18, 2024
1 parent e14a616 commit 69fe7fc
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions src/gp_activetable.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ static void object_access_hook_QuotaStmt(ObjectAccessType access, Oid classId, O
static HTAB *get_active_tables_stats(ArrayType *array);
static HTAB *get_active_tables_oid(void);
static char *pull_active_list_from_seg(void);
static void load_table_size(HTAB *local_table_stats_map, const char *sql, bool is_init);
static void load_table_size(HTAB *local_table_stats_map, bool is_init);
static void report_active_table_helper(const RelFileNodeBackend *relFileNode);
static void remove_from_active_table_map(const RelFileNodeBackend *relFileNode);
static void report_relation_cache_helper(Oid relid);
Expand Down Expand Up @@ -366,7 +366,6 @@ gp_fetch_active_tables(bool is_init)
{
HTAB *local_table_stats_map = NULL;
HASHCTL ctl;
char *sql_command;

Assert(Gp_role == GP_ROLE_DISPATCH);

Expand All @@ -378,21 +377,8 @@ gp_fetch_active_tables(bool is_init)
local_table_stats_map = diskquota_hash_create("local active table map with relfilenode info", 1024, &ctl,
HASH_ELEM | HASH_CONTEXT, DISKQUOTA_OID_HASH);

if (is_init)
{
load_table_size(local_table_stats_map, "select tableid, array_agg(size order by segid) size from diskquota.table_size group by 1 order by 1", is_init);
}
else
{
/* step 1: fetch active oids from all the segments */
sql_command = pull_active_list_from_seg();

/* step 2: fetch active table sizes based on active oids */
load_table_size(local_table_stats_map, is_init);

load_table_size(local_table_stats_map, sql_command, is_init);

pfree(sql_command);
}
return local_table_stats_map;
}

Expand Down Expand Up @@ -937,20 +923,27 @@ get_active_tables_oid(void)
* and other shared memory will be warmed up by table_size table.
*/
static void
load_table_size(HTAB *local_table_stats_map, const char *sql, bool is_init)
load_table_size(HTAB *local_table_stats_map, bool is_init)
{
TupleDesc tupdesc;
int i;
bool found;
ActiveTableEntryCombined *quota_entry;
SPIPlanPtr plan;
Portal portal;
char *sql = "select tableid, array_agg(size order by segid) size from diskquota.table_size group by 1 order by 1";

if (!is_init)
sql = pull_active_list_from_seg();

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)
ereport(ERROR, (errmsg("[diskquota] SPI_cursor_open(\"%s\") failed", sql)));

if (!is_init)
pfree(sql);

SPI_cursor_fetch(portal, true, 1000);

if (SPI_tuptable == NULL)
Expand Down

0 comments on commit 69fe7fc

Please sign in to comment.