Re: [HACKERS] CTE inlining - Mailing list pgsql-hackers

From Yaroslav
Subject Re: [HACKERS] CTE inlining
Date
Msg-id 1494538647075-5961086.post@n3.nabble.com
Whole thread Raw
In response to [HACKERS] CTE inlining  (Ilya Shkuratov <motr.ilya@ya.ru>)
Responses Re: [HACKERS] CTE inlining  (Andreas Joseph Krogh <andreas@visena.com>)
List pgsql-hackers
Ilya Shkuratov wrote
> First of all, to such replacement to be valid, the CTE must be 
>     1. non-writable (e.g. be of form: SELECT ...),
>     2. do not use VOLATILE or STABLE functions,
>     3. ... (maybe there must be more restrictions?) 

What about simple things like this?

CREATE OR REPLACE FUNCTION z(numeric) RETURNS boolean AS $$
BEGIN
RETURN $1 <> 0;
END;
$$ LANGUAGE plpgSQL IMMUTABLE COST 1000;

-- This one works:
WITH T AS (
SELECT 1.0 AS v1, 0.0 AS v2
UNION ALL
SELECT 3.0, 1.0
UNION ALL
SELECT 2.0, 0.0
), a AS (
SELECT * FROM tWHERE z(v2)
)
SELECT * FROM aWHERE v1/v2 > 1.5;

-- This one gives 'division by zero':
WITH T AS (
SELECT 1.0 AS v1, 0.0 AS v2
UNION ALL
SELECT 3.0, 1.0
UNION ALL
SELECT 2.0, 0.0
)
SELECT * FROM (      SELECT *        FROM t       WHERE z(v2)      ) AS aWHERE v1/v2 > 1.5;




-----
WBR, Yaroslav Schekin.
--
View this message in context: http://www.postgresql-archive.org/CTE-inlining-tp5958992p5961086.html
Sent from the PostgreSQL - hackers mailing list archive at Nabble.com.



pgsql-hackers by date:

Previous
From: Andres Freund
Date:
Subject: Re: [HACKERS] [BUGS] Concurrent ALTER SEQUENCE RESTART Regression
Next
From: andres@anarazel.de (Andres Freund)
Date:
Subject: Re: [HACKERS] snapbuild woes