Skip to content

Commit ac090da

Browse files
committed
Merge branch 'master' into picky_nodes (resolve conflicts, clean code)
2 parents 7d3e324 + a1e6bd3 commit ac090da

File tree

11 files changed

+354
-161
lines changed

11 files changed

+354
-161
lines changed

expected/pg_pathman.out

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ CREATE INDEX ON test.range_rel (dt);
5353
INSERT INTO test.range_rel (dt, txt)
5454
SELECT g, md5(g::TEXT) FROM generate_series('2015-01-01', '2015-04-30', '1 day'::interval) as g;
5555
SELECT pathman.create_range_partitions('test.range_rel', 'dt', '2015-01-01'::DATE, '1 month'::INTERVAL, 2);
56-
ERROR: Partitioning key 'dt' must be NOT NULL P0001
56+
ERROR: Partitioning key 'dt' must be NOT NULL
5757
ALTER TABLE test.range_rel ALTER COLUMN dt SET NOT NULL;
5858
SELECT pathman.create_range_partitions('test.range_rel', 'dt', '2015-01-01'::DATE, '1 month'::INTERVAL, 2);
59-
ERROR: Not enough partitions to fit all the values of 'dt' P0001
59+
ERROR: Not enough partitions to fit all the values of 'dt'
6060
SELECT pathman.create_range_partitions('test.range_rel', 'DT', '2015-01-01'::DATE, '1 month'::INTERVAL);
6161
NOTICE: sequence "range_rel_seq" does not exist, skipping
6262
NOTICE: Copying data to partitions...
@@ -997,7 +997,7 @@ EXPLAIN (COSTS OFF) SELECT * FROM test.range_rel WHERE dt BETWEEN '2014-12-15' A
997997
(3 rows)
998998

999999
SELECT pathman.add_range_partition('test.range_rel', '2014-12-01'::DATE, '2015-01-02'::DATE);
1000-
ERROR: Specified range overlaps with existing partitions P0001
1000+
ERROR: Specified range overlaps with existing partitions
10011001
SELECT pathman.add_range_partition('test.range_rel', '2014-12-01'::DATE, '2015-01-01'::DATE);
10021002
NOTICE: Done!
10031003
add_range_partition
@@ -1017,7 +1017,7 @@ EXPLAIN (COSTS OFF) SELECT * FROM test.range_rel WHERE dt BETWEEN '2014-12-15' A
10171017

10181018
CREATE TABLE test.range_rel_archive (LIKE test.range_rel INCLUDING ALL);
10191019
SELECT pathman.attach_range_partition('test.range_rel', 'test.range_rel_archive', '2014-01-01'::DATE, '2015-01-01'::DATE);
1020-
ERROR: Specified range overlaps with existing partitions P0001
1020+
ERROR: Specified range overlaps with existing partitions
10211021
SELECT pathman.attach_range_partition('test.range_rel', 'test.range_rel_archive', '2014-01-01'::DATE, '2014-12-01'::DATE);
10221022
attach_range_partition
10231023
------------------------
@@ -1056,12 +1056,12 @@ CREATE TABLE test.range_rel_test1 (
10561056
txt TEXT,
10571057
abc INTEGER);
10581058
SELECT pathman.attach_range_partition('test.range_rel', 'test.range_rel_test1', '2013-01-01'::DATE, '2014-01-01'::DATE);
1059-
ERROR: Partition must have the exact same structure as parent P0001
1059+
ERROR: Partition must have the exact same structure as parent
10601060
CREATE TABLE test.range_rel_test2 (
10611061
id SERIAL PRIMARY KEY,
10621062
dt TIMESTAMP);
10631063
SELECT pathman.attach_range_partition('test.range_rel', 'test.range_rel_test2', '2013-01-01'::DATE, '2014-01-01'::DATE);
1064-
ERROR: Partition must have the exact same structure as parent P0001
1064+
ERROR: Partition must have the exact same structure as parent
10651065
/*
10661066
* Check that altering table columns doesn't break trigger
10671067
*/
@@ -1620,7 +1620,7 @@ INSERT INTO messages SELECT g, md5(g::text) FROM generate_series(1, 10) as g;
16201620
INSERT INTO replies SELECT g, g, md5(g::text) FROM generate_series(1, 10) as g;
16211621
SELECT create_range_partitions('messages', 'id', 1, 100, 2);
16221622
WARNING: Foreign key 'replies_message_id_fkey' references to the relation 'messages'
1623-
ERROR: Relation 'messages' is referenced from other relations P0001
1623+
ERROR: Relation 'messages' is referenced from other relations
16241624
ALTER TABLE replies DROP CONSTRAINT replies_message_id_fkey;
16251625
SELECT create_range_partitions('messages', 'id', 1, 100, 2);
16261626
NOTICE: sequence "messages_seq" does not exist, skipping

