Skip to content

Commit 5c7b664

Browse files
committed
Initial exchange_node commit
1 parent da9582b commit 5c7b664

File tree

17 files changed

+1036
-13
lines changed

17 files changed

+1036
-13
lines changed

contrib/pg_execplan/pg_execplan.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include "access/printtup.h"
99
#include "commands/extension.h"
1010
#include "commands/prepare.h"
11+
#include "common/base64.h"
1112
#include "executor/executor.h"
1213
#include "nodes/nodes.h"
1314
#include "nodes/plannodes.h"
@@ -65,15 +66,15 @@ pg_store_query_plan(PG_FUNCTION_ARGS)
6566
elog(ERROR, "Query contains %d elements, but must contain only one.", nstmts);
6667

6768
parsetree = (RawStmt *) linitial(parsetree_list);
68-
querytree_list = pg_analyze_and_rewrite(parsetree, query_string, NULL, 0);
69+
querytree_list = pg_analyze_and_rewrite(parsetree, query_string, NULL, 0, NULL);
6970
plantree_list = pg_plan_queries(querytree_list, CURSOR_OPT_PARALLEL_OK, NULL);
7071

7172
queryDesc = CreateQueryDesc((PlannedStmt *) linitial(plantree_list),
7273
query_string,
7374
InvalidSnapshot,
7475
InvalidSnapshot,
7576
None_Receiver,
76-
0,
77+
NULL, NULL,
7778
0);
7879

7980
if (EXPLAN_DEBUG_LEVEL > 0)
@@ -131,7 +132,7 @@ exec_plan(char *query_string, char *plan_string)
131132
CURSOR_OPT_GENERIC_PLAN, false);
132133

133134
SetRemoteSubplan(psrc, pstmt);
134-
cplan = GetCachedPlan(psrc, paramLI, false);
135+
cplan = GetCachedPlan(psrc, paramLI, false, NULL);
135136

136137
receiver = CreateDestReceiver(DestLog);
137138

@@ -142,11 +143,11 @@ exec_plan(char *query_string, char *plan_string)
142143
GetActiveSnapshot(),
143144
InvalidSnapshot,
144145
receiver,
145-
paramLI,
146+
paramLI, NULL,
146147
0);
147148
ExecutorStart(queryDesc, eflags);
148149
PushActiveSnapshot(queryDesc->snapshot);
149-
ExecutorRun(queryDesc, ForwardScanDirection, 0);
150+
ExecutorRun(queryDesc, ForwardScanDirection, 0, true);
150151
PopActiveSnapshot();
151152
ExecutorFinish(queryDesc);
152153
ExecutorEnd(queryDesc);
@@ -183,14 +184,14 @@ pg_exec_plan(PG_FUNCTION_ARGS)
183184
Assert(query_string != NULL);
184185
Assert(plan_string != NULL);
185186

186-
dec_query_len = b64_dec_len(query_string, strlen(query_string) + 1)+1;
187+
dec_query_len = pg_b64_dec_len(strlen(query_string) + 1) + 1;
187188
dec_query = palloc0(dec_query_len + 1);
188-
dec_query_len1 = b64_decode(query_string, strlen(query_string), dec_query);
189+
dec_query_len1 = pg_b64_decode(query_string, strlen(query_string), dec_query);
189190
Assert(dec_query_len > dec_query_len1);
190191

191-
dec_plan_len = b64_dec_len(plan_string, strlen(plan_string) + 1);
192+
dec_plan_len = pg_b64_dec_len(strlen(plan_string) + 1);
192193
dec_plan = palloc0(dec_plan_len + 1);
193-
dec_plan_len1 = b64_decode(plan_string, strlen(plan_string), dec_plan);
194+
dec_plan_len1 = pg_b64_decode(plan_string, strlen(plan_string), dec_plan);
194195
Assert(dec_plan_len > dec_plan_len1);
195196

196197
exec_plan(dec_query, dec_plan);
File renamed without changes.

src/backend/access/common/printtup.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -631,6 +631,48 @@ debugtup(TupleTableSlot *slot, DestReceiver *self)
631631
return true;
632632
}
633633

634+
void
635+
logStartup(DestReceiver *self, int operation, TupleDesc typeinfo)
636+
{
637+
int natts = typeinfo->natts;
638+
int i;
639+
640+
/*
641+
* show the return type of the tuples
642+
*/
643+
printf("\t---- Result Attributes ----\n");
644+
for (i = 0; i < natts; ++i)
645+
printf("%s\t|\t", NameStr(TupleDescAttr(typeinfo, i)->attname));
646+
printf("\n");
647+
}
648+
649+
bool
650+
logtup(TupleTableSlot *slot, DestReceiver *self)
651+
{
652+
TupleDesc typeinfo = slot->tts_tupleDescriptor;
653+
int natts = typeinfo->natts;
654+
int i;
655+
Datum attr;
656+
char *value;
657+
bool isnull;
658+
Oid typoutput;
659+
bool typisvarlena;
660+
661+
for (i = 0; i < natts; ++i)
662+
{
663+
attr = slot_getattr(slot, i + 1, &isnull);
664+
if (isnull)
665+
continue;
666+
getTypeOutputInfo(TupleDescAttr(typeinfo, i)->atttypid,
667+
&typoutput, &typisvarlena);
668+
669+
value = OidOutputFunctionCall(typoutput, attr);
670+
printf("%s\t|\t", value);
671+
}
672+
printf("\n");
673+
674+
return true;
675+
}
634676
/* ----------------
635677
* printtup_internal_20 --- print a binary tuple in protocol 2.0
636678
*

src/backend/commands/opclasscmds.c

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1599,6 +1599,58 @@ RemoveOpFamilyById(Oid opfamilyOid)
15991599
heap_close(rel, RowExclusiveLock);
16001600
}
16011601

1602+
Oid
1603+
get_family_oid(const char *opfname, const char *nspname, const char *ammth)
1604+
{
1605+
Oid nspoid,
1606+
amoid,
1607+
opfoid = InvalidOid;
1608+
HeapTuple htup = NULL;
1609+
1610+
nspoid = LookupNamespaceNoError(nspname);
1611+
amoid = get_am_oid(ammth, false);
1612+
1613+
if (OidIsValid(nspoid) && OidIsValid(amoid))
1614+
htup = SearchSysCache3(OPFAMILYAMNAMENSP,
1615+
ObjectIdGetDatum(amoid),
1616+
PointerGetDatum(opfname),
1617+
ObjectIdGetDatum(nspoid));
1618+
1619+
if (HeapTupleIsValid(htup))
1620+
{
1621+
opfoid = HeapTupleGetOid(htup);
1622+
ReleaseSysCache(htup);
1623+
}
1624+
1625+
return opfoid;
1626+
}
1627+
1628+
char *
1629+
get_opfamily_name(Oid opfamilyOid, char **nspname, char **opfmethod)
1630+
{
1631+
HeapTuple tup;
1632+
char *opfname;
1633+
Oid nspoid,
1634+
mthoid;
1635+
1636+
Assert(nspname != NULL);
1637+
1638+
1639+
tup = SearchSysCache1(OPFAMILYOID, ObjectIdGetDatum(opfamilyOid));
1640+
if (!HeapTupleIsValid(tup)) /* should not happen */
1641+
elog(ERROR, "cache lookup failed for opfamily %u", opfamilyOid);
1642+
1643+
opfname = pstrdup(NameStr(((Form_pg_opfamily) GETSTRUCT(tup))->opfname));
1644+
nspoid = ((Form_pg_opfamily) GETSTRUCT(tup))->opfnamespace;
1645+
*nspname = get_namespace_name(nspoid);
1646+
1647+
mthoid = ((Form_pg_opfamily) GETSTRUCT(tup))->opfmethod;
1648+
*opfmethod = get_am_name(mthoid);
1649+
1650+
ReleaseSysCache(tup);
1651+
return opfname;
1652+
}
1653+
16021654
void
16031655
RemoveOpClassById(Oid opclassOid)
16041656
{

src/backend/commands/user.c

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1136,6 +1136,42 @@ DropRole(DropRoleStmt *stmt)
11361136
heap_close(pg_authid_rel, NoLock);
11371137
}
11381138

1139+
char *
1140+
get_rolename(Oid roleid)
1141+
{
1142+
HeapTuple tuple;
1143+
char *rolename;
1144+
1145+
tuple = SearchSysCache1(AUTHOID, ObjectIdGetDatum(roleid));
1146+
1147+
if (!HeapTupleIsValid(tuple))
1148+
ereport(ERROR,
1149+
(errcode(ERRCODE_UNDEFINED_OBJECT),
1150+
errmsg("role with oid\"%d\" does not exist", roleid)));
1151+
1152+
rolename = strdup(NameStr(((Form_pg_authid) GETSTRUCT(tuple))->rolname));
1153+
ReleaseSysCache(tuple);
1154+
return rolename;
1155+
}
1156+
1157+
Oid
1158+
get_roleid(const char *rolename)
1159+
{
1160+
HeapTuple tuple;
1161+
Oid roleid;
1162+
1163+
tuple = SearchSysCache1(AUTHNAME, CStringGetDatum(rolename));
1164+
1165+
if (!HeapTupleIsValid(tuple))
1166+
ereport(ERROR,
1167+
(errcode(ERRCODE_UNDEFINED_OBJECT),
1168+
errmsg("role \"%s\" does not exist", rolename)));
1169+
1170+
roleid = HeapTupleGetOid(tuple);
1171+
ReleaseSysCache(tuple);
1172+
return roleid;
1173+
}
1174+
11391175
/*
11401176
* Rename role
11411177
*/

0 commit comments

Comments
 (0)