[PATCH] Fixed assertion issues in "pg_get_viewdef"

From: 曾满 <zengman(at)halodbtech(dot)com>
To: pgsql-hackers <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: [PATCH] Fixed assertion issues in "pg_get_viewdef"
Date: 2024-11-15 11:05:33
Message-ID: tencent_7ABF9B1F23B0C77606FC5FE3@qq.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Hi everyone,

The following bug has been logged on the website:

Bug reference: &nbsp; &nbsp; &nbsp;18710
Logged by: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Man Zeng
Email address: &nbsp; &nbsp; &nbsp;zengman(at)halodbtech(dot)com
PostgreSQL version: 14.14
Operating system: &nbsp; centos-8
Description: &nbsp; &nbsp; &nbsp; &nbsp;

A prototype of the problem from
https://github.com/duckdb/pg_duckdb/issues/435
This exception can be reliably triggered by calling "pg_get_viewdef"

Step 1 :
CREATE VIEW view_a AS
WITH RECURSIVE outermost(x) AS (
&nbsp;SELECT 1
&nbsp;UNION (WITH innermost1 AS (
&nbsp;SELECT 2)
&nbsp; SELECT * FROM outermost
&nbsp; UNION SELECT * FROM innermost1)
&nbsp;)
&nbsp;SELECT * FROM outermost ORDER BY 1;

Step 2 :
SELECT oid FROM pg_class where relname = 'view_a';

Step 3:
SELECT pg_get_viewdef( this oid ); -- error

The abnormalities appear as follows
[postgres(at)iZuf6hwo0wgeev4dvua4csZ postgres]$ psql
psql (14.14)
Type "help" for help.

postgres=# CREATE VIEW view_a AS
postgres-# WITH RECURSIVE outermost(x) AS (
postgres(# &nbsp;SELECT 1
postgres(# &nbsp;UNION (WITH innermost1 AS (
postgres(# &nbsp;SELECT 2)
postgres(# &nbsp; SELECT * FROM outermost
postgres(# &nbsp; UNION SELECT * FROM innermost1)
postgres(# &nbsp;)
postgres-# &nbsp;SELECT * FROM outermost ORDER BY 1;
CREATE VIEW
postgres=# SELECT * FROM pg_class where relname = 'view_a';
&nbsp; oid &nbsp;| relname | relnamespace | reltype | reloftype | relowner | relam |
relfilenode | reltablespace | relpages | reltuples | relallvisible |
reltoastrelid | relhasindex | relisshared | relpersistence | relkind |
relnatt
s | relchecks | relhasrules | relhastriggers | relhassubclass |
relrowsecurity | relforcerowsecurity | relispopulated | relreplident |
relispartition | relrewrite | relfrozenxid | relminmxid | relacl |
reloptions | relpart
bound
-------+---------+--------------+---------+-----------+----------+-------+-------------+---------------+----------+-----------+---------------+---------------+-------------+-------------+----------------+---------+--------
--+-----------+-------------+----------------+----------------+----------------+---------------------+----------------+--------------+----------------+------------+--------------+------------+--------+------------+--------
------
&nbsp;32768 | view_a &nbsp;| &nbsp; &nbsp; &nbsp; &nbsp; 2200 | &nbsp; 32770 | &nbsp; &nbsp; &nbsp; &nbsp; 0 | &nbsp; &nbsp; &nbsp; 10 | &nbsp; &nbsp; 0 | &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp; 0 | &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0 | &nbsp; &nbsp; &nbsp; &nbsp;0 | &nbsp; &nbsp; &nbsp; &nbsp;-1 | &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 0 | &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; 0 | f &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | f &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | p &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| v &nbsp; &nbsp; &nbsp; | &nbsp; &nbsp; &nbsp; &nbsp;
1 | &nbsp; &nbsp; &nbsp; &nbsp; 0 | t &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | f &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| f &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| f &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;
&nbsp; | f &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; | t &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| n &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| f &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| &nbsp;
&nbsp; &nbsp; &nbsp; &nbsp;0 | &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0 | &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0 | &nbsp; &nbsp; &nbsp; &nbsp;| &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|
(1 row)

postgres=# select pg_get_viewdef(32768);
TRAP: FailedAssertion("subquery-&gt;setOperations == NULL", File:
"ruleutils.c", Line: 6094, PID: 325948)
postgres: postgres postgres [local]
SELECT(ExceptionalCondition+0xb9)[0xb1a6c1]
postgres: postgres postgres [local] SELECT[0xa95d6b]
postgres: postgres postgres [local] SELECT[0xa960b5]
......

Fix:

We can comment out the assertion that raises the exception, because I looked up the code and found that the assertion doesn't seem to make a lot
of sense here.

Please find the patch attached.

Attachment Content-Type Size
v1-0001-Remove-invalid-assertion.patch application/octet-stream 3.7 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Heikki Linnakangas 2024-11-15 11:06:00 Re: POC: make mxidoff 64 bits
Previous Message Shubham Khanna 2024-11-15 10:29:09 Re: Improve the error message for logical replication of regular column to generated column.