hash.sql

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,6 @@ BEGIN
3030
PERFORM @extschema@.common_relation_checks(relation, attribute);
3131

3232
v_type := @extschema@.get_attribute_type_name(v_relname, attribute);
33-
-- IF v_type::regtype != 'integer'::regtype THEN
34-
-- RAISE EXCEPTION 'Attribute type must be INTEGER';
35-
-- END IF;
3633

3734
SELECT * INTO v_plain_schema, v_plain_relname
3835
FROM @extschema@.get_plain_schema_and_relname(relation);
@@ -42,10 +39,9 @@ BEGIN
4239
/* Create partitions and update pg_pathman configuration */
4340
FOR partnum IN 0..partitions_count-1
4441
LOOP
45-
-- v_child_relname := @extschema@.get_schema_qualified_name(relation, '.', suffix := '_' || partnum);
4642
v_child_relname := format('%s.%s',
47-
v_plain_schema,
48-
quote_ident(v_plain_relname || '_' || partnum));
43+
v_plain_schema,
44+
quote_ident(v_plain_relname || '_' || partnum));
4945

5046
EXECUTE format('CREATE TABLE %s (LIKE %s INCLUDING ALL)'
5147
, v_child_relname

init.sql

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,10 +104,6 @@ BEGIN
104104
, relname);
105105
GET DIAGNOSTICS p_total = ROW_COUNT;
106106
RETURN;
107-
108-
-- EXCEPTION WHEN others THEN
109-
-- PERFORM on_remove_partitions(p_parent::regclass::integer);
110-
-- RAISE EXCEPTION '% %', SQLERRM, SQLSTATE;
111107
END
112108
$$
113109
LANGUAGE plpgsql;

range.sql

Lines changed: 53 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,7 @@ BEGIN
106106
RETURN p_count;
107107

108108
EXCEPTION WHEN others THEN
109-
PERFORM @extschema@.on_remove_partitions(p_relation::integer);
110-
RAISE EXCEPTION '% %', SQLERRM, SQLSTATE;
109+
RAISE EXCEPTION '%', SQLERRM;
111110
END
112111
$$ LANGUAGE plpgsql;
113112

@@ -193,8 +192,7 @@ BEGIN
193192
RETURN p_count;
194193

195194
EXCEPTION WHEN others THEN
196-
PERFORM @extschema@.on_remove_partitions(p_relation::regclass::integer);
197-
RAISE EXCEPTION '% %', SQLERRM, SQLSTATE;
195+
RAISE EXCEPTION '%', SQLERRM;
198196
END
199197
$$ LANGUAGE plpgsql;
200198

@@ -257,8 +255,7 @@ BEGIN
257255
RETURN i;
258256

259257
EXCEPTION WHEN others THEN
260-
PERFORM @extschema@.on_remove_partitions(p_relation::regclass::integer);
261-
RAISE EXCEPTION '% %', SQLERRM, SQLSTATE;
258+
RAISE EXCEPTION '%', SQLERRM;
262259
END
263260
$$ LANGUAGE plpgsql;
264261

