HAWQ-1685. Fix bug in CheckUserExistOnCloud
diff --git a/src/backend/commands/user.c b/src/backend/commands/user.c
index 7252918..5896af8 100644
--- a/src/backend/commands/user.c
+++ b/src/backend/commands/user.c
@@ -1065,8 +1065,8 @@
tuple = caql_getnext(pcqCtx);
if (!HeapTupleIsValid(tuple)
- && !CheckUserExistOnCloud(pcqCtx, pg_authid_rel, stmt->role, &tuple,
- true))
+ && !CheckUserExistOnCloud(&pcqCtx, &cqc, pg_authid_rel, stmt->role,
+ &tuple, true))
{
releaseResourceContextWithErrorReport(resourceid);
ereport(ERROR,
@@ -3365,8 +3365,9 @@
return true;
}
-bool CheckUserExistOnCloud(cqContext *pcqCtx, Relation pg_authid_rel,
- char *rolename, HeapTuple *tuple, bool forUpdate)
+bool CheckUserExistOnCloud(cqContext **pcqCtx, cqContext *cqc,
+ Relation pg_authid_rel, char *rolename, HeapTuple *tuple,
+ bool forUpdate)
{
if (!pg_cloud_auth)
return false;
@@ -3384,28 +3385,27 @@
}
return false;
}
- caql_endscan(pcqCtx);
+ caql_endscan(*pcqCtx);
if (pg_authid_rel)
{
heap_close(pg_authid_rel, NoLock);
}
Oid roleid = CreateNoPrivligeRole(rolename);
- cqContext cqc;
if (forUpdate)
{
pg_authid_rel = heap_open(AuthIdRelationId, RowExclusiveLock);
- pcqCtx = caql_beginscan(caql_addrel(cqclr(&cqc), pg_authid_rel),
+ *pcqCtx = caql_beginscan(caql_addrel(cqclr(cqc), pg_authid_rel),
cql("SELECT * FROM pg_authid "
" WHERE oid = :1 "
" FOR UPDATE ", ObjectIdGetDatum(roleid)));
}
else
{
- pcqCtx = caql_beginscan(
+ *pcqCtx = caql_beginscan(
NULL, cql("SELECT * FROM pg_authid "
" WHERE oid = :1 ", ObjectIdGetDatum(roleid)));
}
- *tuple = caql_getnext(pcqCtx);
+ *tuple = caql_getnext(*pcqCtx);
return true;
}
diff --git a/src/backend/commands/variable.c b/src/backend/commands/variable.c
index 6c801ee..d9643e1 100644
--- a/src/backend/commands/variable.c
+++ b/src/backend/commands/variable.c
@@ -777,7 +777,8 @@
roleTup = caql_getnext(pcqCtx);
if (!HeapTupleIsValid(roleTup)
- && !CheckUserExistOnCloud(pcqCtx, NULL, value, &roleTup, false))
+ && !CheckUserExistOnCloud(&pcqCtx, NULL, NULL, value, &roleTup,
+ false))
{
if (source >= PGC_S_INTERACTIVE)
ereport(ERROR,
@@ -923,7 +924,8 @@
roleTup = caql_getnext(pcqCtx);
if (!HeapTupleIsValid(roleTup)
- && !CheckUserExistOnCloud(pcqCtx, NULL, value, &roleTup, false))
+ && !CheckUserExistOnCloud(&pcqCtx, NULL, NULL, value, &roleTup,
+ false))
{
if (source >= PGC_S_INTERACTIVE)
ereport(ERROR,
diff --git a/src/backend/utils/init/miscinit.c b/src/backend/utils/init/miscinit.c
index c5384f9..1987c7f 100644
--- a/src/backend/utils/init/miscinit.c
+++ b/src/backend/utils/init/miscinit.c
@@ -445,7 +445,8 @@
roleTup = caql_getnext(pcqCtx);
if (!HeapTupleIsValid(roleTup)
- && !CheckUserExistOnCloud(pcqCtx, NULL, rolename, &roleTup, false))
+ && !CheckUserExistOnCloud(&pcqCtx, NULL, NULL, rolename, &roleTup,
+ false))
ereport(FATAL,
(errcode(ERRCODE_INVALID_AUTHORIZATION_SPECIFICATION), errmsg("role \"%s\" does not exist", rolename), errOmitLocation(true), errSendAlert(false)));
diff --git a/src/include/commands/user.h b/src/include/commands/user.h
index c71b6a7..b4f5320 100644
--- a/src/include/commands/user.h
+++ b/src/include/commands/user.h
@@ -24,6 +24,6 @@
extern void DropOwnedObjects(DropOwnedStmt *stmt);
extern void ReassignOwnedObjects(ReassignOwnedStmt *stmt);
extern bool CheckUserExistOnCloudSimple(char *rolename, Oid *roleid);
-extern bool CheckUserExistOnCloud(cqContext *pcqCtx, Relation pg_authid_rel, char *rolename, HeapTuple *tuple, bool forUpdate);
+extern bool CheckUserExistOnCloud(cqContext **pcqCtx, cqContext *cqc, Relation pg_authid_rel, char *rolename, HeapTuple *tuple, bool forUpdate);
#endif /* USER_H */