@@ -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 */
11141114CREATE TABLE test.cte_del_xacts (id BIGSERIAL PRIMARY KEY, pdate DATE NOT NULL);
11151115INSERT 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
11201120state_code SMALLINT NOT NULL DEFAULT 8,
11211121regtime 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 */
11241125SELECT pathman.create_range_partitions('test.cte_del_xacts'::regclass, 'pdate', '2016-01-01'::date, '50 days'::interval);
11251126NOTICE: 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);
12411272DROP TABLE test.cte_del_xacts, test.cte_del_xacts_specdata CASCADE;
12421273NOTICE: drop cascades to table test.cte_del_xacts_1
12431274/*