@@ -314,8 +311,7 @@ BEGIN
314311
RETURN i;
315312

316313
EXCEPTION WHEN others THEN
317-
PERFORM @extschema@.on_remove_partitions(p_relation::regclass::integer);
318-
RAISE EXCEPTION '% %', SQLERRM, SQLSTATE;
314+
RAISE EXCEPTION '%', SQLERRM;
319315
END
320316
$$ LANGUAGE plpgsql;
321317

@@ -401,19 +397,19 @@ CREATE OR REPLACE FUNCTION @extschema@.create_single_range_partition(
401397
RETURNS TEXT AS
402398
$$
403399
DECLARE
404-
v_part_num INT;
400+
v_part_num INT;
405401
v_child_relname TEXT;
406-
v_plain_child_relname TEXT;
402+
v_plain_child_relname TEXT;
407403
v_attname TEXT;
408-
v_sql TEXT;
409-
v_cond TEXT;
410-
v_plain_schema TEXT;
411-
v_plain_relname TEXT;
412-
v_child_relname_exists INTEGER := 1;
413-
v_seq_name TEXT;
404+
v_sql TEXT;
405+
v_cond TEXT;
406+
v_plain_schema TEXT;
407+
v_plain_relname TEXT;
408+
v_child_relname_exists INTEGER := 1;
409+
v_seq_name TEXT;
414410
BEGIN
415-
v_attname := attname FROM @extschema@.pathman_config
416-
WHERE relname::regclass = p_parent;
411+
v_attname := attname FROM @extschema@.pathman_config
412+
WHERE relname::regclass = p_parent;
417413

418414
IF v_attname IS NULL THEN
419415
RAISE EXCEPTION 'Table % is not partitioned', quote_ident(p_parent::TEXT);
@@ -424,36 +420,36 @@ BEGIN
424420

425421
v_seq_name := @extschema@.get_sequence_name(v_plain_schema, v_plain_relname);
426422

427-
/* get next value from sequence */
428-
LOOP
429-
v_part_num := nextval(v_seq_name);
430-
v_plain_child_relname := format('%s_%s', v_plain_relname, v_part_num);
431-
v_child_relname := format('%s.%s',
432-
v_plain_schema,
433-
quote_ident(v_plain_child_relname));
434-
v_child_relname_exists := count(*)
435-
FROM pg_class
436-
WHERE relnamespace::regnamespace || '.' || relname = v_child_relname
437-
LIMIT 1;
438-
EXIT WHEN v_child_relname_exists = 0;
439-
END LOOP;
440-
441-
EXECUTE format('CREATE TABLE %s (LIKE %s INCLUDING ALL)'
442-
, v_child_relname
443-
, p_parent);
444-
445-
EXECUTE format('ALTER TABLE %s INHERIT %s'
446-
, v_child_relname
447-
, p_parent);
448-
449-
v_cond := @extschema@.get_range_condition(v_attname, p_start_value, p_end_value);
450-
v_sql := format('ALTER TABLE %s ADD CONSTRAINT %s CHECK (%s)'
451-
, v_child_relname
452-
, quote_ident(format('%s_%s_check', v_plain_schema, v_plain_child_relname))
453-
, v_cond);
454-
455-
EXECUTE v_sql;
456-
RETURN v_child_relname;
423+
/* get next value from sequence */
424+
LOOP
425+
v_part_num := nextval(v_seq_name);
426+
v_plain_child_relname := format('%s_%s', v_plain_relname, v_part_num);
427+
v_child_relname := format('%s.%s',
428+
v_plain_schema,
429+
quote_ident(v_plain_child_relname));
430+
v_child_relname_exists := count(*)
431+
FROM pg_class
432+
WHERE relnamespace::regnamespace || '.' || relname = v_child_relname
433+
LIMIT 1;
434+
EXIT WHEN v_child_relname_exists = 0;
435+
END LOOP;
436+
437+
EXECUTE format('CREATE TABLE %s (LIKE %s INCLUDING ALL)'
438+
, v_child_relname
439+
, p_parent);
440+
441+
EXECUTE format('ALTER TABLE %s INHERIT %s'
442+
, v_child_relname
443+
, p_parent);
444+
445+
v_cond := @extschema@.get_range_condition(v_attname, p_start_value, p_end_value);
446+
v_sql := format('ALTER TABLE %s ADD CONSTRAINT %s CHECK (%s)'
447+
, v_child_relname
448+
, quote_ident(format('%s_%s_check', v_plain_schema, v_plain_child_relname))
449+
, v_cond);
450+
451+
EXECUTE v_sql;
452+
RETURN v_child_relname;
457453
END
458454
$$ LANGUAGE plpgsql;
459455

@@ -735,7 +731,7 @@ BEGIN
735731
RETURN v_part_name;
736732

737733
EXCEPTION WHEN others THEN
738-
RAISE EXCEPTION '% %', SQLERRM, SQLSTATE;
734+
RAISE EXCEPTION '%', SQLERRM;
739735
END
740736
$$
741737
LANGUAGE plpgsql;
@@ -809,7 +805,7 @@ BEGIN
809805
RETURN v_part_name;
810806

811807
EXCEPTION WHEN others THEN
812-
RAISE EXCEPTION '% %', SQLERRM, SQLSTATE;
808+
RAISE EXCEPTION '%', SQLERRM;
813809
END
814810
$$
815811
LANGUAGE plpgsql;
@@ -879,7 +875,7 @@ BEGIN
879875
RETURN v_part_name;
880876

881877
EXCEPTION WHEN others THEN
882-
RAISE EXCEPTION '% %', SQLERRM, SQLSTATE;
878+
RAISE EXCEPTION '%', SQLERRM;
883879
END
884880
$$
885881
LANGUAGE plpgsql;
@@ -918,7 +914,7 @@ BEGIN
918914
RETURN v_part_name;
919915

920916
EXCEPTION WHEN others THEN
921-
RAISE EXCEPTION '% %', SQLERRM, SQLSTATE;
917+
RAISE EXCEPTION '%', SQLERRM;
922918
END
923919
$$
924920
LANGUAGE plpgsql;
@@ -951,15 +947,13 @@ BEGIN
951947
/* Prevent concurrent partition management */
952948
PERFORM @extschema@.acquire_partitions_lock();
953949

954-
-- p_relation := @extschema@.validate_relname(p_relation);
955-
956950
IF @extschema@.check_overlap(p_relation::oid, p_start_value, p_end_value) != FALSE THEN
957951
RAISE EXCEPTION 'Specified range overlaps with existing partitions';
958952
END IF;
959953

960-
IF NOT @extschema@.validate_relations_equality(p_relation, p_partition) THEN
961-
RAISE EXCEPTION 'Partition must have the exact same structure as parent';
962-
END IF;
954+
IF NOT @extschema@.validate_relations_equality(p_relation, p_partition) THEN
955+
RAISE EXCEPTION 'Partition must have the exact same structure as parent';
956+
END IF;
963957

964958
/* Set inheritance */
965959
EXECUTE format('ALTER TABLE %s INHERIT %s'
@@ -993,7 +987,7 @@ BEGIN
993987
RETURN p_partition;
994988

995989
EXCEPTION WHEN others THEN
996-
RAISE EXCEPTION '% %', SQLERRM, SQLSTATE;
990+
RAISE EXCEPTION '%', SQLERRM;
997991
END
998992
$$
999993
LANGUAGE plpgsql;
@@ -1034,7 +1028,7 @@ BEGIN
10341028
RETURN p_partition;
10351029

10361030
EXCEPTION WHEN others THEN
1037-
RAISE EXCEPTION '% %', SQLERRM, SQLSTATE;
1031+
RAISE EXCEPTION '%', SQLERRM;
10381032
END
10391033
$$
10401034
LANGUAGE plpgsql;

src/hooks.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,7 +345,8 @@ pathman_rel_pathlist_hook(PlannerInfo *root, RelOptInfo *rel, Index rti, RangeTb
345345
}
346346
}
347347

348-
void pg_pathman_enable_assign_hook(bool newval, void *extra)
348+
void
349+
pg_pathman_enable_assign_hook(bool newval, void *extra)
349350
{
350351
/* Return quickly if nothing has changed */
351352
if (newval == (pg_pathman_enable &&
@@ -424,7 +425,9 @@ pathman_planner_hook(Query *parse, int cursorOptions, ParamListInfo boundParams)
424425
}
425426

426427
list_free(inheritance_disabled_relids);
428+
list_free(inheritance_enabled_relids);
427429
inheritance_disabled_relids = NIL;
430+
inheritance_enabled_relids = NIL;
428431

429432
return result;
430433
}

src/init.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ get_extension_schema()
165165
}
166166

167167
/*
168-
* Loads partitioned tables structure to hashtable
168+
* Loads partitioned tables structure to hashtable.
169+
*
170+
* TODO: reload just the specified relation
169171
*/
170172
void
171173
load_relations(bool reinitialize)
@@ -680,7 +682,8 @@ validate_hash_constraint(Expr *expr, PartRelationInfo *prel, int *hash)
680682
/* Check that function is the base hash function for the type */
681683
funcexpr = (FuncExpr *) first;
682684
if (funcexpr->funcid != prel->hash_proc ||
683-
(!IsA(linitial(funcexpr->args), Var) && !IsA(linitial(funcexpr->args), RelabelType)))
685+
(!IsA(linitial(funcexpr->args), Var) && !IsA(linitial(funcexpr->args),
686+
RelabelType)))
684687
return false;
685688

