프로그램밍

Vertica table row count

fingertree 2023. 1. 25. 17:03

Vertica 테이블 건수 조회 

-- 전체 테이블 건수 
with num_rows as (
    select schema_name,
           anchor_table_name as table_name,
           sum(total_row_count) as rows
    from v_monitor.storage_containers sc
    join v_catalog.projections p
         on sc.projection_id = p.projection_id
         and p.is_super_projection = true
         and schema_name = 'DW'   -- 포함 스키마 
         and (anchor_table_name like 'DG%' or   -- 포함 테이블  
              anchor_table_name like 'GC%' or
              anchor_table_name like 'HC%' or
              anchor_table_name like 'MR%' or
              anchor_table_name like 'PI%' or 
              anchor_table_name like 'PI%' or
              anchor_table_name like 'RG%')
    group by schema_name,
             table_name,
             sc.projection_id
)
select schema_name,
       table_name,
       max(rows) as rows
from num_rows
where table_name not like '%LDNG' and table_name not like '%INIT'  -- 제외 테이블 
group by schema_name,
         table_name
order by rows desc;