Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9620cef

Browse files
committed
Merge branch 'rel_future_beta' into rel_future_copy_attributes
2 parents 96376f1 + 065cb70 commit 9620cef

35 files changed

+1049
-499
lines changed

.editorconfig

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[*]
2+
indent_style = tab
3+
indent_size = 4

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ regression.out
1212
pg_pathman--*.sql
1313
tags
1414
cscope*
15+
Dockerfile

.travis.yml

+18-23
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,28 @@
11
os:
2-
- linux
2+
- linux
33

44
sudo: required
55
dist: trusty
66

77
language: c
88

9-
compiler:
10-
- clang
11-
- gcc
9+
services:
10+
- docker
1211

13-
before_install:
14-
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get -y install -qq wget ca-certificates; fi
15-
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then source ./travis/dep-ubuntu-postgres.sh; fi
16-
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then source ./travis/dep-ubuntu-llvm.sh; fi
17-
- if [[ "$TRAVIS_OS_NAME" == "linux" ]]; then sudo apt-get update -qq; fi
12+
install:
13+
- sed -e 's/${CHECK_CODE}/'${CHECK_CODE}/g -e 's/${PG_VERSION}/'${PG_VERSION}/g Dockerfile.tmpl > Dockerfile
14+
- docker-compose build
1815

