Skip to content

Commit fc9d807

Browse files
committed
add CTE test involving pl/pgsql function
1 parent 216b4da commit fc9d807

File tree

2 files changed

+57
-2
lines changed

2 files changed

+57
-2
lines changed

expected/pathman_basic.out

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,7 @@ SELECT * FROM ttt;
11091109
(5 rows)
11101110

11111111
/*
1112-
* Test CTE query (DELETE) - by @parihaaraka (add varno to WalkerContext)
1112+
* Test CTE query - by @parihaaraka (add varno to WalkerContext)
11131113
*/
11141114
CREATE TABLE test.cte_del_xacts (id BIGSERIAL PRIMARY KEY, pdate DATE NOT NULL);
11151115
INSERT INTO test.cte_del_xacts (pdate) SELECT gen_date FROM generate_series('2016-01-01'::date, '2016-04-9'::date, '1 day') AS gen_date;
@@ -1120,6 +1120,7 @@ create table test.cte_del_xacts_specdata
11201120
state_code SMALLINT NOT NULL DEFAULT 8,
11211121
regtime TIMESTAMP WITHOUT TIME ZONE NOT NULL
11221122
);
1123+
INSERT INTO test.cte_del_xacts_specdata VALUES(1, 1, 1, current_timestamp); /* for subquery test */
11231124
/* create 2 partitions */
11241125
SELECT pathman.create_range_partitions('test.cte_del_xacts'::regclass, 'pdate', '2016-01-01'::date, '50 days'::interval);
11251126
NOTICE: sequence "cte_del_xacts_seq" does not exist, skipping
@@ -1238,6 +1239,36 @@ WHERE t.id = tmp.tid AND t.pdate = tmp.pdate AND tmp.test_mode > 0;
12381239
-> Index Scan using cte_del_xacts_1_pkey on cte_del_xacts_1 t
12391240
(9 rows)
12401241

1242+
/* create stub pl/PgSQL function */
1243+
CREATE OR REPLACE FUNCTION test.cte_del_xacts_stab(name TEXT)
1244+
RETURNS smallint AS
1245+
$$
1246+
begin
1247+
return 2::smallint;
1248+
end
1249+
$$
1250+
LANGUAGE plpgsql STABLE;
1251+
/* test subquery planning */
1252+
WITH tmp AS (
1253+
SELECT tid FROM test.cte_del_xacts_specdata
1254+
WHERE state_code != test.cte_del_xacts_stab('test'))
1255+
SELECT * FROM test.cte_del_xacts t JOIN tmp ON t.id = tmp.tid;
1256+
id | pdate | tid
1257+
----+------------+-----
1258+
1 | 01-01-2016 | 1
1259+
(1 row)
1260+
1261+
/* test subquery planning (one more time) */
1262+
WITH tmp AS (
1263+
SELECT tid FROM test.cte_del_xacts_specdata
1264+
WHERE state_code != test.cte_del_xacts_stab('test'))
1265+
SELECT * FROM test.cte_del_xacts t JOIN tmp ON t.id = tmp.tid;
1266+
id | pdate | tid
1267+
----+------------+-----
1268+
1 | 01-01-2016 | 1
1269+
(1 row)
1270+
1271+
DROP FUNCTION test.cte_del_xacts_stab(TEXT);
12411272
DROP TABLE test.cte_del_xacts, test.cte_del_xacts_specdata CASCADE;
12421273
NOTICE: drop cascades to table test.cte_del_xacts_1
12431274
/*

sql/pathman_basic.sql

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ SELECT * FROM ttt;
277277

278278

279279
/*
280-
* Test CTE query (DELETE) - by @parihaaraka (add varno to WalkerContext)
280+
* Test CTE query - by @parihaaraka (add varno to WalkerContext)
281281
*/
282282
CREATE TABLE test.cte_del_xacts (id BIGSERIAL PRIMARY KEY, pdate DATE NOT NULL);
283283
INSERT INTO test.cte_del_xacts (pdate) SELECT gen_date FROM generate_series('2016-01-01'::date, '2016-04-9'::date, '1 day') AS gen_date;
@@ -289,6 +289,7 @@ create table test.cte_del_xacts_specdata
289289
state_code SMALLINT NOT NULL DEFAULT 8,
290290
regtime TIMESTAMP WITHOUT TIME ZONE NOT NULL
291291
);
292+
INSERT INTO test.cte_del_xacts_specdata VALUES(1, 1, 1, current_timestamp); /* for subquery test */
292293

293294
/* create 2 partitions */
294295
SELECT pathman.create_range_partitions('test.cte_del_xacts'::regclass, 'pdate', '2016-01-01'::date, '50 days'::interval);
@@ -323,6 +324,29 @@ WITH tmp AS (
323324
DELETE FROM test.cte_del_xacts t USING tmp
324325
WHERE t.id = tmp.tid AND t.pdate = tmp.pdate AND tmp.test_mode > 0;
325326

327+
/* create stub pl/PgSQL function */
328+
CREATE OR REPLACE FUNCTION test.cte_del_xacts_stab(name TEXT)
329+
RETURNS smallint AS
330+
$$
331+
begin
332+
return 2::smallint;
333+
end
334+
$$
335+
LANGUAGE plpgsql STABLE;
336+
337+
/* test subquery planning */
338+
WITH tmp AS (
339+
SELECT tid FROM test.cte_del_xacts_specdata
340+
WHERE state_code != test.cte_del_xacts_stab('test'))
341+
SELECT * FROM test.cte_del_xacts t JOIN tmp ON t.id = tmp.tid;
342+
343+
/* test subquery planning (one more time) */
344+
WITH tmp AS (
345+
SELECT tid FROM test.cte_del_xacts_specdata
346+
WHERE state_code != test.cte_del_xacts_stab('test'))
347+
SELECT * FROM test.cte_del_xacts t JOIN tmp ON t.id = tmp.tid;
348+
349+
DROP FUNCTION test.cte_del_xacts_stab(TEXT);
326350
DROP TABLE test.cte_del_xacts, test.cte_del_xacts_specdata CASCADE;
327351

328352

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy