Bug: wrong relname in RemoveSubscriptionRel() error detail - Mailing list pgsql-hackers

From Chao Li
Subject Bug: wrong relname in RemoveSubscriptionRel() error detail
Date
Msg-id B7B16777-AC54-413A-BECE-A814E90D395B@gmail.com
Whole thread Raw
Responses Re: Bug: wrong relname in RemoveSubscriptionRel() error detail
List pgsql-hackers
Hi,

I just noticed a wrong relation name in the error detail emitted by RemoveSubscriptionRel():
```
*
 * Drop subscription relation mapping. These can be for a particular
 * subscription, or for a particular relation, or both.
 */
void
RemoveSubscriptionRel(Oid subid, Oid relid)
{
    Relation    rel;
    TableScanDesc scan;
    ScanKeyData skey[2];
    HeapTuple    tup;
    int            nkeys = 0;

    rel = table_open(SubscriptionRelRelationId, RowExclusiveLock);

    if (OidIsValid(subid))
    {
        ScanKeyInit(&skey[nkeys++],
                    Anum_pg_subscription_rel_srsubid,
                    BTEqualStrategyNumber,
                    F_OIDEQ,
                    ObjectIdGetDatum(subid));
    }

    if (OidIsValid(relid))
    {
        ScanKeyInit(&skey[nkeys++],
                    Anum_pg_subscription_rel_srrelid,
                    BTEqualStrategyNumber,
                    F_OIDEQ,
                    ObjectIdGetDatum(relid));
    }

    /* Do the search and delete what we found. */
    scan = table_beginscan_catalog(rel, nkeys, skey);
    while (HeapTupleIsValid(tup = heap_getnext(scan, ForwardScanDirection)))
    {
        Form_pg_subscription_rel subrel;

        subrel = (Form_pg_subscription_rel) GETSTRUCT(tup);

        if (!OidIsValid(subid) &&
            subrel->srsubstate != SUBREL_STATE_READY &&
            get_rel_relkind(subrel->srrelid) != RELKIND_SEQUENCE)
        {
            ereport(ERROR,
                    (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
                     errmsg("could not drop relation mapping for subscription \"%s\"",
                            get_subscription_name(subrel->srsubid, false)),
                     errdetail("Table synchronization for relation \"%s\" is in progress and is in state \"%c\".",
                               get_rel_name(relid), subrel->srsubstate), // <====== bug is here

```

In the error detail, it uses relid to get the relation name. But at that point we are iterating over subrel, and the
functionargument relid can be InvalidOid. So the error detail should use subrel->srrelid instead. 

This looks like a first-day bug introducing by ce0fdbf, so I think it’s worth back-patching.

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/





Attachment

pgsql-hackers by date:

Previous
From: Dean Rasheed
Date:
Subject: Re: Adjust error message for CREATE STATISTICS to account for expressions
Next
From: Peter Eisentraut
Date:
Subject: Re: SQL Property Graph Queries (SQL/PGQ)