Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit8f87c53

Browse files
committed
Rewrite all mixed-sign comparisons, rewrite some plpgsql functions to C (append_partitions_on_demand, get_range_condition, is_date_type, is_attribute_nullable, get_attribute_type_name), introduce 'delayed invalidation' list & finish_delayed_invalidation() function, group functions in utils.h
1 parent4d8e430 commit8f87c53

20 files changed

+939
-666
lines changed

‎hash.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,8 @@ BEGIN
6868

6969
RETURN partitions_count;
7070
END
71-
$$ LANGUAGE plpgsql;
71+
$$ LANGUAGE plpgsql
72+
SET client_min_messages= WARNING;
7273

7374
/*
7475
* Creates an update trigger

‎init.sql

Lines changed: 115 additions & 130 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/* ------------------------------------------------------------------------
22
*
33
* init.sql
4-
*Creates config table and provides common utility functions
4+
*Creates config table and provides common utility functions
55
*
66
* Copyright (c) 2015-2016, Postgres Professional
77
*
@@ -27,57 +27,9 @@ CREATE TABLE IF NOT EXISTS @extschema@.pathman_config (
2727
CHECK (parttype>=1OR parttype<=2)/* check for allowed part types*/
2828
);
2929

30-
SELECTpg_catalog.pg_extension_config_dump('@extschema@.pathman_config','');
31-
32-
CREATEOR REPLACE FUNCTION @extschema@.on_create_partitions(relidOID)
33-
RETURNS VOIDAS'pg_pathman','on_partitions_created' LANGUAGE C STRICT;
34-
35-
CREATEOR REPLACE FUNCTION @extschema@.on_update_partitions(relidOID)
36-
RETURNS VOIDAS'pg_pathman','on_partitions_updated' LANGUAGE C STRICT;
37-
38-
CREATEOR REPLACE FUNCTION @extschema@.on_remove_partitions(relidOID)
39-
RETURNS VOIDAS'pg_pathman','on_partitions_removed' LANGUAGE C STRICT;
40-
41-
CREATEOR REPLACE FUNCTION @extschema@.find_or_create_range_partition(relidOID, value ANYELEMENT)
42-
RETURNSOIDAS'pg_pathman','find_or_create_range_partition' LANGUAGE C STRICT;
43-
44-
45-
/*
46-
* Returns min and max values for specified RANGE partition.
47-
*/
48-
CREATEOR REPLACE FUNCTION @extschema@.get_partition_range(
49-
parent_relidOID, partition_relidOID, dummy ANYELEMENT)
50-
RETURNS ANYARRAYAS'pg_pathman','get_partition_range' LANGUAGE C STRICT;
51-
52-
53-
/*
54-
* Returns N-th range (in form of array)
55-
*/
56-
CREATEOR REPLACE FUNCTION @extschema@.get_range_by_idx(
57-
parent_relidOID, idxINTEGER, dummy ANYELEMENT)
58-
RETURNS ANYARRAYAS'pg_pathman','get_range_by_idx' LANGUAGE C STRICT;
59-
60-
/*
61-
* Returns min value of the first range for relation
62-
*/
63-
CREATEOR REPLACE FUNCTION @extschema@.get_min_range_value(
64-
parent_relidOID, dummy ANYELEMENT)
65-
RETURNS ANYELEMENTAS'pg_pathman','get_min_range_value' LANGUAGE C STRICT;
6630

67-
/*
68-
* Returns max value of the last range for relation
69-
*/
70-
CREATEOR REPLACE FUNCTION @extschema@.get_max_range_value(
71-
parent_relidOID, dummy ANYELEMENT)
72-
RETURNS ANYELEMENTAS'pg_pathman','get_max_range_value' LANGUAGE C STRICT;
31+
SELECTpg_catalog.pg_extension_config_dump('@extschema@.pathman_config','');
7332

74-
/*
75-
* Checks if range overlaps with existing partitions.
76-
* Returns TRUE if overlaps and FALSE otherwise.
77-
*/
78-
CREATEOR REPLACE FUNCTION @extschema@.check_overlap(
79-
parent_relidOID, range_min ANYELEMENT, range_max ANYELEMENT)
80-
RETURNSBOOLEANAS'pg_pathman','check_overlap' LANGUAGE C STRICT;
8133

8234
/*
8335
* Copy rows to partitions
@@ -111,7 +63,6 @@ END
11163
$$
11264
LANGUAGE plpgsql;
11365

114-
11566
/*
11667
* Disable pathman partitioning for specified relation
11768
*/
@@ -130,43 +81,6 @@ END
13081
$$
13182
LANGUAGE plpgsql;
13283

