Skip to content

Commit

Permalink
[BACKPORT pg15-cherrypicks][#23706] YSQL: Add table-level catcache Pr…
Browse files Browse the repository at this point in the history
…ometheus metrics

Summary:
Original commit: 9889df7 / D37633

PG15 removes the YB pinned objects in bea1ffb. YB master 9889df7 conflicts with this (false conflict, we keep the PG15 code here).

There is also the following logical conflict:

PG15 adds 6 new catcaches:
  - 2 on pg_parameter_acl
  - 2 on pg_publication_namespace
  - 1 on pg_range
  - 1 on pg_statistic_ext_data
Of these, pg_parameter_acl, pg_publication_namespace, and pg_statistic_ext_data are new catalog tables introduced in pg15.

Adjust catalog cache metrics to account for new catalog tables/caches introduced in pg15, adapt according to YB pg15 merge 602cb2d.

 - src/postgres/src/backend/utils/cache/syscache.h:
    - enum YbCatalogCacheTable:
        - YB master 9889df7 adds this enum representing the catalog tables that have catcaches.
        - PG15 adds three new catalog tables.
        - Resolution: add the three new catalog tables to this enum.

 - src/postgres/src/backend/utils/cache/syscache.c:
    - `static const char *yb_cache_table_name_table` / `static YbCatalogCacheTable yb_catalog_cache_tables`:
        - YB master 9889df7 adds this list of all the PG catalog tables there are catcaches for.
        - PG15 adds three new catalog tables and six new catcaches.
        - Resolution: add the six entries corresponding to the new catcaches to these lists.

 - src/postgres/yb-extensions/yb_pg_metrics/yb_pg_metrics.c:
    - enum statementType:
        - YB master 9889df7 adds one CatCacheTableMisses entry per table that has a catcache (total 47 entries).
        - PG15 adds three new catalog tables.
        - Resolution: add the three new CatCacheTableMisses entries corresponding to the new catcaches to this enum (total 50 entries).

 - src/yb/yql/pgwrapper/pg_libpq-test.cc:
    - GetCatalogTableNameFromIndexName:
        - YB master commit 9889df7 adds a test that has a list of all the PG catalog tables.
        - PG15 adds three new catalog tables.
        - Resolution: add the three new catalog tables to this list.

Conflict is related to c271944.
 - `src/postgres/yb-extensions/yb_pg_metrics/yb_pg_metrics.c`:
    - In c271944, are correcting the `enum statementType`'s `CatCacheIdMisses` section so that the end-of-section market points to the last enum in the section rather than being its own enum after the end of the section. In this revision, we are adding a new section, `CatCacheTableMisses`, to `enum statementType`, so the changes are unrelated. We make sure, however, that the end-of-section marker here points to the last enum in the section to avoid the issue addressed in c271944.

Adds table-level Prometheus metrics for the number of catcache misses in addition to the current index-level ones added in D35792.

These metrics are node-level, i.e. they will include the cache misses from all backends running on this node, but not the other nodes. They accessible via the `:13000/prometheus-metrics` endpoint.
Including the metrics added in this revision, we now have three YSQL metrics that track catalog cache misses:

  - `CatalogCacheMisses` (no `table_name` field): Total number of cache misses across all catcaches.
  - `CatalogCacheMisses` (`table_name` field specified): Number of cache misses for the index specified by `table_name`.
  - `CatalogCacheTableMisses` (**new**): Number of cache misses for all catcaches on the table specified by `table_name`.
Jira: DB-12616

Test Plan:
```
./yb_build.sh --cxx-test pgwrapper_pg_libpq-test --gtest_filter PgLibPqTest.CatalogCacheIdMissMetricsTest
```

Manual test:
```
bin/yb-ctl create

bin/ysqlsh
yugabyte=# create table test(a int);
CREATE TABLE
yugabyte=# \c
You are now connected to database "yugabyte" as user "yugabyte".
yugabyte=# select * from t;
 a
---
(0 rows)

yugabyte=# \q
wget 'http://127.0.0.1:13000/prometheus-metrics?reset_histograms=false&show_help=false' -O - 2>/dev/null | grep CatalogCacheTableMisses | grep count
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_aggregate",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_am",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_amop",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_amproc",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_attribute",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_auth_members",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_authid",exported_instance="kf-mbp-v47vl:9000"} 2 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_cast",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_class",exported_instance="kf-mbp-v47vl:9000"} 3 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_collation",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_constraint",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_conversion",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_database",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_default_acl",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_enum",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_event_trigger",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_foreign_data_wrapper",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_foreign_server",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_foreign_table",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_index",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_language",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_namespace",exported_instance="kf-mbp-v47vl:9000"} 2 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_opclass",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_operator",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_opfamily",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_partitioned_table",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_proc",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_publication",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_publication_rel",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_range",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_replication_origin",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_rewrite",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_sequence",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_statistic",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_statistic_ext",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_subscription",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_subscription_rel",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_tablespace",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_transform",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_ts_config",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_ts_config_map",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_ts_dict",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_ts_parser",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_ts_template",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_type",exported_instance="kf-mbp-v47vl:9000"} 1 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_user_mapping",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
handler_latency_yb_ysqlserver_SQLProcessor_CatalogCacheTableMisses_count{metric_id="yb.ysqlserver",metric_type="server",table_name="pg_yb_tablegroup",exported_instance="kf-mbp-v47vl:9000"} 0 1724889458674
```

Reviewers: jason, tfoucher

Reviewed By: jason

Subscribers: yql

Differential Revision: https://phorge.dev.yugabyte.com/D37871
  • Loading branch information
kai-franz committed Sep 11, 2024
1 parent 5ad3f27 commit 6d22317
Show file tree
Hide file tree
Showing 9 changed files with 570 additions and 106 deletions.
8 changes: 8 additions & 0 deletions src/postgres/src/backend/utils/cache/catcache.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
static CatCacheHeader *CacheHdr = NULL;
static long YbNumCatalogCacheMisses;
static long YbNumCatalogCacheIdMisses[SysCacheSize] = {0};
static long YbNumCatalogCacheTableMisses[YbNumCatalogCacheTables] = {0};

static inline HeapTuple SearchCatCacheInternal(CatCache *cache,
int nkeys,
Expand Down Expand Up @@ -1806,6 +1807,7 @@ SearchCatCacheMiss(CatCache *cache,
{
YbNumCatalogCacheMisses++;
YbNumCatalogCacheIdMisses[cache->id]++;
YbNumCatalogCacheTableMisses[YbGetCatalogCacheTableIdFromCacheId(cache->id)]++;
}

if (yb_debug_log_catcache_events)
Expand Down Expand Up @@ -2658,6 +2660,12 @@ YbGetCatCacheIdMisses()
return YbNumCatalogCacheIdMisses;
}

long *
YbGetCatCacheTableMisses()
{
return YbNumCatalogCacheTableMisses;
}

YbCatCListIterator
YbCatCListIteratorBegin(CatCList *list)
{
Expand Down
187 changes: 187 additions & 0 deletions src/postgres/src/backend/utils/cache/syscache.c
Original file line number Diff line number Diff line change
Expand Up @@ -1170,6 +1170,158 @@ static const char *yb_cache_index_name_table[] = {
static_assert(SysCacheSize == sizeof(yb_cache_index_name_table) /
sizeof(const char *), "Wrong catalog cache number");

/* List of all the tables that have caches on them */
static const char *yb_cache_table_name_table[] = {
"pg_aggregate",
"pg_am",
"pg_amop",
"pg_amproc",
"pg_attribute",
"pg_auth_members",
"pg_authid",
"pg_cast",
"pg_class",
"pg_collation",
"pg_constraint",
"pg_conversion",
"pg_database",
"pg_default_acl",
"pg_enum",
"pg_event_trigger",
"pg_foreign_data_wrapper",
"pg_foreign_server",
"pg_foreign_table",
"pg_index",
"pg_language",
"pg_namespace",
"pg_opclass",
"pg_operator",
"pg_opfamily",
"pg_parameter_acl",
"pg_partitioned_table",
"pg_proc",
"pg_publication",
"pg_publication_namespace",
"pg_publication_rel",
"pg_range",
"pg_replication_origin",
"pg_rewrite",
"pg_sequence",
"pg_statistic",
"pg_statistic_ext",
"pg_statistic_ext_data",
"pg_subscription",
"pg_subscription_rel",
"pg_tablespace",
"pg_transform",
"pg_ts_config",
"pg_ts_config_map",
"pg_ts_dict",
"pg_ts_parser",
"pg_ts_template",
"pg_type",
"pg_user_mapping",
"pg_yb_tablegroup",
};

static_assert(YbNumCatalogCacheTables ==
sizeof(yb_cache_table_name_table) / sizeof(const char *),
"yb_catalog_cache_table_name_table size mismatch");


/* Maps cache id to the table id in yb_cache_table_name_table */
static YbCatalogCacheTable yb_catalog_cache_tables[] = {
YbCatalogCacheTable_pg_aggregate,
YbCatalogCacheTable_pg_am,
YbCatalogCacheTable_pg_am,
YbCatalogCacheTable_pg_amop,
YbCatalogCacheTable_pg_amop,
YbCatalogCacheTable_pg_amproc,
YbCatalogCacheTable_pg_attribute,
YbCatalogCacheTable_pg_attribute,
YbCatalogCacheTable_pg_auth_members,
YbCatalogCacheTable_pg_auth_members,
YbCatalogCacheTable_pg_authid,
YbCatalogCacheTable_pg_authid,
YbCatalogCacheTable_pg_cast,
YbCatalogCacheTable_pg_opclass,
YbCatalogCacheTable_pg_opclass,
YbCatalogCacheTable_pg_collation,
YbCatalogCacheTable_pg_collation,
YbCatalogCacheTable_pg_conversion,
YbCatalogCacheTable_pg_conversion,
YbCatalogCacheTable_pg_constraint,
YbCatalogCacheTable_pg_conversion,
YbCatalogCacheTable_pg_database,
YbCatalogCacheTable_pg_default_acl,
YbCatalogCacheTable_pg_enum,
YbCatalogCacheTable_pg_enum,
YbCatalogCacheTable_pg_event_trigger,
YbCatalogCacheTable_pg_event_trigger,
YbCatalogCacheTable_pg_foreign_data_wrapper,
YbCatalogCacheTable_pg_foreign_data_wrapper,
YbCatalogCacheTable_pg_foreign_server,
YbCatalogCacheTable_pg_foreign_server,
YbCatalogCacheTable_pg_foreign_table,
YbCatalogCacheTable_pg_index,
YbCatalogCacheTable_pg_language,
YbCatalogCacheTable_pg_language,
YbCatalogCacheTable_pg_namespace,
YbCatalogCacheTable_pg_namespace,
YbCatalogCacheTable_pg_operator,
YbCatalogCacheTable_pg_operator,
YbCatalogCacheTable_pg_opfamily,
YbCatalogCacheTable_pg_opfamily,
YbCatalogCacheTable_pg_parameter_acl,
YbCatalogCacheTable_pg_parameter_acl,
YbCatalogCacheTable_pg_partitioned_table,
YbCatalogCacheTable_pg_proc,
YbCatalogCacheTable_pg_proc,
YbCatalogCacheTable_pg_publication,
YbCatalogCacheTable_pg_publication_namespace,
YbCatalogCacheTable_pg_publication_namespace,
YbCatalogCacheTable_pg_publication,
YbCatalogCacheTable_pg_publication_rel,
YbCatalogCacheTable_pg_publication_rel,
YbCatalogCacheTable_pg_range,
YbCatalogCacheTable_pg_range,
YbCatalogCacheTable_pg_class,
YbCatalogCacheTable_pg_class,
YbCatalogCacheTable_pg_replication_origin,
YbCatalogCacheTable_pg_replication_origin,
YbCatalogCacheTable_pg_rewrite,
YbCatalogCacheTable_pg_sequence,
YbCatalogCacheTable_pg_statistic_ext_data,
YbCatalogCacheTable_pg_statistic_ext,
YbCatalogCacheTable_pg_statistic_ext,
YbCatalogCacheTable_pg_statistic,
YbCatalogCacheTable_pg_subscription,
YbCatalogCacheTable_pg_subscription,
YbCatalogCacheTable_pg_subscription_rel,
YbCatalogCacheTable_pg_tablespace,
YbCatalogCacheTable_pg_transform,
YbCatalogCacheTable_pg_transform,
YbCatalogCacheTable_pg_ts_config_map,
YbCatalogCacheTable_pg_ts_config,
YbCatalogCacheTable_pg_ts_config,
YbCatalogCacheTable_pg_ts_dict,
YbCatalogCacheTable_pg_ts_dict,
YbCatalogCacheTable_pg_ts_parser,
YbCatalogCacheTable_pg_ts_parser,
YbCatalogCacheTable_pg_ts_template,
YbCatalogCacheTable_pg_ts_template,
YbCatalogCacheTable_pg_type,
YbCatalogCacheTable_pg_type,
YbCatalogCacheTable_pg_user_mapping,
YbCatalogCacheTable_pg_user_mapping,
YbCatalogCacheTable_pg_yb_tablegroup,
YbCatalogCacheTable_pg_constraint,
};

static_assert(SysCacheSize ==
sizeof(yb_catalog_cache_tables) / sizeof(YbCatalogCacheTable),
"yb_catalog_cache_tables size mismatch");

static CatCache *SysCache[SysCacheSize];

static bool CacheInitialized = false;
Expand Down Expand Up @@ -1992,6 +2144,20 @@ YbCheckCatalogCacheIndexNameTable()
return false;
}
ReleaseSysCache(tuple);

const char *table_name = YbGetCatalogCacheTableNameFromCacheId(cache_id);
Oid reloid = cacheinfo[cache_id].reloid;
tuple = SearchSysCache1(RELOID, reloid);
Assert(HeapTupleIsValid(tuple));
classForm = (Form_pg_class) GETSTRUCT(tuple);
if (strcmp(NameStr(classForm->relname), table_name))
{
ReleaseSysCache(tuple);
YBC_LOG_WARNING("Cache id %u has name mismatch: %s vs %s", cache_id,
NameStr(classForm->relname), table_name);
return false;
}
ReleaseSysCache(tuple);
}
return true;
}
Expand All @@ -2001,3 +2167,24 @@ const char* YbGetCatalogCacheIndexName(int cache_id)
{
return yb_cache_index_name_table[cache_id];
}

const char *
YbGetCatalogCacheTableNameFromTableId(int table_id)
{
Assert(table_id >= 0 && table_id < YbNumCatalogCacheTables);
return yb_cache_table_name_table[table_id];
}

int
YbGetCatalogCacheTableIdFromCacheId(int cache_id)
{
int table_id = yb_catalog_cache_tables[cache_id];
Assert(table_id >= 0 && table_id < YbNumCatalogCacheTables);
return table_id;
}

const char *
YbGetCatalogCacheTableNameFromCacheId(int cache_id)
{
return YbGetCatalogCacheTableNameFromTableId(YbGetCatalogCacheTableIdFromCacheId(cache_id));
}
1 change: 1 addition & 0 deletions src/postgres/src/include/utils/catcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ extern void SetCatCacheList(CatCache *cache, int nkeys, List *fnlist);
extern bool RelationHasCachedLists(Relation relation);
extern long YbGetCatCacheMisses();
extern long* YbGetCatCacheIdMisses();
extern long *YbGetCatCacheTableMisses();

extern YbCatCListIterator YbCatCListIteratorBegin(CatCList *list);
extern HeapTuple YbCatCListIteratorGetNext(YbCatCListIterator *iterator);
Expand Down
1 change: 1 addition & 0 deletions src/postgres/src/include/utils/lsyscache.h
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

/*-------------------------------------------------------------------------
*
* lsyscache.h
Expand Down
59 changes: 59 additions & 0 deletions src/postgres/src/include/utils/syscache.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,72 @@ enum SysCacheIdentifier
#define SysCacheSize (YBCONSTRAINTRELIDTYPIDNAME + 1)
};

typedef enum YbCatalogCacheTable
{
YbCatalogCacheTable_pg_aggregate,
YbCatalogCacheTable_pg_am,
YbCatalogCacheTable_pg_amop,
YbCatalogCacheTable_pg_amproc,
YbCatalogCacheTable_pg_attribute,
YbCatalogCacheTable_pg_auth_members,
YbCatalogCacheTable_pg_authid,
YbCatalogCacheTable_pg_cast,
YbCatalogCacheTable_pg_class,
YbCatalogCacheTable_pg_collation,
YbCatalogCacheTable_pg_constraint,
YbCatalogCacheTable_pg_conversion,
YbCatalogCacheTable_pg_database,
YbCatalogCacheTable_pg_default_acl,
YbCatalogCacheTable_pg_enum,
YbCatalogCacheTable_pg_event_trigger,
YbCatalogCacheTable_pg_foreign_data_wrapper,
YbCatalogCacheTable_pg_foreign_server,
YbCatalogCacheTable_pg_foreign_table,
YbCatalogCacheTable_pg_index,
YbCatalogCacheTable_pg_language,
YbCatalogCacheTable_pg_namespace,
YbCatalogCacheTable_pg_opclass,
YbCatalogCacheTable_pg_operator,
YbCatalogCacheTable_pg_opfamily,
YbCatalogCacheTable_pg_parameter_acl,
YbCatalogCacheTable_pg_partitioned_table,
YbCatalogCacheTable_pg_proc,
YbCatalogCacheTable_pg_publication,
YbCatalogCacheTable_pg_publication_namespace,
YbCatalogCacheTable_pg_publication_rel,
YbCatalogCacheTable_pg_range,
YbCatalogCacheTable_pg_replication_origin,
YbCatalogCacheTable_pg_rewrite,
YbCatalogCacheTable_pg_sequence,
YbCatalogCacheTable_pg_statistic,
YbCatalogCacheTable_pg_statistic_ext,
YbCatalogCacheTable_pg_statistic_ext_data,
YbCatalogCacheTable_pg_subscription,
YbCatalogCacheTable_pg_subscription_rel,
YbCatalogCacheTable_pg_tablespace,
YbCatalogCacheTable_pg_transform,
YbCatalogCacheTable_pg_ts_config,
YbCatalogCacheTable_pg_ts_config_map,
YbCatalogCacheTable_pg_ts_dict,
YbCatalogCacheTable_pg_ts_parser,
YbCatalogCacheTable_pg_ts_template,
YbCatalogCacheTable_pg_type,
YbCatalogCacheTable_pg_user_mapping,
YbCatalogCacheTable_pg_yb_tablegroup

#define YbNumCatalogCacheTables (YbCatalogCacheTable_pg_yb_tablegroup + 1)
} YbCatalogCacheTable;

/* Used in IsYugaByteEnabled() mode only */
extern void YbSetSysCacheTuple(Relation rel, HeapTuple tup);
extern void YbPreloadCatalogCache(int cache_id, int idx_cache_id);
#ifndef NDEBUG
extern bool YbCheckCatalogCacheIndexNameTable();
#endif
extern const char* YbGetCatalogCacheIndexName(int cache_id);
extern const char *YbGetCatalogCacheTableNameFromTableId(int table_id);
extern const char *YbGetCatalogCacheTableNameFromCacheId(int cache_id);
extern int YbGetCatalogCacheTableIdFromCacheId(int cache_id);

extern void InitCatalogCache(void);
extern void InitCatalogCachePhase2(void);
Expand Down
Loading

0 comments on commit 6d22317

Please sign in to comment.