Skip to content

Commit

Permalink
fix: include missing schema name on queries
Browse files Browse the repository at this point in the history
  • Loading branch information
sigilioso committed Sep 16, 2024
1 parent 67a4a27 commit b7f9212
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
9 changes: 5 additions & 4 deletions src/metrics/index_definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ var indexDefinition = &QueryDefinition{
idx_tup_read AS tuples_read,
idx_tup_fetch AS tuples_fetched
FROM pg_tables t
LEFT OUTER JOIN pg_class c ON t.tablename=c.relname
LEFT OUTER JOIN
( SELECT c.relname AS ctablename, x.indexrelid indexoid, ipg.relname AS indexname, x.indnatts AS number_of_columns, idx_scan, idx_tup_read, idx_tup_fetch, indexrelname, indisunique FROM pg_index x
( SELECT c.relname AS ctablename, n.nspname AS cschemaname, x.indexrelid indexoid, ipg.relname AS indexname, x.indnatts AS number_of_columns, idx_scan, idx_tup_read, idx_tup_fetch, indexrelname, indisunique FROM pg_index x
JOIN pg_class c ON c.oid = x.indrelid
JOIN pg_namespace n ON c.relnamespace = n.oid
JOIN pg_class ipg ON ipg.oid = x.indexrelid
JOIN pg_stat_all_indexes psai ON x.indexrelid = psai.indexrelid )
JOIN pg_stat_all_indexes psai ON x.indexrelid = psai.indexrelid
)
AS foo
ON t.tablename = foo.ctablename
ON t.tablename = foo.ctablename AND t.schemaname = foo.cschemaname
where indexname is not null and t.schemaname || '.' || t.tablename || '.' || indexname in (%SCHEMA_TABLE_INDEXES%)
ORDER BY 1,2;`,

Expand Down
12 changes: 7 additions & 5 deletions src/metrics/table_definitions.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,13 @@ var tableDefinition = &QueryDefinition{
n_live_tup, -- table.liveRows
n_dead_tup -- table.deadRows
FROM pg_statio_user_tables as statio
join pg_stat_user_tables as stat
on stat.relid=statio.relid
join pg_class c
on c.relname=stat.relname
where stat.schemaname::text || '.' || stat.relname::text in (%SCHEMA_TABLES%)`,
JOIN pg_stat_user_tables as stat
ON stat.relid=statio.relid
JOIN pg_class c
ON c.relname=stat.relname
JOIN pg_namespace n
ON c.relnamespace = n.oid
WHERE n.nspname = stat.schemaname AND stat.schemaname::text || '.' || stat.relname::text in (%SCHEMA_TABLES%)`,

dataModels: []struct {
databaseBase
Expand Down

0 comments on commit b7f9212

Please sign in to comment.