19-
env:
20-
global:
21-
- LLVM_VER=4.0
22-
matrix:
23-
- PG_VER=10 CHECK_CODE=true
24-
- PG_VER=10 CHECK_CODE=false
25-
- PG_VER=9.6 CHECK_CODE=true
26-
- PG_VER=9.6 CHECK_CODE=false
27-
- PG_VER=9.5 CHECK_CODE=true
28-
- PG_VER=9.5 CHECK_CODE=false
29-
30-
script: bash ./travis/pg-travis-test.sh
16+
script:
17+
- docker-compose run $(bash <(curl -s https://codecov.io/env)) tests
3118

32-
after_success:
33-
- bash <(curl -s https://codecov.io/bash)
19+
env:
20+
- PG_VERSION=10 CHECK_CODE=clang
21+
- PG_VERSION=9.6 CHECK_CODE=clang
22+
- PG_VERSION=9.5 CHECK_CODE=clang
23+
- PG_VERSION=10 CHECK_CODE=cppcheck
24+
- PG_VERSION=9.6 CHECK_CODE=cppcheck
25+
- PG_VERSION=9.5 CHECK_CODE=cppcheck
26+
- PG_VERSION=10 CHECK_CODE=false
27+
- PG_VERSION=9.6 CHECK_CODE=false
28+
- PG_VERSION=9.5 CHECK_CODE=false

Dockerfile.tmpl

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
FROM postgres:${PG_VERSION}-alpine
2+
3+
ENV LANG=C.UTF-8 PGDATA=/pg/data
4+
5+
RUN if [ "${CHECK_CODE}" = "clang" ] ; then \
6+
echo 'http://dl-3.alpinelinux.org/alpine/edge/main' > /etc/apk/repositories; \
7+
apk --no-cache add clang-analyzer make musl-dev gcc; \
8+
fi
9+
10+
RUN if [ "${CHECK_CODE}" = "cppcheck" ] ; then \
11+
apk --no-cache add cppcheck --repository http://dl-cdn.alpinelinux.org/alpine/v3.6/community; \
12+
fi
13+
14+
RUN if [ "${CHECK_CODE}" = "false" ] ; then \
15+
echo 'http://dl-3.alpinelinux.org/alpine/edge/main' > /etc/apk/repositories; \
16+
apk --no-cache add curl python3 gcc make musl-dev cmocka-dev;\
17+
pip3 install testgres; \
18+
fi
19+
20+
RUN mkdir -p /pg/data && \
21+
mkdir /pg/pg_pathman && \
22+
chown postgres:postgres ${PGDATA} && \
23+
chmod a+rwx /usr/local/lib/postgresql && \
24+
chmod a+rwx /usr/local/share/postgresql/extension
25+
26+
ADD . /pg/pg_pathman
27+
WORKDIR /pg/pg_pathman
28+
RUN chmod -R go+rwX /pg/pg_pathman
29+
USER postgres
30+
ENTRYPOINT PGDATA=${PGDATA} CHECK_CODE=${CHECK_CODE} bash run_tests.sh

Makefile

+8-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ OBJS = src/init.o src/relation_info.o src/utils.o src/partition_filter.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 \
99
src/planner_tree_modification.o src/debug_print.o src/partition_creation.o \
10-
src/compat/pg_compat.o src/compat/relation_tags.o src/compat/expand_rte_hook.o \
11-
src/compat/rowmarks_fix.o $(WIN32RES)
10+
src/compat/pg_compat.o src/compat/relation_tags.o src/compat/rowmarks_fix.o \
11+
$(WIN32RES)
1212

1313
override PG_CPPFLAGS += -I$(CURDIR)/src/include
1414

@@ -84,3 +84,9 @@ python_tests:
8484

8585
cmocka_tests:
8686
$(MAKE) -C tests/cmocka check
87+
88+
clean_gcov:
89+
find . \
90+
-name "*.gcda" -delete -o \
91+
-name "*.gcno" -delete -o \
92+
-name "*.gcov" -delete

docker-compose.yml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
tests:
2+
build: .

expected/pathman_basic.out

+31-3
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ PL/pgSQL function pathman.prepare_for_partitioning(regclass,text,boolean) line 9
1818
SQL statement "SELECT pathman.prepare_for_partitioning(parent_relid,
1919
expression,
2020
partition_data)"
21-
PL/pgSQL function pathman.create_hash_partitions(regclass,text,integer,boolean,text[],text[]) line 4 at PERFORM
21+
PL/pgSQL function pathman.create_hash_partitions(regclass,text,integer,boolean,text[],text[]) line 3 at PERFORM
2222
\set VERBOSITY terse
2323
ALTER TABLE test.hash_rel ALTER COLUMN value SET NOT NULL;
2424
SELECT pathman.create_hash_partitions('test.hash_rel', 'value', 3, partition_data:=false);
@@ -1685,7 +1685,7 @@ EXPLAIN (COSTS OFF) SELECT * FROM test.range_rel WHERE dt > '2010-12-15';
16851685
CREATE TABLE test.tmp (id INTEGER NOT NULL, value INTEGER NOT NULL);
16861686
INSERT INTO test.tmp VALUES (1, 1), (2, 2);
16871687
/* Test UPDATE and DELETE */
1688-
EXPLAIN (COSTS OFF) UPDATE test.range_rel SET value = 111 WHERE dt = '2010-06-15';
1688+
EXPLAIN (COSTS OFF) UPDATE test.range_rel SET value = 111 WHERE dt = '2010-06-15'; /* have partitions for this 'dt' */
16891689
QUERY PLAN
16901690
--------------------------------------------------------------------------------
16911691
Update on range_rel_6
@@ -1700,7 +1700,7 @@ SELECT * FROM test.range_rel WHERE dt = '2010-06-15';
17001700
166 | Tue Jun 15 00:00:00 2010 | 111
17011701
(1 row)
17021702

1703-
EXPLAIN (COSTS OFF) DELETE FROM test.range_rel WHERE dt = '2010-06-15';
1703+
EXPLAIN (COSTS OFF) DELETE FROM test.range_rel WHERE dt = '2010-06-15'; /* have partitions for this 'dt' */
17041704
QUERY PLAN
17051705
--------------------------------------------------------------------------------
17061706
Delete on range_rel_6
@@ -1714,6 +1714,34 @@ SELECT * FROM test.range_rel WHERE dt = '2010-06-15';
17141714
----+----+-------
17151715
(0 rows)
17161716

1717+
EXPLAIN (COSTS OFF) UPDATE test.range_rel SET value = 222 WHERE dt = '1990-01-01'; /* no partitions for this 'dt' */
1718+
QUERY PLAN
1719+
--------------------------------------------------------------------------------
1720+
Update on range_rel
1721+
-> Seq Scan on range_rel
1722+
Filter: (dt = 'Mon Jan 01 00:00:00 1990'::timestamp without time zone)
1723+
(3 rows)
1724+
1725+
UPDATE test.range_rel SET value = 111 WHERE dt = '1990-01-01';
1726+
SELECT * FROM test.range_rel WHERE dt = '1990-01-01';
1727+
id | dt | value
1728+
----+----+-------
1729+
(0 rows)
1730+
1731+
EXPLAIN (COSTS OFF) DELETE FROM test.range_rel WHERE dt < '1990-01-01'; /* no partitions for this 'dt' */
1732+
QUERY PLAN
1733+
--------------------------------------------------------------------------------
1734+
Delete on range_rel
1735+
-> Seq Scan on range_rel
1736+
Filter: (dt < 'Mon Jan 01 00:00:00 1990'::timestamp without time zone)
1737+
(3 rows)
1738+
1739+
DELETE FROM test.range_rel WHERE dt < '1990-01-01';
1740+
SELECT * FROM test.range_rel WHERE dt < '1990-01-01';
1741+
id | dt | value
1742+
----+----+-------
1743+
(0 rows)
1744+
17171745
EXPLAIN (COSTS OFF) UPDATE test.range_rel r SET value = t.value FROM test.tmp t WHERE r.dt = '2010-01-01' AND r.id = t.id;
17181746
QUERY PLAN
17191747
--------------------------------------------------------------------------------------------

expected/pathman_expressions.out

+6-6
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ PL/pgSQL function prepare_for_partitioning(regclass,text,boolean) line 9 at PERF
234234
SQL statement "SELECT public.prepare_for_partitioning(parent_relid,
235235
expression,
236236
partition_data)"
237-
PL/pgSQL function create_hash_partitions(regclass,text,integer,boolean,text[],text[]) line 4 at PERFORM
237+
PL/pgSQL function create_hash_partitions(regclass,text,integer,boolean,text[],text[]) line 3 at PERFORM
238238
/* Try using system attributes */
239239
SELECT create_hash_partitions('test_exprs.hash_rel', 'xmin', 4);
240240
ERROR: failed to analyze partitioning expression "xmin"
@@ -244,7 +244,7 @@ PL/pgSQL function prepare_for_partitioning(regclass,text,boolean) line 9 at PERF
244244
SQL statement "SELECT public.prepare_for_partitioning(parent_relid,
245245
expression,
246246
partition_data)"
247-
PL/pgSQL function create_hash_partitions(regclass,text,integer,boolean,text[],text[]) line 4 at PERFORM
247+
PL/pgSQL function create_hash_partitions(regclass,text,integer,boolean,text[],text[]) line 3 at PERFORM
248248
/* Try using subqueries */
249249
SELECT create_hash_partitions('test_exprs.hash_rel',
250250
'value, (select oid from pg_class limit 1)',
@@ -256,7 +256,7 @@ PL/pgSQL function prepare_for_partitioning(regclass,text,boolean) line 9 at PERF
256256
SQL statement "SELECT public.prepare_for_partitioning(parent_relid,
257257
expression,
258258
partition_data)"
259-
PL/pgSQL function create_hash_partitions(regclass,text,integer,boolean,text[],text[]) line 4 at PERFORM
259+
PL/pgSQL function create_hash_partitions(regclass,text,integer,boolean,text[],text[]) line 3 at PERFORM
260260
/* Try using mutable expression */
261261
SELECT create_hash_partitions('test_exprs.hash_rel', 'random()', 4);
262262
ERROR: failed to analyze partitioning expression "random()"
@@ -266,7 +266,7 @@ PL/pgSQL function prepare_for_partitioning(regclass,text,boolean) line 9 at PERF
266266
SQL statement "SELECT public.prepare_for_partitioning(parent_relid,
267267
expression,
268268
partition_data)"
269-
PL/pgSQL function create_hash_partitions(regclass,text,integer,boolean,text[],text[]) line 4 at PERFORM
269+
PL/pgSQL function create_hash_partitions(regclass,text,integer,boolean,text[],text[]) line 3 at PERFORM
270270
/* Try using broken parentheses */
271271
SELECT create_hash_partitions('test_exprs.hash_rel', 'value * value2))', 4);
272272
ERROR: failed to parse partitioning expression "value * value2))"
@@ -276,7 +276,7 @@ CONTEXT: PL/pgSQL function prepare_for_partitioning(regclass,text,boolean) line
276276
SQL statement "SELECT public.prepare_for_partitioning(parent_relid,
277277
expression,
278278
partition_data)"
279-
PL/pgSQL function create_hash_partitions(regclass,text,integer,boolean,text[],text[]) line 4 at PERFORM
279+
PL/pgSQL function create_hash_partitions(regclass,text,integer,boolean,text[],text[]) line 3 at PERFORM
280280
/* Try using missing columns */
281281
SELECT create_hash_partitions('test_exprs.hash_rel', 'value * value3', 4);
282282
ERROR: failed to analyze partitioning expression "value * value3"
@@ -287,7 +287,7 @@ CONTEXT: PL/pgSQL function prepare_for_partitioning(regclass,text,boolean) line
287287
SQL statement "SELECT public.prepare_for_partitioning(parent_relid,
288288
expression,
289289
partition_data)"
290-
PL/pgSQL function create_hash_partitions(regclass,text,integer,boolean,text[],text[]) line 4 at PERFORM
290+
PL/pgSQL function create_hash_partitions(regclass,text,integer,boolean,text[],text[]) line 3 at PERFORM
291291
/* Check that 'pathman_hooks_enabled' is true (1 partition in plan) */
292292
EXPLAIN (COSTS OFF) INSERT INTO test_exprs.canary_copy
293293
SELECT * FROM test_exprs.canary WHERE val = 1;

