Using ForeignScan::fs_server to find user mapping

Started by Anton Ratundalov5 months ago1 messageshackers

Thread notes

1 note#refactor
hackorum-bot#refactor
hackorum-bot
2 days ago

@global #refactor

#refactor
Jump to latest
#1Anton Ratundalov
a.ratundalov@postgrespro.ru

Hi hackers

In the postgresBeginForeignScan I see rather complex logic just before
GetUserMapping call.

This is all about finding serverid.

    /*
     * Identify which user to do the remote access as.  This should
match what
     * ExecCheckPermissions() does.
     */
    userid = OidIsValid(fsplan->checkAsUser) ? fsplan->checkAsUser :
GetUserId();
    if (fsplan->scan.scanrelid > 0)
        rtindex = fsplan->scan.scanrelid;
    else
        rtindex = bms_next_member(fsplan->fs_base_relids, -1);
    rte = exec_rt_fetch(rtindex, estate);

    /* Get info about foreign table. */
    table = GetForeignTable(rte->relid);
    user = GetUserMapping(userid, table->serverid);

Seems like we have the required serverid in ForeignScan::fs_server already.

Why not to use it?

Best regards

Anton Ratundalov