Re: Wrong rows estimations with joins of CTEs slows queries by more than factor 500

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Alexander Lakhin <exclusion(at)gmail(dot)com>
Cc: Richard Guo <guofenglinux(at)gmail(dot)com>, Jian Guo <gjian(at)vmware(dot)com>, Tomas Vondra <tomas(dot)vondra(at)enterprisedb(dot)com>, Hans Buschmann <buschmann(at)nidsa(dot)net>, "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>, Zhenghua Lyu <zlyu(at)vmware(dot)com>
Subject: Re: Wrong rows estimations with joins of CTEs slows queries by more than factor 500
Date: 2024-01-06 22:41:14
Message-ID: 1450797.1704580874@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Alexander Lakhin <exclusion(at)gmail(dot)com> writes:
> Please look at the following query:
> CREATE TABLE t(i int);
> INSERT INTO t VALUES (1);
> VACUUM ANALYZE t;

> WITH ir AS (INSERT INTO t VALUES (2) RETURNING i)
> SELECT * FROM ir WHERE i = 2;

> which produces ERROR:  no relation entry for relid 1
> starting from f7816aec2.

Thanks for the report! I guess we need something like the attached.
I'm surprised that this hasn't been noticed before; was the case
really unreachable before?

regards, tom lane

Attachment Content-Type Size
fix-examine-variable-for-INSERT-RETURNING.patch text/x-diff 4.7 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Geoff Winkless 2024-01-06 23:27:40 Re: weird GROUPING SETS and ORDER BY behaviour
Previous Message Tom Lane 2024-01-06 21:08:57 Re: Fix bogus Asserts in calc_non_nestloop_required_outer