expected/pathman_rowmarks.out

+155
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
/*
2+
* -------------------------------------------
3+
* NOTE: This test behaves differenly on 9.5
4+
* -------------------------------------------
5+
*/
16
CREATE EXTENSION pg_pathman;
27
CREATE SCHEMA rowmarks;
38
CREATE TABLE rowmarks.first(id int NOT NULL);
@@ -168,6 +173,156 @@ FOR SHARE;
168173
6
169174
(1 row)
170175

176+
/* Check updates (plan) */
177+
SET enable_hashjoin = f; /* Hash Semi Join on 10 vs Hash Join on 9.6 */
178+
SET enable_mergejoin = f; /* Merge Semi Join on 10 vs Merge Join on 9.6 */
179+
EXPLAIN (COSTS OFF)
180+
UPDATE rowmarks.second SET id = 2
181+
WHERE rowmarks.second.id IN (SELECT id FROM rowmarks.first WHERE id = 1);
182+
QUERY PLAN
183+
---------------------------------------------
184+
Update on second
185+
-> Nested Loop Semi Join
186+
-> Seq Scan on second
187+
Filter: (id = 1)
188+
-> Materialize
189+
-> Append
190+
-> Seq Scan on first_0
191+
Filter: (id = 1)
192+
(8 rows)
193+
194+
EXPLAIN (COSTS OFF)
195+
UPDATE rowmarks.second SET id = 2
196+
WHERE rowmarks.second.id IN (SELECT id FROM rowmarks.first WHERE id < 1);
197+
QUERY PLAN
198+
-----------------------------------------------
199+
Update on second
200+
-> Nested Loop
201+
Join Filter: (second.id = first_0.id)
202+
-> HashAggregate
203+
Group Key: first_0.id
204+
-> Append
205+
-> Seq Scan on first_0
206+
Filter: (id < 1)
207+
-> Seq Scan on first_1
208+
Filter: (id < 1)
209+
-> Seq Scan on first_2
210+
Filter: (id < 1)
211+
-> Seq Scan on first_3
212+
Filter: (id < 1)
213+
-> Seq Scan on first_4
214+
Filter: (id < 1)
215+
-> Materialize
216+
-> Seq Scan on second
217+
(18 rows)
218+
219+
EXPLAIN (COSTS OFF)
220+
UPDATE rowmarks.second SET id = 2
221+
WHERE rowmarks.second.id IN (SELECT id FROM rowmarks.first WHERE id = 1 OR id = 2);
222+
QUERY PLAN
223+
-----------------------------------------------
224+
Update on second
225+
-> Nested Loop Semi Join
226+
Join Filter: (second.id = first_0.id)
227+
-> Seq Scan on second
228+
-> Materialize
229+
-> Append
230+
-> Seq Scan on first_0
231+
Filter: (id = 1)
232+
-> Seq Scan on first_1
233+
Filter: (id = 2)
234+
(10 rows)
235+
236+
EXPLAIN (COSTS OFF)
237+
UPDATE rowmarks.second SET id = 2
238+
WHERE rowmarks.second.id IN (SELECT id FROM rowmarks.first WHERE id = 1)
239+
RETURNING *, tableoid::regclass;
240+
QUERY PLAN
241+
---------------------------------------------
242+
Update on second
243+
-> Nested Loop Semi Join
244+
-> Seq Scan on second
245+
Filter: (id = 1)
246+
-> Materialize
247+
-> Append
248+
-> Seq Scan on first_0
249+
Filter: (id = 1)
250+
(8 rows)
251+
252+
SET enable_hashjoin = t;
253+
SET enable_mergejoin = t;
254+
/* Check updates (execution) */
255+
UPDATE rowmarks.second SET id = 1
256+
WHERE rowmarks.second.id IN (SELECT id FROM rowmarks.first WHERE id = 1 OR id = 2)
257+
RETURNING *, tableoid::regclass;
258+
id | tableoid
259+
----+-----------------
260+
1 | rowmarks.second
261+
1 | rowmarks.second
262+
(2 rows)
263+
264+
/* Check deletes (plan) */
265+
SET enable_hashjoin = f; /* Hash Semi Join on 10 vs Hash Join on 9.6 */
266+
SET enable_mergejoin = f; /* Merge Semi Join on 10 vs Merge Join on 9.6 */
267+
EXPLAIN (COSTS OFF)
268+
DELETE FROM rowmarks.second
269+
WHERE rowmarks.second.id IN (SELECT id FROM rowmarks.first WHERE id = 1);
270+
QUERY PLAN
271+
---------------------------------------------
272+
Delete on second
273+
-> Nested Loop Semi Join
274+
-> Seq Scan on second
275+
Filter: (id = 1)
276+
-> Materialize
277+
-> Append
278+
-> Seq Scan on first_0
279+
Filter: (id = 1)
280+
(8 rows)
281+
282+
EXPLAIN (COSTS OFF)
283+
DELETE FROM rowmarks.second
284+
WHERE rowmarks.second.id IN (SELECT id FROM rowmarks.first WHERE id < 1);
285+
QUERY PLAN
286+
-----------------------------------------------
287+
Delete on second
288+
-> Nested Loop
289+
Join Filter: (second.id = first_0.id)
290+
-> HashAggregate
291+
Group Key: first_0.id
292+
-> Append
293+
-> Seq Scan on first_0
294+
Filter: (id < 1)
295+
-> Seq Scan on first_1
296+
Filter: (id < 1)
297+
-> Seq Scan on first_2
298+
Filter: (id < 1)
299+
-> Seq Scan on first_3
300+
Filter: (id < 1)
301+
-> Seq Scan on first_4
302+
Filter: (id < 1)
303+
-> Materialize
304+
-> Seq Scan on second
305+
(18 rows)
306+
307+
EXPLAIN (COSTS OFF)
308+
DELETE FROM rowmarks.second
309+
WHERE rowmarks.second.id IN (SELECT id FROM rowmarks.first WHERE id = 1 OR id = 2);
310+
QUERY PLAN
311+
-----------------------------------------------
312+
Delete on second
313+
-> Nested Loop Semi Join
314+
Join Filter: (second.id = first_0.id)
315+
-> Seq Scan on second
316+
-> Materialize
317+
-> Append
318+
-> Seq Scan on first_0
319+
Filter: (id = 1)
320+
-> Seq Scan on first_1
321+
Filter: (id = 2)
322+
(10 rows)
323+
324+
SET enable_hashjoin = t;
325+
SET enable_mergejoin = t;
171326
DROP SCHEMA rowmarks CASCADE;
172327
NOTICE: drop cascades to 7 other objects
173328
DETAIL: drop cascades to table rowmarks.first

0 commit comments

Comments
 (0)