From bd88dbd9081577e441220ba8d39fcda31ebe0dc2 Mon Sep 17 00:00:00 2001 From: ztao1987 Date: Mon, 27 Dec 2021 16:36:44 +0800 Subject: [PATCH] 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 1c8c3d115..fdd065eb1 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 a21d803ed..60dc98b41 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 16d408779..1a8807ac3 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);