如果我在分区表上创建索引,则每个分区都有自己的索引。如果我删除主索引,这些不会被删除。
是否有捷径可寻?
我编写了一个函数来查找与顶级索引名称与分区后缀匹配的所有索引,并且对于在分区上创建的索引工作正常。
但是,当 Greenplum 通过默认分区拆分添加新分区时,它会为该分区生成一个具有完全不同命名约定的新索引。
现有分区的名称类似于 indexname_1_prt_partitionname
新分区的名称类似于 tablename_1_prt_partitionname_indexcolumn
知道当名称不匹配时如何识别新分区索引是父索引的一部分吗?或者我只是用两种不同的模式来匹配我的索引删除器两次?
我将使用下面的 Bell 查询,或者这个适合采用分区索引的查询(以防我们已经删除了头索引):
SELECT child_index.indexrelid::regclass
FROM pg_index AS partition_index
-- Find the partition that the partition index is on
INNER JOIN pg_partition_rule parindex_rule ON parindex_rule.parchildrelid = partition_index.indrelid
-- Follup up to the partitioning scheme
INNER JOIN pg_partition ON pg_partition.oid = parindex_rule.paroid
-- Follow the links through to the individual partitions
INNER JOIN pg_partition_rule ON pg_partition_rule.paroid = pg_partition.oid
-- Find the indexes on each partition
INNER JOIN pg_index AS child_index …
Run Code Online (Sandbox Code Playgroud) 据我所知,此查询应显示串行列的新值的表达式:
select d.adsrc
from (
SELECT a.attrelid, a.attnum, n.nspname, c.relname, a.attname
FROM pg_catalog.pg_attribute a, pg_namespace n, pg_class c
WHERE a.attnum > 0
AND NOT a.attisdropped
AND a.attrelid = c.oid
and c.relkind not in ('S','v')
and c.relnamespace = n.oid
and n.nspname not in ('pg_catalog','pg_toast','information_schema')
) x
left join pg_attrdef d on d.adrelid = x.attrelid and d.adnum = x.attnum
where x.relname = 'table_name' and x.nspname = 'schema_name' and x.attname = 'column_name'
;
Run Code Online (Sandbox Code Playgroud)
它大部分时间都有效,但如果我重命名序列,新名称不会反映在查询结果中 - 它继续显示序列的原始名称。任何想法为什么?
PostgreSQL 实现了execute ... using
将参数传递给动态 SQL的选项,据我所知,这个功能是在 8.4 版中引入的。我们使用的是Greenplum,它是从8.2 版的PostgreSQL 分叉出来的,所以它没有这个特性。
有没有其他方法可以在 Greenplum 或 PostgreSQL 8.2 中做同样的事情?