pgfdw support join\agg\sort\limit\lockrows
This commit is contained in:
@ -28,7 +28,7 @@
|
||||
#include "utils/syscache.h"
|
||||
#include "utils/timestamp.h"
|
||||
#include "storage/ipc.h"
|
||||
|
||||
#include "executor/executor.h"
|
||||
|
||||
/*
|
||||
* Connection cache hash table entry
|
||||
@ -243,6 +243,39 @@ PGconn *GetConnection(ForeignServer *server, UserMapping *user, bool will_prep_s
|
||||
return entry->conn;
|
||||
}
|
||||
|
||||
PGconn* GetConnectionByFScanState(ForeignScanState* node, bool will_prep_stmt)
|
||||
{
|
||||
ForeignScan* fsplan = (ForeignScan *)node->ss.ps.plan;
|
||||
EState* estate = node->ss.ps.state;
|
||||
RangeTblEntry* rte = NULL;
|
||||
Oid userid;
|
||||
ForeignTable* table = NULL;
|
||||
ForeignServer* server = NULL;
|
||||
UserMapping* user = NULL;
|
||||
int rtindex;
|
||||
|
||||
/*
|
||||
* Identify which user to do the remote access as. This should match what
|
||||
* ExecCheckRTEPerms() does. In case of a join or aggregate, use the
|
||||
* lowest-numbered member RTE as a representative; we would get the same
|
||||
* result from any.
|
||||
*/
|
||||
if (fsplan->scan.scanrelid > 0) {
|
||||
rtindex = fsplan->scan.scanrelid;
|
||||
} else {
|
||||
rtindex = bms_next_member(fsplan->fs_relids, -1);
|
||||
}
|
||||
rte = exec_rt_fetch(rtindex, estate);
|
||||
userid = rte->checkAsUser ? rte->checkAsUser : GetUserId();
|
||||
|
||||
/* Get info about foreign table. */
|
||||
table = GetForeignTable(rte->relid);
|
||||
server = GetForeignServer(table->serverid);
|
||||
user = GetUserMapping(userid, table->serverid);
|
||||
|
||||
return GetConnection(server, user, will_prep_stmt);
|
||||
}
|
||||
|
||||
/*
|
||||
* Connect to remote server using specified server and user mapping properties.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user