当分区表中存在GLOBAL INDEX时,可以使用GLOBAL INDEX SCAN进行DML(DELETE、UPDATE)操作。
使用指南
- 创建分区表和全局索引(GLOBAL INDEX):
CREATE TABLE gi_ora ( a int, b int, c int GENERATED ALWAYS AS (b * 2), d int DEFAULT 0, e int, f text, g text ) PARTITION BY RANGE (a) ( partition p0 values less than (50), partition p1 values less than (100), partition p2 values less than (200), partition p3 values less than (300), partition p4 values less than (400), partition p5 values less than (500), partition p6 values less than (600), partition p7 values less than (700), partition p8 values less than (800) ); INSERT INTO gi_ora(a,b,d,e,f,g) SELECT i,i,i, (random()*1000)::int,(random()*30000000)::int::text,(random()*30000000)::int::text FROM generate_series(1,799) i ; CREATE INDEX ON gi_ora(b) global; ANALYZE gi_ora;
-
使用GLOBAL INDEX SCAN对指定数据进行删除操作:
显示结果如下:EXPLAIN (costs off, verbose on) DELETE FROM gi_ora WHERE b = 198;
QUERY PLAN ---------------------------------------------------------------------------- DELETE ON global_index_dml.gi_ora -> GLOBAL INDEX SCAN USING gi_ora_global_idx ON global_index_dml.gi_ora Output: gi_ora.tableoid, gi_ora.ctid Index Cond: (gi_ora.b = 198) (4 rows)
-
使用GLOBAL INDEX SCAN对指定数据进行更新操作:
显示结果如下:EXPLAIN (costs off, verbose on) UPDATE gi_ora SET a = a - 10 WHERE b = 198;
QUERY PLAN ---------------------------------------------------------------------------- UPDATE ON global_index_dml.gi_ora -> GLOBAL INDEX SCAN USING gi_ora_global_idx ON global_index_dml.gi_ora Output: (gi_ora.a - 10), gi_ora.tableoid, gi_ora.ctid Index Cond: (gi_ora.b = 198) (4 rows)