From 69fe7fc37500244397f565f6c9d55d2fc2e5afe0 Mon Sep 17 00:00:00 2001 From: Georgy Shelkovy Date: Fri, 18 Oct 2024 12:42:27 +0500 Subject: [PATCH] optimize --- src/gp_activetable.c | 27 ++++++++++----------------- 1 file changed, 10 insertions(+), 17 deletions(-) diff --git a/src/gp_activetable.c b/src/gp_activetable.c index ea4c99e5..e133e40f 100644 --- a/src/gp_activetable.c +++ b/src/gp_activetable.c @@ -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); @@ -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); @@ -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; } @@ -937,7 +923,7 @@ 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; @@ -945,12 +931,19 @@ load_table_size(HTAB *local_table_stats_map, const char *sql, bool is_init) 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)