Skip to content

Commit cf4c9d5

Browse files
committed
concurrent partitioning PL function rewrited
1 parent 00c8d9e commit cf4c9d5

File tree

1 file changed

+10
-38
lines changed

1 file changed

+10
-38
lines changed

init.sql

Lines changed: 10 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -134,36 +134,6 @@ CREATE OR REPLACE FUNCTION @extschema@.pathman_range_out(PathmanRange)
134134
AS 'pg_pathman'
135135
LANGUAGE C IMMUTABLE STRICT;
136136

137-
/*
138-
CREATE OR REPLACE FUNCTION @extschema@.get_whole_range(relid OID)
139-
RETURNS PathmanRange
140-
AS 'pg_pathman'
141-
LANGUAGE C STRICT;
142-
143-
CREATE OR REPLACE FUNCTION @extschema@.range_value_cmp(range PathmanRange, value ANYELEMENT)
144-
RETURNS INTEGER
145-
AS 'pg_pathman'
146-
LANGUAGE C STRICT;
147-
148-
CREATE OR REPLACE FUNCTION @extschema@.range_lower(range PathmanRange, dummy ANYELEMENT)
149-
RETURNS ANYELEMENT
150-
AS 'pg_pathman'
151-
LANGUAGE C;
152-
153-
CREATE OR REPLACE FUNCTION @extschema@.range_upper(range PathmanRange, dummy ANYELEMENT)
154-
RETURNS ANYELEMENT
155-
AS 'pg_pathman'
156-
LANGUAGE C;
157-
158-
CREATE OR REPLACE FUNCTION @extschema@.range_oid(range PathmanRange)
159-
RETURNS OID
160-
AS 'pg_pathman'
161-
LANGUAGE C STRICT;
162-
163-
CREATE OR REPLACE FUNCTION @extschema@.range_partitions_list(parent_relid OID)
164-
RETURNS SETOF PATHMANRANGE AS 'pg_pathman'
165-
LANGUAGE C STRICT;
166-
*/
167137
CREATE TYPE @extschema@.PathmanRange (
168138
internallength = 32,
169139
input = pathman_range_in,
@@ -185,12 +155,11 @@ DECLARE
185155
v_attr TEXT;
186156
v_limit_clause TEXT := '';
187157
v_where_clause TEXT := '';
158+
ctids TID[];
188159
BEGIN
189160
SELECT attname INTO v_attr
190161
FROM @extschema@.pathman_config WHERE partrel = p_relation;
191162

192-
PERFORM @extschema@.debug_capture();
193-
194163
p_total := 0;
195164

196165
/* Format LIMIT clause if needed */
@@ -216,14 +185,17 @@ BEGIN
216185

217186
/* Lock rows and copy data */
218187
RAISE NOTICE 'Copying data to partitions...';
188+
EXECUTE format('SELECT array(SELECT ctid FROM ONLY %1$s %2$s %3$s FOR UPDATE NOWAIT)',
189+
p_relation, v_where_clause, v_limit_clause)
190+
USING p_min, p_max
191+
INTO ctids;
192+
219193
EXECUTE format('
220194
WITH data AS (
221-
DELETE FROM ONLY %1$s WHERE ctid IN (
222-
SELECT ctid FROM ONLY %1$s %2$s %3$s FOR UPDATE NOWAIT
223-
) RETURNING *)
224-
INSERT INTO %1$s SELECT * FROM data'
225-
, p_relation, v_where_clause, v_limit_clause)
226-
USING p_min, p_max;
195+
DELETE FROM ONLY %1$s WHERE ctid = ANY($1) RETURNING *)
196+
INSERT INTO %1$s SELECT * FROM data',
197+
p_relation)
198+
USING ctids;
227199

228200
GET DIAGNOSTICS p_total = ROW_COUNT;
229201
RETURN;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy