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

From: Alexander Lakhin <exclusion(at)gmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Richard Guo <guofenglinux(at)gmail(dot)com>
Cc: 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 09:00:01
Message-ID: 608a4886-6c60-0f9e-97d5-591256bd4150@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hello Tom and Richard,

17.11.2023 22:42, Tom Lane wrote:
> OK. I pushed the patch after a bit more review: we can simplify
> things some more by using the subroot->parse querytree for all
> tests. After the previous refactoring, it wasn't buying us anything
> to do some initial tests with the raw querytree. (The original
> idea of that, I believe, was to avoid doing find_base_rel if we
> could; but now that's not helpful.)

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.

Best regards,
Alexander

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Bertrand Drouvot 2024-01-06 09:03:52 Re: verify predefined LWLocks have entries in wait_event_names.txt
Previous Message jian he 2024-01-06 02:01:27 Re: Change GUC hashtable to use simplehash?