You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hawq.apache.org by zt...@apache.org on 2021/12/27 08:39:29 UTC

[hawq] 01/01: HAWQ-1823. avoid of reallocating resource in udf

This is an automated email from the ASF dual-hosted git repository.

ztao1987 pushed a commit to branch ztao
in repository https://gitbox.apache.org/repos/asf/hawq.git

commit bd88dbd9081577e441220ba8d39fcda31ebe0dc2
Author: ztao1987 <zh...@gmail.com>
AuthorDate: Mon Dec 27 16:36:44 2021 +0800

    HAWQ-1823. avoid of reallocating resource in udf
---
 src/backend/commands/indexcmds.c              | 10 +++++++++-
 src/backend/commands/tablecmds.c              | 14 +++++++++++---
 src/backend/resourcemanager/resqueuemanager.c |  4 ++--
 3 files changed, 22 insertions(+), 6 deletions(-)

diff --git a/src/backend/commands/indexcmds.c b/src/backend/commands/indexcmds.c
index 1c8c3d1..fdd065e 100644
--- a/src/backend/commands/indexcmds.c
+++ b/src/backend/commands/indexcmds.c
@@ -147,7 +147,15 @@ bool CDBCreateIndex(IndexStmt *stmt, Oid relationOid, Oid indexOid)
 
 	elog(DEBUG1, "CDBCreateIndex virtual segment number is: %d\n", target_segment_num);
 
-	QueryResource *resource = AllocateResource(QRL_ONCE, 1, 1, target_segment_num, target_segment_num, NULL, 0);
+	QueryResource *resource = NULL;
+	QueryResource *savedResource = NULL;
+	savedResource = GetActiveQueryResource();
+	if (!savedResource) {
+	  resource = AllocateResource(QRL_ONCE, 1, 1, target_segment_num, target_segment_num, NULL, 0);
+	} else {
+	  resource = AllocateResource(QRL_INHERIT, 0, 0, 0, 0, NULL, 0);
+	}
+	SetActiveQueryResource(resource);
 
 	/* 4.bind SegNO to Vseg */
 	int total_segfiles = 0;
diff --git a/src/backend/commands/tablecmds.c b/src/backend/commands/tablecmds.c
index a21d803..60dc98b 100644
--- a/src/backend/commands/tablecmds.c
+++ b/src/backend/commands/tablecmds.c
@@ -7219,8 +7219,12 @@ ATRewriteTable(AlteredTableInfo *tab, Oid OIDNewHeap)
       }
 		}
 
-	  resource = AllocateResource(QRL_ONCE, 1, 1, target_segment_num, target_segment_num,NULL,0);
-	  savedResource = GetActiveQueryResource();
+		savedResource = GetActiveQueryResource();
+		if (!savedResource) {
+		  resource = AllocateResource(QRL_ONCE, 1, 1, target_segment_num, target_segment_num,NULL,0);
+		} else {
+		  resource = AllocateResource(QRL_INHERIT, 0, 0, 0, 0, NULL, 0);
+		}
 	  SetActiveQueryResource(resource);
 
 	  segment_segnos = SetSegnoForWrite(NIL, 0, target_segment_num, true, true, false);
@@ -17578,8 +17582,12 @@ ATPExecPartSplit(Relation rel,
 
     }
 
-    resource = AllocateResource(QRL_ONCE, 1, 1, target_segment_num, target_segment_num, NULL, 0);
     savedResource = GetActiveQueryResource();
+    if (!savedResource) {
+      resource = AllocateResource(QRL_ONCE, 1, 1, target_segment_num, target_segment_num, NULL, 0);
+    } else {
+      resource = AllocateResource(QRL_INHERIT, 0, 0, 0, 0, NULL, 0);
+    }
     SetActiveQueryResource(resource);
     segment_segnos = SetSegnoForWrite(NIL, 0, target_segment_num, true, true, false);
     scantable_splits = NIL;
diff --git a/src/backend/resourcemanager/resqueuemanager.c b/src/backend/resourcemanager/resqueuemanager.c
index 16d4087..1a8807a 100644
--- a/src/backend/resourcemanager/resqueuemanager.c
+++ b/src/backend/resourcemanager/resqueuemanager.c
@@ -4385,8 +4385,8 @@ void buildAcquireResourceResponseMessage(ConnectionTrack conn)
 	conn->MessageID    = RESPONSE_QD_ACQUIRE_RESOURCE;
 	conn->ResAllocTime = gettime_microsec();
 
-	elog(LOG, "latency of getting resource allocated is "UINT64_FORMAT "us",
-			  conn->ResAllocTime - conn->ResRequestTime);
+	elog(LOG, "ConnID %d latency of getting resource allocated is "UINT64_FORMAT "us",
+			  conn->ConnID, conn->ResAllocTime - conn->ResRequestTime);
 
 	MEMORY_CONTEXT_SWITCH_TO(PCONTEXT)
 	PCONTRACK->ConnToSend = lappend(PCONTRACK->ConnToSend, conn);