cockroachdb / cockroach

CockroachDB — the cloud native, distributed SQL database designed for high availability, effortless scale, and control over data placement.
https://www.cockroachlabs.com
Other
30.11k stars 3.81k forks source link

sql: implement pg_stat tables where possible #70781

Open rafiss opened 3 years ago

rafiss commented 3 years ago

Add implementations for the following tables, for the columns that can be supported in CockroachDB

Jira issue: CRDB-10219

otan commented 1 year ago

reltuples in pg_class has a similar affliction. this prevent AWS DMS from providing "estimates" of progress.

example query:

2022-12-08 19:04:34 UTC:172.31.55.39(37296):postgres@replicationload:[666]:LOG:  statement: BEGIN;declare "SQL_CUR0x146ee0196860" cursor with hold for 
     ( 
      select
         t.schemaname                  as ownerName,
         t.tablename                   as tableName,
         /*c.oid*/ cast(c.oid as bigint) as objectId, 
         (select n_live_tup from pg_stat_user_tables s where s.schemaname=t.schemaname and s.relname=t.tablename)  as row_count,
           1                        as tableType
      from pg_tables t, pg_class c, pg_namespace n
      /*where clause number 1 (table where clause)*/
      where t.tablename=c.relname
      and   n.oid      = c.relnamespace
      and   t.schemaname = n.nspname
      and t.schemaname <> 'information_schema'
      and t.tablename  <> 'awsdms_ddl_audit'
      and t.tablename  <> 'awsdms_heartbeat'
      and
      (
         (( (1=0) ) -- Explicit Inclusion
         or 
         (
            ( 
     t.schemaname LIKE '%' and t.schemaname not like 'pg\_%' and t.tablename LIKE 'good\_table'
     ) -- Patterned Inclusion
              and not
            ( 
     t.schemaname LIKE '%' and t.schemaname not like 'pg\_%' and t.tablename LIKE 'awsdms\_changes%'
     or 
     t.schemaname LIKE '%' and t.schemaname not like 'pg\_%' and t.tablename LIKE 'awsdms\_apply%'
     or 
     t.schemaname LIKE '%' and t.schemaname not like 'pg\_%' and t.tablename LIKE 'awsdms\_truncation%'
     or 
     t.schemaname LIKE '%' and t.schemaname not like 'pg\_%' and t.tablename LIKE 'awsdms\_audit\_table'
     or 
     t.schemaname LIKE '%' and t.schemaname not like 'pg\_%' and t.tablename LIKE 'awsdms\_status'
     or 
     t.schemaname LIKE '%' and t.schemaname not like 'pg\_%' and t.tablename LIKE 'awsdms\_suspended\_tables'
     or 
     t.schemaname LIKE '%' and t.schemaname not like 'pg\_%' and t.tablename LIKE 'awsdms\_history'
     or 
     t.schemaname LIKE '%' and t.schemaname not like 'pg\_%' and t.tablename LIKE 'awsdms\_validation\_failure'
     or 
     t.schemaname LIKE '%' and t.schemaname not like 'pg\_%' and t.tablename LIKE 'awsdms\_cdc\_%awsdms\_full\_load\_exceptions%'
     ) -- Patterned exclusion
          ))
          and 
          (1=1) 
      )

      UNION

      select
         v.schemaname                  as ownerName,
         v.viewname                   as tableName,
         /*c.oid*/ cast(c.oid as bigint) as objectId, 
         0  as row_count,/**/ 
           2                        as tableType
      from pg_views v, pg_class c, pg_namespace n
      /*where clause number 2 (view where clause)*/ 
      where v.viewname = c.relname
      and   n.oid       = c.relnamespace
      and   v.schemaname = n.nspname
      and v.schemaname <> 'information_schema'
      and v.viewname  <> 'awsdms_ddl_audit'
      and v.viewname  <> 'awsdms_heartbeat'
      and
      (
         (( (1=0) ) -- Explicit Inclusion
         or 
         (
            ( (1=0) ) -- Patterned Inclusion
              and not
            ( (1=0) ) -- Patterned exclusion
          ))
          and 
          (1=1) 
      )
     )
     order by 1,2
    ;fetch 10000 in "SQL_CUR0x146ee0196860"