686689
/* Check that argument is partitioning key attribute */
@@ -722,7 +725,7 @@ create_range_restrictions_hashtable()
722725
}
723726

724727
/*
725-
* Remove partitions
728+
* Remove partitions from pathman's cache
726729
*/
727730
void
728731
remove_relation_info(Oid relid)
@@ -738,21 +741,26 @@ remove_relation_info(Oid relid)
738741

739742
/* If there is nothing to remove then just return */
740743
if (!prel)
744+
{
745+
elog(DEBUG2, "pg_pathman's cache does not contain relation %u", relid);
741746
return;
747+
}
742748

743749
/* Remove children relations */
744750
switch (prel->parttype)
745751
{
746752
case PT_HASH:
747753
free_dsm_array(&prel->children);
748754
break;
755+
749756
case PT_RANGE:
750757
rangerel = get_pathman_range_relation(relid, NULL);
751758
free_dsm_array(&rangerel->ranges);
752759
free_dsm_array(&prel->children);
753760
hash_search(range_restrictions, (const void *) &key, HASH_REMOVE, NULL);
754761
break;
755762
}
763+
756764
prel->children_count = 0;
757765
hash_search(relations, (const void *) &key, HASH_REMOVE, 0);
758766
}

src/nodes_common.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "nodes_common.h"
1212
#include "runtimeappend.h"
1313
#include "optimizer/restrictinfo.h"
14-
#include "optimizer/plancat.h"
1514
#include "utils/memutils.h"
1615
#include "utils.h"
1716

@@ -215,7 +214,7 @@ unpack_runtimeappend_private(RuntimeAppendState *scan_state, CustomScan *cscan)
215214

216215
children_table = hash_create("Plan storage", nchildren,
217216
children_table_config,
218-
HASH_ELEM | HASH_BLOBS);
217+
HASH_ELEM | HASH_BLOBS);
219218

220219
i = 0;
221220
forboth (oid_cell, custom_oids, plan_cell, cscan->custom_plans)

0 commit comments

Comments
 (0)