@@ -1109,7 +1109,7 @@ SELECT * FROM ttt;
1109
1109
(5 rows)
1110
1110
1111
1111
/*
1112
- * Test CTE query (DELETE) - by @parihaaraka (add varno to WalkerContext)
1112
+ * Test CTE query - by @parihaaraka (add varno to WalkerContext)
1113
1113
*/
1114
1114
CREATE TABLE test.cte_del_xacts (id BIGSERIAL PRIMARY KEY, pdate DATE NOT NULL);
1115
1115
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
1120
1120
state_code SMALLINT NOT NULL DEFAULT 8,
1121
1121
regtime TIMESTAMP WITHOUT TIME ZONE NOT NULL
1122
1122
);
1123
+ INSERT INTO test.cte_del_xacts_specdata VALUES(1, 1, 1, current_timestamp); /* for subquery test */
1123
1124
/* create 2 partitions */
1124
1125
SELECT pathman.create_range_partitions('test.cte_del_xacts'::regclass, 'pdate', '2016-01-01'::date, '50 days'::interval);
1125
1126
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;
1238
1239
-> Index Scan using cte_del_xacts_1_pkey on cte_del_xacts_1 t
1239
1240
(9 rows)
1240
1241
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);
1241
1272
DROP TABLE test.cte_del_xacts, test.cte_del_xacts_specdata CASCADE;
1242
1273
NOTICE: drop cascades to table test.cte_del_xacts_1
1243
1274
/*
0 commit comments