If a partitioned table has global indexes, you can use global index scan in DML operations of DELETE and UPDATE.
Usage
- Create a partitioned table and a 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;
-
Use global index scan to perform the DELETE operation on specified data:
A similar output is displayed: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)
-
Use global index scan to perform the UPDATE operation on specified data:
A similar output is displayed: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)