git.postgresql.org Git - postgresql.git/commitdiff

git projects / postgresql.git / commitdiff
? search:
summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: fd5a2db)
Fix busted Assert for CREATE MATVIEW ... WITH NO DATA.
2016年8月11日 15:22:25 +0000 (11:22 -0400)
2016年8月11日 15:22:25 +0000 (11:22 -0400)
Commit 874fe3aea changed the command tag returned for CREATE MATVIEW/CREATE
TABLE AS ... WITH NO DATA, but missed that there was code in spi.c that
expected the command tag to always be "SELECT". Fortunately, the
consequence was only an Assert failure, so this oversight should have no
impact in production builds.

Since this code path was evidently un-exercised, add a regression test.

Per report from Shivam Saxena. Back-patch to 9.3, like the previous commit.

Michael Paquier

Report: <97218716-480B-4527-B5CD-D08D798A0C7B@dresources.com>


diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c
index 7ccabdb44b2f5e2bbf5d4949c9f91eee13c4ff55..38de18006de49affdb79e63b5506a593e84b4088 100644 (file)
--- a/src/backend/executor/spi.c
+++ b/src/backend/executor/spi.c
@@ -2226,8 +2226,12 @@ _SPI_execute_plan(SPIPlanPtr plan, ParamListInfo paramLI,
pg_strtouint64(completionTag + 7, NULL, 10);
else
{
- /* Must be an IF NOT EXISTS that did nothing */
- Assert(ctastmt->if_not_exists);
+ /*
+ * Must be an IF NOT EXISTS that did nothing, or a
+ * CREATE ... WITH NO DATA.
+ */
+ Assert(ctastmt->if_not_exists ||
+ ctastmt->into->skipData);
_SPI_current->processed = 0;
}
diff --git a/src/test/regress/expected/matview.out b/src/test/regress/expected/matview.out
index 102bf1f155d0837a60dea714fe64460c249ae82e..e7d0ad1d86d1b2ccfa28a55614300ae3e1d8532d 100644 (file)
--- a/src/test/regress/expected/matview.out
+++ b/src/test/regress/expected/matview.out
@@ -557,3 +557,28 @@ REFRESH MATERIALIZED VIEW mvtest_mv_foo;
REFRESH MATERIALIZED VIEW CONCURRENTLY mvtest_mv_foo;
DROP OWNED BY regress_user_mvtest CASCADE;
DROP ROLE regress_user_mvtest;
+-- make sure that create WITH NO DATA works via SPI
+BEGIN;
+CREATE FUNCTION mvtest_func()
+ RETURNS void AS $$
+BEGIN
+ CREATE MATERIALIZED VIEW mvtest1 AS SELECT 1 AS x;
+ CREATE MATERIALIZED VIEW mvtest2 AS SELECT 1 AS x WITH NO DATA;
+END;
+$$ LANGUAGE plpgsql;
+SELECT mvtest_func();
+ mvtest_func
+-------------
+
+(1 row)
+
+SELECT * FROM mvtest1;
+ x
+---
+ 1
+(1 row)
+
+SELECT * FROM mvtest2;
+ERROR: materialized view "mvtest2" has not been populated
+HINT: Use the REFRESH MATERIALIZED VIEW command.
+ROLLBACK;
diff --git a/src/test/regress/sql/matview.sql b/src/test/regress/sql/matview.sql
index a108b6943dcad0c947234e00a3cf4d56eab3c004..5f3269def8a3558145d45fd1973c94e3bdcda161 100644 (file)
--- a/src/test/regress/sql/matview.sql
+++ b/src/test/regress/sql/matview.sql
@@ -226,3 +226,17 @@ REFRESH MATERIALIZED VIEW mvtest_mv_foo;
REFRESH MATERIALIZED VIEW CONCURRENTLY mvtest_mv_foo;
DROP OWNED BY regress_user_mvtest CASCADE;
DROP ROLE regress_user_mvtest;
+
+-- make sure that create WITH NO DATA works via SPI
+BEGIN;
+CREATE FUNCTION mvtest_func()
+ RETURNS void AS $$
+BEGIN
+ CREATE MATERIALIZED VIEW mvtest1 AS SELECT 1 AS x;
+ CREATE MATERIALIZED VIEW mvtest2 AS SELECT 1 AS x WITH NO DATA;
+END;
+$$ LANGUAGE plpgsql;
+SELECT mvtest_func();
+SELECT * FROM mvtest1;
+SELECT * FROM mvtest2;
+ROLLBACK;
This is the main PostgreSQL git repository.
RSS Atom

AltStyle によって変換されたページ (->オリジナル) /