pg.ddx.io pgsql-bugs@postgresql.org mailing list archive
help / color / mirror / Atom feedBUG: Session getting disconnected while executing a function to create materialised views in PostgreSQL 9.6
8+ messages / 4 participants
[nested] [flat]
* BUG: Session getting disconnected while executing a function to create materialised views in PostgreSQL 9.6
@ 2016-08-11 09:30 Saxena, Shivam <shsaxena@teamdrg.com>
0 siblings, 1 reply; 8+ messages in thread
From: Saxena, Shivam @ 2016-08-11 09:30 UTC (permalink / raw)
To: pgsql-bugs; +Cc: DB Development DBAs <DBDevelopmentDBAs@teamdrg.com>; Lee, Ming <milee@teamdrg.com>
Dear Team,
While creating a 9.6 database environment we have come across a situation where the session is getting disconnected while running a function. Below are the DB details and function details.
DB Version: PostgreSQL 9.6beta3 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-17), 64-bit
DB Client: PgAdmin 3 v1.22.1
DB Client Operating System: Mac OS v10.11.3
DB Function definition (sample test function to replicate the issue):-
CREATE OR REPLACE FUNCTION testing_func()
RETURNS void AS $$
BEGIN
DROP MATERIALIZED VIEW IF EXISTS test1;
CREATE MATERIALIZED VIEW test1 AS
(
SELECT 1 as a,2 as b,3 as c,4 as d,5 as e,6 as f
ORDER BY
1
) WITH NO DATA;
END;
$$ LANGUAGE plpgsql;
Replication Scenario:
* Compile the above code. Run select query of the above function (I.e. Select testing_func();)
Result:
* Session gets disconnected forcibly.
Few other observations:
* The same code snippet runs fine in PostreSQL v9.5
* When we remove the clause WITH NO DATA, then the functions runs successfully
Please let me know in case any more details are required from our side.
Regards,
Shivam Saxena
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: BUG: Session getting disconnected while executing a function to create materialised views in PostgreSQL 9.6
@ 2016-08-11 12:10 Michael Paquier <michael.paquier@gmail.com>
parent: Saxena, Shivam <shsaxena@teamdrg.com>
0 siblings, 1 reply; 8+ messages in thread
From: Michael Paquier @ 2016-08-11 12:10 UTC (permalink / raw)
To: Saxena, Shivam <shsaxena@teamdrg.com>; +Cc: pgsql-bugs; DB Development DBAs <DBDevelopmentDBAs@teamdrg.com>; Lee, Ming <milee@teamdrg.com>
On Thu, Aug 11, 2016 at 6:30 PM, Saxena, Shivam <shsaxena@teamdrg.com> wrote:
> While creating a 9.6 database environment we have come across a situation
> where the session is getting disconnected while running a function. Below
> are the DB details and function details.
Thanks for the report!
> Few other observations:
>
> The same code snippet runs fine in PostreSQL v9.5
> When we remove the clause WITH NO DATA, then the functions runs successfully
9.5.4 and other is impacted as well by this crash, down to 9.3, and
this is an oversight of 1651b9aa that made a matview query with WITH
NO DATA not run the parser/planner when executed. spi.c has a special
handling for CTAS, and this query runs into that, so any such query
executed through the SPI is going to crash on that:
(lldb) up 1
frame #4: 0x0000000105986dde
postgres`_SPI_execute_plan(plan=0x00007f9ff383c038,
paramLI=0x0000000000000000, snapshot=0x0000000000000000,
crosscheck_snapshot=0x0000000000000000, read_only='\0',
fire_triggers='\x01', tcount=0) + 1902 at spi.c:2228
2225 else
2226 {
2227 /* Must be an IF NOT EXISTS that
did nothing */
-> 2228 Assert(ctastmt->if_not_exists);
2229 _SPI_current->processed = 0;
2230 }
2231
(lldb) p *ctastmt
(CreateTableAsStmt) $1 = {
type = T_CreateTableAsStmt
query = 0x00007f9ff385e4d0
into = 0x00007f9ff3868ef0
relkind = OBJECT_MATVIEW
is_select_into = '\0'
if_not_exists = '\0'
}
I'll produce a patch in the worst case by tomorrow morning my time.
--
Michael
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: BUG: Session getting disconnected while executing a function to create materialised views in PostgreSQL 9.6
@ 2016-08-11 13:09 Michael Paquier <michael.paquier@gmail.com>
parent: Michael Paquier <michael.paquier@gmail.com>
0 siblings, 3 replies; 8+ messages in thread
From: Michael Paquier @ 2016-08-11 13:09 UTC (permalink / raw)
To: Saxena, Shivam <shsaxena@teamdrg.com>; +Cc: pgsql-bugs; DB Development DBAs <DBDevelopmentDBAs@teamdrg.com>; Lee, Ming <milee@teamdrg.com>
On Thu, Aug 11, 2016 at 9:10 PM, Michael Paquier
<michael.paquier@gmail.com> wrote:
> I'll produce a patch in the worst case by tomorrow morning my time.
And attached is the patch. I arrived at the conclusion that the
assertion being broken here just needs to be relaxed a bit so as it
understands that this code path can be taken by a matview WITH NO
DATA. I have bundled a regression test as well. This should be
backpatched down to 9.3.
--
Michael
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Attachments:
matview-func-fix.patch (application/x-download, 2.2K) download
diff --git a/src/backend/executor/spi.c b/src/backend/executor/spi.c
index 7ccabdb..3c2f2bb 100644
--- a/src/backend/executor/spi.c
+++ b/src/backend/executor/spi.c
@@ -2226,8 +2226,13 @@ _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
+ * MATERIALIZED VIEW WITH NO DATA.
+ */
+ Assert(ctastmt->if_not_exists ||
+ (ctastmt->relkind == OBJECT_MATVIEW &&
+ ctastmt->into->skipData));
_SPI_current->processed = 0;
}
diff --git a/src/test/regress/expected/matview.out b/src/test/regress/expected/matview.out
index 102bf1f..65635b4 100644
--- a/src/test/regress/expected/matview.out
+++ b/src/test/regress/expected/matview.out
@@ -557,3 +557,19 @@ 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 in functions
+CREATE OR REPLACE FUNCTION mvtest_func()
+ RETURNS void AS $$
+BEGIN
+ CREATE MATERIALIZED VIEW mvtest AS SELECT 1;
+ CREATE MATERIALIZED VIEW mvtest2 AS SELECT 1 WITH NO DATA;
+ END;
+$$ LANGUAGE plpgsql;
+SELECT mvtest_func();
+ mvtest_func
+-------------
+
+(1 row)
+
+DROP MATERIALIZED VIEW mvtest;
+DROP MATERIALIZED VIEW mvtest2;
diff --git a/src/test/regress/sql/matview.sql b/src/test/regress/sql/matview.sql
index a108b69..6fc2d33 100644
--- a/src/test/regress/sql/matview.sql
+++ b/src/test/regress/sql/matview.sql
@@ -226,3 +226,15 @@ 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 in functions
+CREATE OR REPLACE FUNCTION mvtest_func()
+ RETURNS void AS $$
+BEGIN
+ CREATE MATERIALIZED VIEW mvtest AS SELECT 1;
+ CREATE MATERIALIZED VIEW mvtest2 AS SELECT 1 WITH NO DATA;
+ END;
+$$ LANGUAGE plpgsql;
+SELECT mvtest_func();
+DROP MATERIALIZED VIEW mvtest;
+DROP MATERIALIZED VIEW mvtest2;
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: BUG: Session getting disconnected while executing a function to create materialised views in PostgreSQL 9.6
@ 2016-08-11 13:21 Andrew Gierth <andrew@tao11.riddles.org.uk>
parent: Michael Paquier <michael.paquier@gmail.com>
2 siblings, 1 reply; 8+ messages in thread
From: Andrew Gierth @ 2016-08-11 13:21 UTC (permalink / raw)
To: Michael Paquier <michael.paquier@gmail.com>; +Cc: Saxena\, Shivam <shsaxena@teamdrg.com>; pgsql-bugs; DB Development DBAs <DBDevelopmentDBAs@teamdrg.com>; Lee\, Ming <milee@teamdrg.com>
>>>>> "Michael" == Michael Paquier <michael.paquier@gmail.com> writes:
>> I'll produce a patch in the worst case by tomorrow morning my time.
Michael> And attached is the patch. I arrived at the conclusion that
Michael> the assertion being broken here just needs to be relaxed a bit
Michael> so as it understands that this code path can be taken by a
Michael> matview WITH NO DATA. I have bundled a regression test as
Michael> well. This should be backpatched down to 9.3.
Might it make sense in the regression test to check that ROW_COUNT ends
up correctly set?
--
Andrew (irc:RhodiumToad)
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: BUG: Session getting disconnected while executing a function to create materialised views in PostgreSQL 9.6
@ 2016-08-11 13:33 Michael Paquier <michael.paquier@gmail.com>
parent: Andrew Gierth <andrew@tao11.riddles.org.uk>
0 siblings, 0 replies; 8+ messages in thread
From: Michael Paquier @ 2016-08-11 13:33 UTC (permalink / raw)
To: Andrew Gierth <andrew@tao11.riddles.org.uk>; +Cc: Saxena, Shivam <shsaxena@teamdrg.com>; pgsql-bugs; DB Development DBAs <DBDevelopmentDBAs@teamdrg.com>; Lee, Ming <milee@teamdrg.com>
On Thu, Aug 11, 2016 at 10:21 PM, Andrew Gierth
<andrew@tao11.riddles.org.uk> wrote:
>>>>>> "Michael" == Michael Paquier <michael.paquier@gmail.com> writes:
>
> >> I'll produce a patch in the worst case by tomorrow morning my time.
>
> Michael> And attached is the patch. I arrived at the conclusion that
> Michael> the assertion being broken here just needs to be relaxed a bit
> Michael> so as it understands that this code path can be taken by a
> Michael> matview WITH NO DATA. I have bundled a regression test as
> Michael> well. This should be backpatched down to 9.3.
>
> Might it make sense in the regression test to check that ROW_COUNT ends
> up correctly set?
I didn't think that this was necessary, the existence of the relations
being a sufficient guarantee.
--
Michael
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: BUG: Session getting disconnected while executing a function to create materialised views in PostgreSQL 9.6
@ 2016-08-11 14:04 Tom Lane <tgl@sss.pgh.pa.us>
parent: Michael Paquier <michael.paquier@gmail.com>
2 siblings, 0 replies; 8+ messages in thread
From: Tom Lane @ 2016-08-11 14:04 UTC (permalink / raw)
To: Michael Paquier <michael.paquier@gmail.com>; +Cc: Saxena, Shivam <shsaxena@teamdrg.com>; pgsql-bugs; DB Development DBAs <DBDevelopmentDBAs@teamdrg.com>; Lee, Ming <milee@teamdrg.com>
Michael Paquier <michael.paquier@gmail.com> writes:
> And attached is the patch. I arrived at the conclusion that the
> assertion being broken here just needs to be relaxed a bit so as it
> understands that this code path can be taken by a matview WITH NO
> DATA.
Man, that looks familiar. Didn't we fix a similar oversight somewhere
else, not long ago? Wonder if there are more. But a quick grep for
if_not_exists doesn't find anything, so I'm not quite sure what I'm
half-remembering ...
regards, tom lane
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: BUG: Session getting disconnected while executing a function to create materialised views in PostgreSQL 9.6
@ 2016-08-11 15:24 Tom Lane <tgl@sss.pgh.pa.us>
parent: Michael Paquier <michael.paquier@gmail.com>
2 siblings, 1 reply; 8+ messages in thread
From: Tom Lane @ 2016-08-11 15:24 UTC (permalink / raw)
To: Michael Paquier <michael.paquier@gmail.com>; +Cc: Saxena, Shivam <shsaxena@teamdrg.com>; pgsql-bugs; DB Development DBAs <DBDevelopmentDBAs@teamdrg.com>; Lee, Ming <milee@teamdrg.com>
Michael Paquier <michael.paquier@gmail.com> writes:
> And attached is the patch. I arrived at the conclusion that the
> assertion being broken here just needs to be relaxed a bit so as it
> understands that this code path can be taken by a matview WITH NO
> DATA. I have bundled a regression test as well. This should be
> backpatched down to 9.3.
Pushed. The Assert was still a bit too strong: as you had it, it
still crashed on CREATE TABLE AS ... WITH NO DATA.
regards, tom lane
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 8+ messages in thread
* Re: BUG: Session getting disconnected while executing a function to create materialised views in PostgreSQL 9.6
@ 2016-08-11 23:09 Michael Paquier <michael.paquier@gmail.com>
parent: Tom Lane <tgl@sss.pgh.pa.us>
0 siblings, 0 replies; 8+ messages in thread
From: Michael Paquier @ 2016-08-11 23:09 UTC (permalink / raw)
To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: Saxena, Shivam <shsaxena@teamdrg.com>; pgsql-bugs; DB Development DBAs <DBDevelopmentDBAs@teamdrg.com>; Lee, Ming <milee@teamdrg.com>
On Fri, Aug 12, 2016 at 12:24 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Michael Paquier <michael.paquier@gmail.com> writes:
>> And attached is the patch. I arrived at the conclusion that the
>> assertion being broken here just needs to be relaxed a bit so as it
>> understands that this code path can be taken by a matview WITH NO
>> DATA. I have bundled a regression test as well. This should be
>> backpatched down to 9.3.
>
> Pushed. The Assert was still a bit too strong: as you had it, it
> still crashed on CREATE TABLE AS ... WITH NO DATA.
Thanks, I missed this point. Hacking at night is never good..
--
Michael
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
^ permalink raw reply [nested|flat] 8+ messages in thread
end of thread, other threads:[~2016-08-11 23:09 UTC | newest]
Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2016-08-11 09:30 BUG: Session getting disconnected while executing a function to create materialised views in PostgreSQL 9.6 Saxena, Shivam <shsaxena@teamdrg.com>
2016-08-11 12:10 ` Michael Paquier <michael.paquier@gmail.com>
2016-08-11 13:09 ` Michael Paquier <michael.paquier@gmail.com>
2016-08-11 13:21 ` Andrew Gierth <andrew@tao11.riddles.org.uk>
2016-08-11 13:33 ` Michael Paquier <michael.paquier@gmail.com>
2016-08-11 14:04 ` Tom Lane <tgl@sss.pgh.pa.us>
2016-08-11 15:24 ` Tom Lane <tgl@sss.pgh.pa.us>
2016-08-11 23:09 ` Michael Paquier <michael.paquier@gmail.com>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox