pgfdw support join\agg\sort\limit\lockrows

This commit is contained in:
gentle_hu
2022-11-15 15:31:38 +08:00
parent 0d771b4357
commit f995bd2209
58 changed files with 34971 additions and 1787 deletions

View File

@ -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.
*/