pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #8606: Materialized View WITH NO DATA bug
6+ messages / 4 participants
[nested] [flat]

* BUG #8606: Materialized View WITH NO DATA bug
@ 2013-11-19 15:35  j.rejda@konektel.cz
  0 siblings, 1 reply; 6+ messages in thread

From: j.rejda@konektel.cz @ 2013-11-19 15:35 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      8606
Logged by:          Jaroslav Rejda
Email address:      j.rejda@konektel.cz
PostgreSQL version: 9.3.1
Operating system:   MS Windows XP SP3
Description:        

-- Hi,
-- please, check this example:


-- simple table
CREATE TABLE test (cislo integer);
INSERT INTO test VALUES (10);


-- immutable "long time" math func
CREATE FUNCTION long_test(_n bigint)
  RETURNS bigint AS
$BODY$DECLARE
  _result bigint := 0;
  _i bigint := 2;
BEGIN
  _n := !! _n;
  WHILE _i < _n LOOP
    IF _n % _i = 0 THEN
      _result := _result + 1;
    END IF;
    _i := _i + 1;
  END LOOP;
  RETURN _result;
END;$BODY$
  LANGUAGE plpgsql IMMUTABLE STRICT
  COST 100;


-- this returns "immediately"
CREATE MATERIALIZED VIEW test1 AS SELECT long_test(cislo) FROM test WITH NO
DATA;


-- this returns "after some time" (as long as normal "SELECT long_test(10);"
do)
CREATE MATERIALIZED VIEW test2 AS SELECT long_test(10) WITH NO DATA;


-- it's ok or bug?
-- Thanks ... JR



-- 
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] 6+ messages in thread

* Re: BUG #8606: Materialized View WITH NO DATA bug
@ 2013-11-19 22:46  Kevin Grittner <kgrittn@ymail.com>
  parent: j.rejda@konektel.cz
  0 siblings, 1 reply; 6+ messages in thread

From: Kevin Grittner @ 2013-11-19 22:46 UTC (permalink / raw)
  To: j.rejda@konektel.cz <j.rejda@konektel.cz>; pgsql-bugs

"j.rejda@konektel.cz" <j.rejda@konektel.cz> wrote:

> -- simple table
> CREATE TABLE test (cislo integer);
> INSERT INTO test VALUES (10);
>
> -- immutable "long time" math func
> CREATE FUNCTION long_test(_n bigint)
>   RETURNS bigint AS
> $BODY$DECLARE
>   _result bigint := 0;
>   _i bigint := 2;
> BEGIN
>   _n := !! _n;
>   WHILE _i < _n LOOP
>     IF _n % _i = 0 THEN
>       _result := _result + 1;
>     END IF;
>     _i := _i + 1;
>   END LOOP;
>   RETURN _result;
> END;$BODY$
>   LANGUAGE plpgsql IMMUTABLE STRICT
>   COST 100;
>
> -- this returns "immediately"
> CREATE MATERIALIZED VIEW test1 AS
>   SELECT long_test(cislo) FROM test WITH NO DATA;
>
> -- this returns "after some time" (as long as normal "SELECT
> long_test(10);"
> do)
> CREATE MATERIALIZED VIEW test2 AS
>   SELECT long_test(10) WITH NO DATA;
>
> -- it's ok or bug?

It's not a bug in the sense that it crashes or returns an incorrect
result, but it may be an opportunity for a performance enhancement.

FWIW, CREATE TABLE AS has the same behavior.  Just replace
MATERIALIZED VIEW in your examples with TABLE to see it.

--
Kevin Grittner
EDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
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] 6+ messages in thread

* Re: BUG #8606: Materialized View WITH NO DATA bug
@ 2013-11-20 03:49  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Kevin Grittner <kgrittn@ymail.com>
  0 siblings, 2 replies; 6+ messages in thread

From: Tom Lane @ 2013-11-20 03:49 UTC (permalink / raw)
  To: Kevin Grittner <kgrittn@ymail.com>; +Cc: j.rejda@konektel.cz <j.rejda@konektel.cz>; pgsql-bugs

Kevin Grittner <kgrittn@ymail.com> writes:
> "j.rejda@konektel.cz" <j.rejda@konektel.cz> wrote:
>> -- this returns "after some time" (as long as normal "SELECT
>> long_test(10);"
>> do)
>> CREATE MATERIALIZED VIEW test2 AS
>>    SELECT long_test(10) WITH NO DATA;
>> 
>> -- it's ok or bug?

> It's not a bug in the sense that it crashes or returns an incorrect
> result, but it may be an opportunity for a performance enhancement.

Meh.  I'm not sure this can be considered to be a problem.  One of
the implications of marking a function immutable is that it has no
side-effects worthy of concern; otherwise, it wouldn't be safe for
the planner to constant-fold it, which is pretty much the whole point
of immutability.  But if you're concerned about how long it takes to
evaluate, that's a kind of side effect, IMHO.  Maybe it'd be better
if you marked the function VOLATILE.

But having said that, it seems that this complaint implies that
CREATE MATERIALIZED VIEW ... WITH NO DATA still runs the query
through a planning cycle.  Why is that?  I can't immediately see
any benefit to doing so.

			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] 6+ messages in thread

* Re: BUG #8606: Materialized View WITH NO DATA bug
@ 2013-11-20 08:06  Jaroslav Rejda <j.rejda@konektel.cz>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 0 replies; 6+ messages in thread

From: Jaroslav Rejda @ 2013-11-20 08:06 UTC (permalink / raw)
  To: 'Tom Lane' <tgl@sss.pgh.pa.us>; 'Kevin Grittner' <kgrittn@ymail.com>; +Cc: pgsql-bugs

