Dear PostgreSQL Developer,
My point is that this kind of query, which is always logically empty, should not be executed at all. Executing it not only wastes time, but more concerningly, it can lead to incorrect results. I have discovered bugs in MySQL, MariaDB, and TiDB where such queries, which should have returned empty result sets, instead produced incorrect non-empty results due to being actually executed. Since I’ve only recently started working with PostgreSQL in the past two days, I haven’t yet tested whether it exhibits similar bugs. If I do find any such cases, I will provide concrete examples. Therefore, my additional point is that avoiding the execution of such queries can fundamentally eliminate these types of logical bugs at their source.
Best regrerds,
发件人:David Rowley <dgrowleyml@gmail.com> 发件时间:2025年4月29日 19:57 收件人:Tom Lane <tgl@sss.pgh.pa.us> 抄送:David G. Johnston <david.g.johnston@gmail.com>, jh.lai@qq.com <jh.lai@qq.com>, pgsql-bugs@lists.postgresql.org <pgsql-bugs@lists.postgresql.org> 主题:Re: BUG #18904: INTERSECT with an impossible where should eliminateboth from the query plan |
On Mon, 28 Apr 2025 at 06:02, Tom Lane <tgl@sss.pgh.pa.us> wrote:
> Anyway, as David said, this is not a bug. If it's something you
> really want to see happen, try writing a patch yourself.
This is already somewhat better in v18 thanks to [1].
generate_nonunion_paths() already has some code to put the smallest
child on the left, and the recent changes in nodeSetOp.c means very
little work will be done when the left side is empty.
David
[1] https://git.postgresql.org/gitweb/?p=postgresql.git;a=commit;h=276279295