133-
134-
/*
135-
* Returns attribute type name for relation
136-
*/
137-
CREATEOR REPLACE FUNCTION @extschema@.get_attribute_type_name(
138-
p_relation REGCLASS
139-
, p_attnameTEXT
140-
, OUT p_atttypeTEXT)
141-
RETURNSTEXTAS
142-
$$
143-
BEGIN
144-
SELECT typname::TEXT INTO p_atttype
145-
FROM pg_typeJOIN pg_attributeon atttypid="oid"
146-
WHERE attrelid= p_relation::oidand attname=lower(p_attname);
147-
END
148-
$$
149-
LANGUAGE plpgsql;
150-
151-
152-
/*
153-
* Checks if attribute is nullable
154-
*/
155-
CREATEOR REPLACE FUNCTION @extschema@.is_attribute_nullable(
156-
p_relation REGCLASS
157-
, p_attnameTEXT
158-
, OUT p_nullableBOOLEAN)
159-
RETURNSBOOLEANAS
160-
$$
161-
BEGIN
162-
SELECT NOT attnotnull INTO p_nullable
163-
FROM pg_typeJOIN pg_attributeon atttypid="oid"
164-
WHERE attrelid= p_relation::oidand attname=lower(p_attname);
165-
END
166-
$$
167-
LANGUAGE plpgsql;
168-
169-
17084
/*
17185
* Aggregates several common relation checks before partitioning. Suitable for every partitioning type.
17286
*/
@@ -217,17 +131,6 @@ END
217131
$$
218132
LANGUAGE plpgsql;
219133

220-
221-
CREATEOR REPLACE FUNCTION @extschema@.get_plain_relname(cls regclass)
222-
RETURNSTEXTAS
223-
$$
224-
BEGIN
225-
RETURN relnameFROM pg_classWHEREoid= cls::oid;
226-
END
227-
$$
228-
LANGUAGE plpgsql;
229-
230-
231134
/*
232135
* Validates relation name. It must be schema qualified
233136
*/
@@ -240,7 +143,6 @@ END
240143
$$
241144
LANGUAGE plpgsql;
242145

243-
244146
/*
245147
* Returns schema-qualified name for table
246148
*/
@@ -288,18 +190,6 @@ END
288190
$$
289191
LANGUAGE plpgsql;
290192

291-
/*
292-
* Check if regclass if date or timestamp
293-
*/
294-
CREATEOR REPLACE FUNCTION @extschema@.is_date(cls REGTYPE)
295-
RETURNSBOOLEANAS
296-
$$
297-
BEGIN
298-
RETURN clsIN ('timestamp'::regtype,'timestamptz'::regtype,'date'::regtype);
299-
END
300-
$$
301-
LANGUAGE plpgsql;
302-
303193
/*
304194
* DDL trigger that deletes entry from pathman_config table
305195
*/
@@ -322,22 +212,6 @@ END
322212
$$
323213
LANGUAGE plpgsql;
324214

325-
CREATE EVENT TRIGGER pathman_ddl_trigger
326-
ON sql_drop
327-
EXECUTE PROCEDURE @extschema@.pathman_ddl_trigger_func();
328-
329-
/*
330-
* Acquire partitions lock to prevent concurrent partitions creation
331-
*/
332-
CREATEOR REPLACE FUNCTION @extschema@.acquire_partitions_lock()
333-
RETURNS VOIDAS'pg_pathman','acquire_partitions_lock' LANGUAGE C STRICT;
334-
335-
/*
336-
* Release partitions lock
337-
*/
338-
CREATEOR REPLACE FUNCTION @extschema@.release_partitions_lock()
339-
RETURNS VOIDAS'pg_pathman','release_partitions_lock' LANGUAGE C STRICT;
340-
341215
/*
342216
* Drop trigger
343217
*/
@@ -410,18 +284,122 @@ END
410284
$$ LANGUAGE plpgsql
411285
SETpg_pathman.enable_partitionfilter= off;
412286

