【问题标题】:query partition table name for a specific value查询特定值的分区表名称
【发布时间】:2013-09-13 09:28:37
【问题描述】:

我已按timestamp with timezone 列对表进行了分区。然后我添加了一个分区,然后在该分区上添加了一个索引。现在看来,Greenplum onlyvacuum analyze TABLENAME 之后使用该索引。否则它使用顺序扫描。

vacuum analyze TABLENAME 的缺点是耗时较长。它想做一个vacuum analyze PARTITIONTABLENAME,因为我知道上个月的每日分区已经没有变化了。

问题是:如何获取特定值(如current_timestamp)的分区表名称?换句话说:我想访问 Greenplum 用来决定在哪个分区中放置新条目的函数。

【问题讨论】:

    标签: greenplum


    【解决方案1】:

    Greenplum 中的分区被视为与任何其他表一样。如果您有 psql 访问权限,您应该能够使用 '\d' 命令查看您在 search_path 中有权访问的所有表。较大表的每个分区都将显示在其中。除非你明确命名分区,greenplum 只会根据父表名和自动递增的分区号来命名它们:

    gpadmin=# create table testtab (testcol varchar(10),
    gpadmin(#  test_time timestamptz)
    gpadmin-# distributed by (testcol)
    gpadmin-#  partition by range (test_time)
    gpadmin-# ( START (date '2013-10-01') INCLUSIVE
    gpadmin(#   END  (date '2013-11-25') EXCLUSIVE
    gpadmin(# EVERY (INTERVAL '1 week'));
    NOTICE:  CREATE TABLE will create partition "testtab_1_prt_1" for table "testtab"
    NOTICE:  CREATE TABLE will create partition "testtab_1_prt_2" for table "testtab"
    NOTICE:  CREATE TABLE will create partition "testtab_1_prt_3" for table "testtab"
    NOTICE:  CREATE TABLE will create partition "testtab_1_prt_4" for table "testtab"
    NOTICE:  CREATE TABLE will create partition "testtab_1_prt_5" for table "testtab"
    NOTICE:  CREATE TABLE will create partition "testtab_1_prt_6" for table "testtab"
    NOTICE:  CREATE TABLE will create partition "testtab_1_prt_7" for table "testtab"
    NOTICE:  CREATE TABLE will create partition "testtab_1_prt_8" for table "testtab"
    CREATE TABLE
    Time: 252.080 ms
    gpadmin=#
    

    要仅清理最近的分区,您可以创建一个返回具有最高分区号的表的函数:

    gpadmin=# select tablename from pg_tables
    gpadmin-# where tablename like 'testtab_1_prt_%' 
    gpadmin-# order by tablename desc limit 1;
        tablename    
    -----------------
     testtab_1_prt_8
    (1 row)
    
    Time: 89.151 ms
    

    然后将其传递给真空分析。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2022-07-15
      • 2018-03-15
      • 1970-01-01
      • 1970-01-01
      • 2020-02-08
      • 1970-01-01
      • 1970-01-01
      • 2021-07-23
      相关资源
      最近更新 更多