Skip to content

Commit bba1535

Browse files
committed
Merge branch 'picky_nodes' into merge_concurrent
2 parents d7665c3 + 951cde1 commit bba1535

File tree

13 files changed

+515
-171
lines changed

13 files changed

+515
-171
lines changed

expected/pg_pathman.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,7 +1273,7 @@ SELECT pathman.enable_auto('test.range_rel');
12731273
INSERT INTO test.range_rel (dt) VALUES ('2015-06-01');
12741274
DROP TABLE test.range_rel CASCADE;
12751275
NOTICE: drop cascades to 20 other objects
1276-
SELECT partrel, attname, parttype, range_interval FROM pathman.pathman_config;
1276+
SELECT * FROM pathman.pathman_config;
12771277
partrel | attname | parttype | range_interval
12781278
---------+---------+----------+----------------
12791279
(0 rows)
@@ -1457,7 +1457,7 @@ SELECT pathman.create_partitions_from_range('test."RangeRel"', 'dt', '2015-01-01
14571457

14581458
DROP TABLE test."RangeRel" CASCADE;
14591459
NOTICE: drop cascades to 5 other objects
1460-
SELECT partrel, attname, parttype, range_interval FROM pathman.pathman_config;
1460+
SELECT * FROM pathman.pathman_config;
14611461
partrel | attname | parttype | range_interval
14621462
--------------------+---------+----------+----------------
14631463
test.num_range_rel | id | 2 | 1000

hash.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ BEGIN
7575
END IF;
7676

7777
RETURN partitions_count;
78+
79+
EXCEPTION WHEN others THEN
80+
RAISE EXCEPTION '%', SQLERRM;
7881
END
7982
$$ LANGUAGE plpgsql
8083
SET client_min_messages = WARNING;

init.sql

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
* range_interval - base interval for RANGE partitioning as string
1919
*/
2020
CREATE TABLE IF NOT EXISTS @extschema@.pathman_config (
21-
id SERIAL PRIMARY KEY,
22-
partrel REGCLASS NOT NULL,
21+
partrel REGCLASS NOT NULL PRIMARY KEY,
2322
attname TEXT NOT NULL,
2423
parttype INTEGER NOT NULL,
2524
range_interval TEXT,
@@ -309,8 +308,18 @@ $$
309308
DECLARE
310309
v_rec RECORD;
311310
is_referenced BOOLEAN;
311+
rel_persistence CHAR;
312312

313313
BEGIN
314+
/* Ignore temporary tables */
315+
SELECT relpersistence FROM pg_catalog.pg_class
316+
WHERE oid = p_relation INTO rel_persistence;
317+
318+
IF rel_persistence = 't'::CHAR THEN
319+
RAISE EXCEPTION 'Temporary table "%" cannot be partitioned',
320+
quote_ident(p_relation::TEXT);
321+
END IF;
322+
314323
IF EXISTS (SELECT * FROM @extschema@.pathman_config
315324
WHERE partrel = p_relation) THEN
316325
RAISE EXCEPTION 'Relation "%" has already been partitioned', p_relation;
@@ -320,7 +329,7 @@ BEGIN
320329
RAISE EXCEPTION 'Partitioning key ''%'' must be NOT NULL', p_attribute;
321330
END IF;
322331

323-
/* Check if there are foreign keys reference to the relation */
332+
/* Check if there are foreign keys that reference the relation */
324333
FOR v_rec IN (SELECT *
325334
FROM pg_constraint WHERE confrelid = p_relation::regclass::oid)
326335
LOOP
@@ -469,12 +478,9 @@ CREATE OR REPLACE FUNCTION @extschema@.drop_triggers(
469478
parent_relid REGCLASS)
470479
RETURNS VOID AS
471480
$$
472-
DECLARE
473-
funcname TEXT;
474-
475481
BEGIN
476-
funcname := @extschema@.build_update_trigger_func_name(parent_relid);
477-
EXECUTE format('DROP FUNCTION IF EXISTS %s() CASCADE', funcname);
482+
EXECUTE format('DROP FUNCTION IF EXISTS %s() CASCADE',
483+
@extschema@.build_update_trigger_func_name(parent_relid));
478484
END
479485
$$ LANGUAGE plpgsql;
480486

@@ -545,12 +551,14 @@ EXECUTE PROCEDURE @extschema@.pathman_ddl_trigger_func();
545551

546552

547553
/*
548-
* Check if regclass is date or timestamp
554+
* Attach partitioned table
549555
*/
550-
CREATE OR REPLACE FUNCTION @extschema@.is_date_type(
551-
typid REGTYPE)
552-
RETURNS BOOLEAN AS 'pg_pathman', 'is_date_type'
553-
LANGUAGE C STRICT;
556+
CREATE OR REPLACE FUNCTION @extschema@.add_to_pathman_config(
557+
parent_relid REGCLASS,
558+
attname TEXT,
559+
range_interval TEXT DEFAULT NULL)
560+
RETURNS BOOLEAN AS 'pg_pathman', 'add_to_pathman_config'
561+
LANGUAGE C;
554562

555563

556564
CREATE OR REPLACE FUNCTION @extschema@.on_create_partitions(
@@ -569,6 +577,21 @@ RETURNS VOID AS 'pg_pathman', 'on_partitions_removed'
569577
LANGUAGE C STRICT;
570578

571579

580+
/*
581+
* Get parent of pg_pathman's partition.
582+
*/
583+
CREATE OR REPLACE FUNCTION @extschema@.get_parent_of_partition(REGCLASS)
584+
RETURNS REGCLASS AS 'pg_pathman', 'get_parent_of_partition_pl'
585+
LANGUAGE C STRICT;
586+
587+
/*
588+
* Check if regclass is date or timestamp
589+
*/
590+
CREATE OR REPLACE FUNCTION @extschema@.is_date_type(
591+
typid REGTYPE)
592+
RETURNS BOOLEAN AS 'pg_pathman', 'is_date_type'
593+
LANGUAGE C STRICT;
594+
572595
/*
573596
* Checks if attribute is nullable
574597
*/
@@ -617,10 +640,3 @@ LANGUAGE C STRICT;
617640
CREATE OR REPLACE FUNCTION @extschema@.debug_capture()
618641
RETURNS VOID AS 'pg_pathman', 'debug_capture'
619642
LANGUAGE C STRICT;
620-
621-
/*
622-
* Get parent of pg_pathman's partition.
623-
*/
624-
CREATE OR REPLACE FUNCTION @extschema@.get_parent_of_partition(REGCLASS)
625-
RETURNS REGCLASS AS 'pg_pathman', 'get_parent_of_partition_pl'
626-
LANGUAGE C STRICT;

range.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ BEGIN
971971
WHERE oid = p_partition INTO rel_persistence;
972972

973973
IF rel_persistence = 't'::CHAR THEN
974-
RAISE EXCEPTION 'Temporary table \"%\" cannot be used as a partition',
974+
RAISE EXCEPTION 'Temporary table "%" cannot be used as a partition',
975975
quote_ident(p_partition::TEXT);
976976
END IF;
977977

src/hooks.c

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ pathman_rel_pathlist_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTb
227227
rte->inh = true; /* we must restore 'inh' flag! */
228228

229229
children = PrelGetChildrenArray(prel);
230-
ranges = list_make1_irange(make_irange(0, PrelChildrenCount(prel) - 1, false));
230+
ranges = list_make1_irange(make_irange(0, PrelLastChild(prel), false));
231231

232232
/* Make wrappers over restrictions and collect final rangeset */
233233
InitWalkerContext(&context, prel, NULL, false);
@@ -361,15 +361,8 @@ pg_pathman_enable_assign_hook(bool newval, void *extra)
361361
elog(DEBUG2, "pg_pathman_enable_assign_hook() [newval = %s] triggered",
362362
newval ? "true" : "false");
363363

364-
if (initialization_needed)
365-
{
366-
elog(DEBUG2, "pg_pathman is not yet initialized, "
367-
"pg_pathman.enable is set to false");
368-
return;
369-
}
370-
371364
/* Return quickly if nothing has changed */
372-
if (newval == (pg_pathman_enable &&
365+
if (newval == (pg_pathman_init_state.pg_pathman_enable &&
373366
pg_pathman_enable_runtimeappend &&
374367
pg_pathman_enable_runtime_merge_append &&
375368
pg_pathman_enable_partition_filter))
@@ -465,23 +458,9 @@ pathman_post_parse_analysis_hook(ParseState *pstate, Query *query)
465458
if (IsPathmanReady())
466459
finish_delayed_invalidation();
467460

468-
elog(DEBUG2, "post_parse: %d %d %u [%u]",
469-
IsPathmanEnabled(),
470-
initialization_needed,
471-
get_pathman_schema(),
472-
MyProcPid);
473-
474-
/* DEBUG!!!! */
475-
// static int parse_sleep = 10;
476-
// if (IsPathmanEnabled() &&
477-
// initialization_needed &&
478-
// get_pathman_schema() == InvalidOid)
479-
// sleep(parse_sleep);
480-
/* -------------------- */
481-
482461
/* Load config if pg_pathman exists & it's still necessary */
483462
if (IsPathmanEnabled() &&
484-
initialization_needed &&
463+
!IsPathmanInitialized() &&
485464
/* Now evaluate the most expensive clause */
486465
get_pathman_schema() != InvalidOid)
487466
{

0 commit comments

Comments
 (0)