Yes, that's what I had in mind ... I expected "CREATE MATERIALIZED VIEW ...
WITH NO DATA" returns almost immediately and "REFRESH MATERIALIZED VIEW ..."
will take a while. But when you use a query that can probably be evaluated
immediately, "CREATE MATERIALIZED VIEW ... WITH NO DATA" apparently do this
query (which spends enough time), but no data is populated. The same time it
takes with "REFRESH MATERIALIZED VIEW ..." to populate data. From my
perspective, this is wrong and should behave the same for any query, ie.
"CREATE MATERIALIZED VIEW ... WITH NO DATA" would not solve the query.

JR

-----Original Message-----
From: Tom Lane [mailto:tgl@sss.pgh.pa.us] 
Sent: Wednesday, November 20, 2013 4:50 AM
To: Kevin Grittner
Cc: j.rejda@konektel.cz; pgsql-bugs@postgresql.org
Subject: Re: [BUGS] BUG #8606: Materialized View WITH NO DATA bug

Kevin Grittner <kgrittn@ymail.com> writes:
> "j.rejda@konektel.cz" <j.rejda@konektel.cz> wrote:
>> -- this returns "after some time" (as long as normal "SELECT
>> long_test(10);"
>> do)
>> CREATE MATERIALIZED VIEW test2 AS
>>    SELECT long_test(10) WITH NO DATA;
>> 
>> -- it's ok or bug?

> It's not a bug in the sense that it crashes or returns an incorrect
> result, but it may be an opportunity for a performance enhancement.

Meh.  I'm not sure this can be considered to be a problem.  One of
the implications of marking a function immutable is that it has no
side-effects worthy of concern; otherwise, it wouldn't be safe for
the planner to constant-fold it, which is pretty much the whole point
of immutability.  But if you're concerned about how long it takes to
evaluate, that's a kind of side effect, IMHO.  Maybe it'd be better
if you marked the function VOLATILE.

But having said that, it seems that this complaint implies that
CREATE MATERIALIZED VIEW ... WITH NO DATA still runs the query
through a planning cycle.  Why is that?  I can't immediately see
any benefit to doing so.

			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] 6+ messages in thread

* Re: BUG #8606: Materialized View WITH NO DATA bug
@ 2013-11-20 14:05  Kevin Grittner <kgrittn@ymail.com>
  parent: Tom Lane <tgl@sss.pgh.pa.us>
  1 sibling, 1 reply; 6+ messages in thread

From: Kevin Grittner @ 2013-11-20 14:05 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: j.rejda@konektel.cz <j.rejda@konektel.cz>; pgsql-bugs

Tom Lane <tgl@sss.pgh.pa.us> wrote:

> But having said that, it seems that this complaint implies that
> CREATE MATERIALIZED VIEW ... WITH NO DATA still runs the query
> through a planning cycle.  Why is that?  I can't immediately see
> any benefit to doing so.

Well, to be honest, it's because CREATE TABLE AS ... WITH NO DATA
does so, and I figured that if it was needed there I didn't see why
CREATE MATERIALIZED VIEW AS ... WITH NO DATA would be any
different.  I'm shameless in copying what seems to be working.

--
Kevin Grittner
EDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company


-- 
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] 6+ messages in thread

* Re: BUG #8606: Materialized View WITH NO DATA bug
@ 2013-11-23 21:15  Tom Lane <tgl@sss.pgh.pa.us>
  parent: Kevin Grittner <kgrittn@ymail.com>
  0 siblings, 0 replies; 6+ messages in thread

From: Tom Lane @ 2013-11-23 21:15 UTC (permalink / raw)
  To: Kevin Grittner <kgrittn@ymail.com>; +Cc: j.rejda@konektel.cz <j.rejda@konektel.cz>; pgsql-bugs

Kevin Grittner <kgrittn@ymail.com> writes:
> Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> But having said that, it seems that this complaint implies that
>> CREATE MATERIALIZED VIEW ... WITH NO DATA still runs the query
>> through a planning cycle.  Why is that?  I can't immediately see
>> any benefit to doing so.

> Well, to be honest, it's because CREATE TABLE AS ... WITH NO DATA
> does so, and I figured that if it was needed there I didn't see why
> CREATE MATERIALIZED VIEW AS ... WITH NO DATA would be any
> different.  I'm shameless in copying what seems to be working.

I looked at that a bit.  The reason we have to plan, in the current code,
is that we create the target table using column type info from the output
tupdesc supplied by the executor; so we have to have a plan to fire up the
executor on, even if we aren't going to fetch any data from the plan.

It's conceivable that we could extract result type info directly from
the original query (a la DefineVirtualRelation), but it'd be a significant
amount of work and it would mean that the WITH DATA and WITH NO DATA code
paths would be almost completely disjoint.  Worse, we'd still need
something pretty close to what we've got now to handle the CREATE TABLE
AS ... EXECUTE case, making that probably a third totally separate path.

So I'm thinking it's not worth the trouble to avoid a planning cycle
here.

			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] 6+ messages in thread


end of thread, other threads:[~2013-11-23 21:15 UTC | newest]

Thread overview: 6+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2013-11-19 15:35 BUG #8606: Materialized View WITH NO DATA bug j.rejda@konektel.cz
2013-11-19 22:46 ` Kevin Grittner <kgrittn@ymail.com>
2013-11-20 03:49   ` Tom Lane <tgl@sss.pgh.pa.us>
2013-11-20 08:06     ` Jaroslav Rejda <j.rejda@konektel.cz>
2013-11-20 14:05     ` Kevin Grittner <kgrittn@ymail.com>
2013-11-23 21:15       ` Tom Lane <tgl@sss.pgh.pa.us>

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