287+
288+
289+
CREATE EVENT TRIGGER pathman_ddl_trigger
290+
ON sql_drop
291+
EXECUTE PROCEDURE @extschema@.pathman_ddl_trigger_func();
292+
293+
294+
/*
295+
* Acquire partitions lock to prevent concurrent partitions creation
296+
*/
297+
CREATEOR REPLACE FUNCTION @extschema@.acquire_partitions_lock()
298+
RETURNS VOIDAS'pg_pathman','acquire_partitions_lock'
299+
LANGUAGE C STRICT;
300+
301+
/*
302+
* Release partitions lock
303+
*/
304+
CREATEOR REPLACE FUNCTION @extschema@.release_partitions_lock()
305+
RETURNS VOIDAS'pg_pathman','release_partitions_lock'
306+
LANGUAGE C STRICT;
307+
308+
/*
309+
* Check if regclass is date or timestamp
310+
*/
311+
CREATEOR REPLACE FUNCTION @extschema@.is_date_type(cls REGTYPE)
312+
RETURNSBOOLEANAS'pg_pathman','is_date_type'
313+
LANGUAGE C STRICT;
314+
315+
/*
316+
* Checks if range overlaps with existing partitions.
317+
* Returns TRUE if overlaps and FALSE otherwise.
318+
*/
319+
CREATEOR REPLACE FUNCTION @extschema@.check_overlap(
320+
parent_relidOID, range_min ANYELEMENT, range_max ANYELEMENT)
321+
RETURNSBOOLEANAS'pg_pathman','check_overlap'
322+
LANGUAGE C STRICT;
323+
324+
325+
CREATEOR REPLACE FUNCTION @extschema@.on_create_partitions(relidOID)
326+
RETURNS VOIDAS'pg_pathman','on_partitions_created'
327+
LANGUAGE C STRICT;
328+
329+
CREATEOR REPLACE FUNCTION @extschema@.on_update_partitions(relidOID)
330+
RETURNS VOIDAS'pg_pathman','on_partitions_updated'
331+
LANGUAGE C STRICT;
332+
333+
CREATEOR REPLACE FUNCTION @extschema@.on_remove_partitions(relidOID)
334+
RETURNS VOIDAS'pg_pathman','on_partitions_removed'
335+
LANGUAGE C STRICT;
336+
337+
338+
CREATEOR REPLACE FUNCTION @extschema@.find_or_create_range_partition(relidOID, value ANYELEMENT)
339+
RETURNSOIDAS'pg_pathman','find_or_create_range_partition'
340+
LANGUAGE C STRICT;
341+
342+
343+
/*
344+
* Returns min and max values for specified RANGE partition.
345+
*/
346+
CREATEOR REPLACE FUNCTION @extschema@.get_partition_range(
347+
parent_relidOID, partition_relidOID, dummy ANYELEMENT)
348+
RETURNS ANYARRAYAS'pg_pathman','get_partition_range'
349+
LANGUAGE C STRICT;
350+
351+
352+
/*
353+
* Returns N-th range (in form of array)
354+
*/
355+
CREATEOR REPLACE FUNCTION @extschema@.get_range_by_idx(
356+
parent_relidOID, idxINTEGER, dummy ANYELEMENT)
357+
RETURNS ANYARRAYAS'pg_pathman','get_range_by_idx'
358+
LANGUAGE C STRICT;
359+
360+
/*
361+
* Returns min value of the first range for relation
362+
*/
363+
CREATEOR REPLACE FUNCTION @extschema@.get_min_range_value(
364+
parent_relidOID, dummy ANYELEMENT)
365+
RETURNS ANYELEMENTAS'pg_pathman','get_min_range_value'
366+
LANGUAGE C STRICT;
367+
368+
/*
369+
* Returns max value of the last range for relation
370+
*/
371+
CREATEOR REPLACE FUNCTION @extschema@.get_max_range_value(
372+
parent_relidOID, dummy ANYELEMENT)
373+
RETURNS ANYELEMENTAS'pg_pathman','get_max_range_value'
374+
LANGUAGE C STRICT;
375+
413376
/*
414377
* Returns hash function OID for specified type
415378
*/
416379
CREATEOR REPLACE FUNCTION @extschema@.get_type_hash_func(OID)
417-
RETURNSOIDAS'pg_pathman','get_type_hash_func' LANGUAGE C STRICT;
380+
RETURNSOIDAS'pg_pathman','get_type_hash_func'
381+
LANGUAGE C STRICT;
418382

419383
/*
420384
* Calculates hash for integer value
421385
*/
422386
CREATEOR REPLACE FUNCTION @extschema@.get_hash(INTEGER,INTEGER)
423-
RETURNSINTEGERAS'pg_pathman','get_hash' LANGUAGE C STRICT;
387+
RETURNSINTEGERAS'pg_pathman','get_hash'
388+
LANGUAGE C STRICT;
424389

390+
/*
391+
* Checks if attribute is nullable
392+
*/
393+
CREATEOR REPLACE FUNCTION @extschema@.is_attribute_nullable(REGCLASS,TEXT)
394+
RETURNSBOOLEANAS'pg_pathman','is_attribute_nullable'
395+
LANGUAGE C STRICT;
396+
397+
/*
398+
* Returns attribute type name for relation
399+
*/
400+
CREATEOR REPLACE FUNCTION @extschema@.get_attribute_type_name(REGCLASS,TEXT)
401+
RETURNSTEXTAS'pg_pathman','get_attribute_type_name'
402+
LANGUAGE C STRICT;
425403

426404
/*
427405
* Build check constraint name for a specified relation's column
@@ -433,3 +411,10 @@ LANGUAGE C STRICT;
433411
CREATEOR REPLACE FUNCTION @extschema@.build_check_constraint_name(REGCLASS,TEXT)
434412
RETURNSTEXTAS'pg_pathman','build_check_constraint_name_attname'
435413
LANGUAGE C STRICT;
414+
415+
/*
416+
* DEBUG: Place this inside some plpgsql fuction and set breakpoint.
417+
*/
418+
CREATEOR REPLACE FUNCTION @extschema@.debug_capture()
419+
RETURNS VOIDAS'pg_pathman','debug_capture'
420+
LANGUAGE C STRICT;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp