Skip to content

Commit e84e169

Browse files
committed
Merge branch 'rel_future_beta' into rel_1_3_trigger
2 parents ecec006 + 0a0d2cf commit e84e169

33 files changed

+533
-284
lines changed

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ OBJS = src/init.o src/relation_info.o src/utils.o src/partition_filter.o \
66
src/runtimeappend.o src/runtime_merge_append.o src/pg_pathman.o src/rangeset.o \
77
src/pl_funcs.o src/pl_range_funcs.o src/pl_hash_funcs.o src/pathman_workers.o \
88
src/hooks.o src/nodes_common.o src/xact_handling.o src/utility_stmt_hooking.o \
9-
src/planner_tree_modification.o src/debug_print.o src/pg_compat.o \
10-
src/partition_creation.o $(WIN32RES)
9+
src/planner_tree_modification.o src/debug_print.o src/partition_creation.o \
10+
src/compat/pg_compat.o $(WIN32RES)
11+
12+
PG_CPPFLAGS = -I$(CURDIR)/src/include
1113

1214
EXTENSION = pg_pathman
1315

@@ -25,6 +27,7 @@ REGRESS = pathman_basic \
2527
pathman_cte \
2628
pathman_bgw \
2729
pathman_inserts \
30+
pathman_updates \
2831
pathman_domains \
2932
pathman_interval \
3033
pathman_callbacks \

README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
[![Build Status](https://travis-ci.org/postgrespro/pg_pathman.svg?branch=master)](https://travis-ci.org/postgrespro/pg_pathman)
22
[![PGXN version](https://badge.fury.io/pg/pg_pathman.svg)](https://badge.fury.io/pg/pg_pathman)
3+
[![codecov](https://codecov.io/gh/postgrespro/pg_pathman/branch/master/graph/badge.svg)](https://codecov.io/gh/postgrespro/pg_pathman)
34

45
# pg_pathman
56

@@ -77,6 +78,19 @@ Done! Now it's time to setup your partitioning schemes.
7778

7879
> **Important:** Don't forget to set the `PG_CONFIG` variable in case you want to test `pg_pathman` on a custom build of PostgreSQL. Read more [here](https://wiki.postgresql.org/wiki/Building_and_Installing_PostgreSQL_Extension_Modules).
7980
81+
## How to update
82+
In order to update pg_pathman:
83+
84+
1. Install the latest _stable_ release of pg_pathman.
85+
2. Restart your PostgreSQL cluster.
86+
3. Execute the following queries:
87+
88+
```plpgsql
89+
/* replace X.Y with the version number, e.g. 1.3 */
90+
ALTER EXTENSION pg_pathman UPDATE TO "X.Y";
91+
SET pg_pathman.enable = t;
92+
```
93+
8094
## Available functions
8195

8296
### Partition creation
@@ -253,17 +267,21 @@ Set partition creation callback to be invoked for each attached or created parti
253267
/* RANGE-partitioned table abc (child abc_4) */
254268
{
255269
"parent": "abc",
270+
"parent_schema": "public",
256271
"parttype": "2",
257272
"partition": "abc_4",
273+
"partition_schema": "public",
258274
"range_max": "401",
259275
"range_min": "301"
260276
}
261277

262278
/* HASH-partitioned table abc (child abc_0) */
263279
{
264280
"parent": "abc",
281+
"parent_schema": "public",
265282
"parttype": "1",
266283
"partition": "abc_0"
284+
"partition_schema": "public"
267285
}
268286
```
269287

@@ -654,3 +672,4 @@ Do not hesitate to post your issues, questions and new ideas at the [issues](htt
654672
Ildar Musin <i.musin@postgrespro.ru> Postgres Professional Ltd., Russia
655673
Alexander Korotkov <a.korotkov@postgrespro.ru> Postgres Professional Ltd., Russia
656674
Dmitry Ivanov <d.ivanov@postgrespro.ru> Postgres Professional Ltd., Russia
675+

expected/pathman_basic.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,14 +1376,14 @@ SELECT pathman.attach_range_partition('test.range_rel', 'test.range_rel_minus_in
13761376
SELECT * FROM pathman.pathman_partition_list WHERE parent = 'test.range_rel'::REGCLASS;
13771377
parent | partition | parttype | partattr | range_min | range_max
13781378
----------------+-------------------------------+----------+----------+--------------------------+--------------------------
1379-
test.range_rel | test.range_rel_minus_infinity | 2 | dt | NULL | Mon Dec 01 00:00:00 2014
1379+
test.range_rel | test.range_rel_minus_infinity | 2 | dt | | Mon Dec 01 00:00:00 2014
13801380
test.range_rel | test.range_rel_8 | 2 | dt | Mon Dec 01 00:00:00 2014 | Thu Jan 01 00:00:00 2015
13811381
test.range_rel | test.range_rel_1 | 2 | dt | Thu Jan 01 00:00:00 2015 | Sun Feb 01 00:00:00 2015
13821382
test.range_rel | test.range_rel_2 | 2 | dt | Sun Feb 01 00:00:00 2015 | Sun Mar 01 00:00:00 2015
13831383
test.range_rel | test.range_rel_3 | 2 | dt | Sun Mar 01 00:00:00 2015 | Wed Apr 01 00:00:00 2015
13841384
test.range_rel | test.range_rel_4 | 2 | dt | Wed Apr 01 00:00:00 2015 | Fri May 01 00:00:00 2015
13851385
test.range_rel | test.range_rel_6 | 2 | dt | Fri May 01 00:00:00 2015 | Mon Jun 01 00:00:00 2015
1386-
test.range_rel | test.range_rel_plus_infinity | 2 | dt | Mon Jun 01 00:00:00 2015 | NULL
1386+
test.range_rel | test.range_rel_plus_infinity | 2 | dt | Mon Jun 01 00:00:00 2015 |
13871387
(8 rows)
13881388

13891389
INSERT INTO test.range_rel (dt) VALUES ('2012-06-15');

expected/pathman_updates.out

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
\set VERBOSITY terse
2+
SET search_path = 'public';
3+
CREATE EXTENSION pg_pathman;
4+
CREATE SCHEMA test_updates;
5+
/*
6+
* Test UPDATEs on a partition with different TupleDescriptor.
7+
*/
8+
/* create partitioned table */
9+
CREATE TABLE test_updates.test(a FLOAT4, val INT4 NOT NULL, b FLOAT8);
10+
INSERT INTO test_updates.test SELECT i, i, i FROM generate_series(1, 100) AS i;
11+
SELECT create_range_partitions('test_updates.test', 'val', 1, 10);
12+
NOTICE: sequence "test_seq" does not exist, skipping
13+
create_range_partitions
14+
-------------------------
15+
10
16+
(1 row)
17+
18+
/* drop column 'a' */
19+
ALTER TABLE test_updates.test DROP COLUMN a;
20+
/* append new partition */
21+
SELECT append_range_partition('test_updates.test');
22+
append_range_partition
23+
------------------------
24+
test_updates.test_11
25+
(1 row)
26+
27+
INSERT INTO test_updates.test_11 (val, b) VALUES (101, 10);
28+
/* tuple descs are the same */
29+
EXPLAIN (COSTS OFF) UPDATE test_updates.test SET b = 0 WHERE val = 1;
30+
QUERY PLAN
31+
---------------------------
32+
Update on test_1
33+
-> Seq Scan on test_1
34+
Filter: (val = 1)
35+
(3 rows)
36+
37+
UPDATE test_updates.test SET b = 0 WHERE val = 1 RETURNING *, tableoid::REGCLASS;
38+
val | b | tableoid
39+
-----+---+---------------------
40+
1 | 0 | test_updates.test_1
41+
(1 row)
42+
43+
/* tuple descs are different */
44+
EXPLAIN (COSTS OFF) UPDATE test_updates.test SET b = 0 WHERE val = 101;
45+
QUERY PLAN
46+
-----------------------------
47+
Update on test
48+
Update on test
49+
Update on test_11
50+
-> Seq Scan on test
51+
Filter: (val = 101)
52+
-> Seq Scan on test_11
53+
Filter: (val = 101)
54+
(7 rows)
55+
56+
UPDATE test_updates.test SET b = 0 WHERE val = 101 RETURNING *, tableoid::REGCLASS;
57+
val | b | tableoid
58+
-----+---+----------------------
59+
101 | 0 | test_updates.test_11
60+
(1 row)
61+
62+
DROP SCHEMA test_updates CASCADE;
63+
NOTICE: drop cascades to 13 other objects
64+
DROP EXTENSION pg_pathman;

sql/pathman_updates.sql

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
\set VERBOSITY terse
2+
3+
SET search_path = 'public';
4+
CREATE EXTENSION pg_pathman;
5+
CREATE SCHEMA test_updates;
6+
7+
8+
/*
9+
* Test UPDATEs on a partition with different TupleDescriptor.
10+
*/
11+
12+
/* create partitioned table */
13+
CREATE TABLE test_updates.test(a FLOAT4, val INT4 NOT NULL, b FLOAT8);
14+
INSERT INTO test_updates.test SELECT i, i, i FROM generate_series(1, 100) AS i;
15+
SELECT create_range_partitions('test_updates.test', 'val', 1, 10);
16+
17+
/* drop column 'a' */
18+
ALTER TABLE test_updates.test DROP COLUMN a;
19+
20+
/* append new partition */
21+
SELECT append_range_partition('test_updates.test');
22+
INSERT INTO test_updates.test_11 (val, b) VALUES (101, 10);
23+
24+
25+
/* tuple descs are the same */
26+
EXPLAIN (COSTS OFF) UPDATE test_updates.test SET b = 0 WHERE val = 1;
27+
UPDATE test_updates.test SET b = 0 WHERE val = 1 RETURNING *, tableoid::REGCLASS;
28+
29+
30+
/* tuple descs are different */
31+
EXPLAIN (COSTS OFF) UPDATE test_updates.test SET b = 0 WHERE val = 101;
32+
UPDATE test_updates.test SET b = 0 WHERE val = 101 RETURNING *, tableoid::REGCLASS;
33+
34+
35+
36+
DROP SCHEMA test_updates CASCADE;
37+
DROP EXTENSION pg_pathman;

src/pg_compat.c renamed to src/compat/pg_compat.c

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
*
66
* Copyright (c) 2016, Postgres Professional
77
*
8+
* Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
9+
* Portions Copyright (c) 1994, Regents of the University of California
10+
*
811
* ------------------------------------------------------------------------
912
*/
1013

11-
#include "pg_compat.h"
14+
#include "compat/pg_compat.h"
1215

1316
#include "catalog/pg_proc.h"
1417
#include "foreign/fdwapi.h"
@@ -22,6 +25,7 @@
2225
#include <math.h>
2326

2427

28+
/* Common code */
2529
void
2630
set_append_rel_size_compat(PlannerInfo *root, RelOptInfo *rel, Index rti)
2731
{
@@ -51,6 +55,7 @@ set_append_rel_size_compat(PlannerInfo *root, RelOptInfo *rel, Index rti)
5155
Assert(childrel->rows > 0);
5256

5357
parent_rows += childrel->rows;
58+
5459
#if PG_VERSION_NUM >= 90600
5560
parent_size += childrel->reltarget->width * childrel->rows;
5661
#else
@@ -66,27 +71,20 @@ set_append_rel_size_compat(PlannerInfo *root, RelOptInfo *rel, Index rti)
6671
#else
6772
rel->width = rint(parent_size / parent_rows);
6873
#endif
74+
6975
rel->tuples = parent_rows;
7076
}
7177

72-
void
73-
adjust_targetlist_compat(PlannerInfo *root, RelOptInfo *dest,
74-
RelOptInfo *rel, AppendRelInfo *appinfo)
75-
{
76-
#if PG_VERSION_NUM >= 90600
77-
dest->reltarget->exprs = (List *)
78-
adjust_appendrel_attrs(root,
79-
(Node *) rel->reltarget->exprs,
80-
appinfo);
81-
#else
82-
dest->reltargetlist = (List *)
83-
adjust_appendrel_attrs(root,
84-
(Node *) rel->reltargetlist,
85-
appinfo);
86-
#endif
87-
}
78+
79+
/*
80+
* ----------
81+
* Variants
82+
* ----------
83+
*/
8884

8985
#if PG_VERSION_NUM >= 90600
86+
87+
9088
/*
9189
* make_result
9290
* Build a Result plan node
@@ -108,6 +106,7 @@ make_result(List *tlist,
108106
return node;
109107
}
110108

109+
111110
/*
112111
* If this relation could possibly be scanned from within a worker, then set
113112
* its consider_parallel flag.
@@ -256,6 +255,7 @@ set_rel_consider_parallel(PlannerInfo *root, RelOptInfo *rel,
256255
rel->consider_parallel = true;
257256
}
258257

258+
259259
/*
260260
* create_plain_partial_paths
261261
* Build partial access paths for parallel scan of a plain relation
@@ -320,6 +320,7 @@ create_plain_partial_paths(PlannerInfo *root, RelOptInfo *rel)
320320

321321
#else /* PG_VERSION_NUM >= 90500 */
322322

323+
323324
/*
324325
* set_dummy_rel_pathlist
325326
* Build a dummy path for a relation that's been excluded by constraints

src/hooks.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88
* ------------------------------------------------------------------------
99
*/
1010

11-
#include "utility_stmt_hooking.h"
11+
#include "compat/pg_compat.h"
12+
1213
#include "hooks.h"
1314
#include "init.h"
1415
#include "partition_filter.h"
15-
#include "pg_compat.h"
1616
#include "planner_tree_modification.h"
1717
#include "runtimeappend.h"
1818
#include "runtime_merge_append.h"
19+
#include "utility_stmt_hooking.h"
1920
#include "utils.h"
2021
#include "xact_handling.h"
2122

0 commit comments

Comments
 (0)