BUG #17243: explain wtih recursive cte error?

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: mark(dot)a(dot)sloan(at)gmail(dot)com
Subject: BUG #17243: explain wtih recursive cte error?
Date: 2021-10-22 00:49:41
Message-ID: 17243-45ee0e3a03063b9b@postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 17243
Logged by: mark sloan
Email address: mark(dot)a(dot)sloan(at)gmail(dot)com
PostgreSQL version: 14.0
Operating system: MacOS
Description:

Seeing a issue with 'EXPLAIN' throwing an error on a query that otherwise
runs without issue.

example query case.
---------------------------------------------
select x.v into explainctebug from (values('foo'),('bar'),('baz')) as
x(v);

query:

with recursive a as
(
select v, '' as x, 0 as n from explainctebug
union all
select v, substring(v,n+1,1) as x, n+1 as n from a where n < length(v)
)
select x, count(*) from a where n > 0
group by x order by count(*) desc;

returns.

x | count
---+-------
a | 2
b | 2
o | 2
r | 1
z | 1
f | 1
(6 rows)

--------

EXPLAIN verbose with recursive a as
(
select v, '' as x, 0 as n from explainctebug
union all
select v, substring(v,n+1,1) as x, n+1 as n from a where n < length(v)
)
select x, count(*) from a where n > 0
group by x order by count(*) desc ;

returns

QUERY PLAN

---------------------------------------------------------------------------------------
Sort (cost=5835.36..5835.86 rows=200 width=40)
Output: a.x, (count(*))
Sort Key: (count(*)) DESC
CTE a
-> Recursive Union (cost=0.00..4697.37 rows=46690 width=68)
-> Seq Scan on public.explainctebug (cost=0.00..23.60 rows=1360
width=68)
Output: explainctebug.v, ''::text, 0
-> WorkTable Scan on a a_1 (cost=0.00..374.00 rows=4533
width=68)
Output: a_1.v, "substring"(a_1.v, (a_1.n + 1), 1), (a_1.n +
1)
Filter: (a_1.n < length(a_1.v))
-> HashAggregate (cost=1128.34..1130.34 rows=200 width=40)
Output: a.x, count(*)
Group Key: a.x
-> CTE Scan on a (cost=0.00..1050.52 rows=15563 width=32)
Output: a.v, a.x, a.n
Filter: (a.n > 0)
(16 rows)

EXPLAIN with recursive a as
(
select v, '' as x, 0 as n from explainctebug
union all
select v, substring(v,n+1,1) as x, n+1 as n from a where n < length(v)
)
select x, count(*) from a where n > 0
group by x order by count(*) desc ;

returns.

ERROR: could not find RecursiveUnion for WorkTableScan with wtParam 0

this seems like it might be a bug?

PostgreSQL 14.0 on x86_64-apple-darwin20.6.0, compiled by Apple clang
version 13.0.0 (clang-1300.0.29.3), 64-bit

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Troska, Cezary 2021-10-22 11:55:20 Logical replication - empty search_path bug?
Previous Message Euler Taveira 2021-10-21 19:46:19 Re: BUG #17238: Link to "Using EXPLAIN" in the "EXPLAIN" documentation