Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit894993f

Browse files
committed
Fix busted Assert for CREATE MATVIEW ... WITH NO DATA.
Commit874fe3a changed the command tag returned for CREATE MATVIEW/CREATETABLE AS ... WITH NO DATA, but missed that there was code in spi.c thatexpected the command tag to always be "SELECT". Fortunately, theconsequence was only an Assert failure, so this oversight should have noimpact 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 PaquierReport: <97218716-480B-4527-B5CD-D08D798A0C7B@dresources.com>
1 parenta470858 commit894993f

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

‎src/backend/executor/spi.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2224,8 +2224,12 @@ _SPI_execute_plan(SPIPlanPtr plan, ParamListInfo paramLI,
22242224
strtoul(completionTag+7,NULL,10);
22252225
else
22262226
{
2227-
/* Must be an IF NOT EXISTS that did nothing */
2228-
Assert(ctastmt->if_not_exists);
2227+
/*
2228+
* Must be an IF NOT EXISTS that did nothing, or a
2229+
* CREATE ... WITH NO DATA.
2230+
*/
2231+
Assert(ctastmt->if_not_exists||
2232+
ctastmt->into->skipData);
22292233
_SPI_current->processed=0;
22302234
}
22312235

‎src/test/regress/expected/matview.out

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,3 +557,28 @@ REFRESH MATERIALIZED VIEW mv_foo;
557557
REFRESH MATERIALIZED VIEW CONCURRENTLY mv_foo;
558558
DROP OWNED BY user_dw CASCADE;
559559
DROP ROLE user_dw;
560+
-- make sure that create WITH NO DATA works via SPI
561+
BEGIN;
562+
CREATE FUNCTION mvtest_func()
563+
RETURNS void AS $$
564+
BEGIN
565+
CREATE MATERIALIZED VIEW mvtest1 AS SELECT 1 AS x;
566+
CREATE MATERIALIZED VIEW mvtest2 AS SELECT 1 AS x WITH NO DATA;
567+
END;
568+
$$ LANGUAGE plpgsql;
569+
SELECT mvtest_func();
570+
mvtest_func
571+
-------------
572+
573+
(1 row)
574+
575+
SELECT * FROM mvtest1;
576+
x
577+
---
578+
1
579+
(1 row)
580+
581+
SELECT * FROM mvtest2;
582+
ERROR: materialized view "mvtest2" has not been populated
583+
HINT: Use the REFRESH MATERIALIZED VIEW command.
584+
ROLLBACK;

‎src/test/regress/sql/matview.sql

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,3 +226,17 @@ REFRESH MATERIALIZED VIEW mv_foo;
226226
REFRESH MATERIALIZED VIEW CONCURRENTLY mv_foo;
227227
DROP OWNED BY user_dw CASCADE;
228228
DROP ROLE user_dw;
229+
230+
-- make sure that create WITH NO DATA works via SPI
231+
BEGIN;
232+
CREATEFUNCTIONmvtest_func()
233+
RETURNS voidAS $$
234+
BEGIN
235+
CREATE MATERIALIZED VIEW mvtest1ASSELECT1AS x;
236+
CREATE MATERIALIZED VIEW mvtest2ASSELECT1AS x WITH NO DATA;
237+
END;
238+
$$ LANGUAGE plpgsql;
239+
SELECT mvtest_func();
240+
SELECT*FROM mvtest1;
241+
SELECT*FROM mvtest2;
242+
ROLLBACK;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp