Skip to content

Commit e0fc2fe

Browse files
zhangwenchao-123my-ship-it
authored andcommitted
Fix always rebuild gang when cdbdisp_dispatchCommandInternal.
In this commit, we will only rebuild gang only when there is catalog updation. In this way, we will imporve qps obviously in concurrence stress testing. Authored-by: Zhang Wenchao zwcpostgres@gmail.com
1 parent f668d85 commit e0fc2fe

5 files changed

Lines changed: 30 additions & 1 deletion

File tree

src/backend/access/heap/heapam.c

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2319,7 +2319,10 @@ heap_insert(Relation relation, HeapTuple tup, CommandId cid,
23192319
* buffer.
23202320
*/
23212321
if (IsSystemRelation(relation))
2322+
{
2323+
system_relation_modified = true;
23222324
CacheInvalidateHeapTuple(relation, heaptup, NULL);
2325+
}
23232326

23242327
/* Note: speculative insertions are counted too, even if aborted later */
23252328
pgstat_count_heap_insert(relation, 1);
@@ -2719,6 +2722,7 @@ heap_multi_insert(Relation relation, TupleTableSlot **slots, int ntuples,
27192722
*/
27202723
if (IsCatalogRelation(relation))
27212724
{
2725+
system_relation_modified = true;
27222726
for (i = 0; i < ntuples; i++)
27232727
CacheInvalidateHeapTuple(relation, heaptuples[i], NULL);
27242728
}
@@ -3203,6 +3207,11 @@ heap_delete(Relation relation, ItemPointer tid,
32033207
*/
32043208
CacheInvalidateHeapTuple(relation, &tp, NULL);
32053209

3210+
if (IsCatalogRelation(relation))
3211+
{
3212+
system_relation_modified = true;
3213+
}
3214+
32063215
/* Now we can release the buffer */
32073216
ReleaseBuffer(buffer);
32083217

@@ -4142,6 +4151,11 @@ heap_update_internal(Relation relation, ItemPointer otid, HeapTuple newtup,
41424151
*/
41434152
CacheInvalidateHeapTuple(relation, &oldtup, heaptup);
41444153

4154+
if (IsCatalogRelation(relation))
4155+
{
4156+
system_relation_modified = true;
4157+
}
4158+
41454159
/* Now we can release the buffer(s) */
41464160
if (newbuf != buffer)
41474161
ReleaseBuffer(newbuf);
@@ -6270,6 +6284,11 @@ heap_inplace_update(Relation relation, HeapTuple tuple)
62706284
*/
62716285
if (!IsBootstrapProcessingMode())
62726286
CacheInvalidateHeapTuple(relation, tuple, NULL);
6287+
6288+
if (IsCatalogRelation(relation))
6289+
{
6290+
system_relation_modified = true;
6291+
}
62736292
}
62746293

62756294
#define FRM_NOOP 0x0001

src/backend/access/transam/xact.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "access/xloginsert.h"
3333
#include "access/xact_storage_tablespace.h"
3434
#include "access/xlogutils.h"
35+
#include "catalog/catalog.h"
3536
#include "catalog/index.h"
3637
#include "catalog/namespace.h"
3738
#include "catalog/pg_enum.h"
@@ -2785,6 +2786,8 @@ CommitTransaction(void)
27852786
if (Gp_role == GP_ROLE_EXECUTE && !Gp_is_writer)
27862787
elog(DEBUG1,"CommitTransaction: called as segment Reader");
27872788

2789+
system_relation_modified = false;
2790+
27882791
/*
27892792
* Do pre-commit processing that involves calling user-defined code, such
27902793
* as triggers. SECURITY_RESTRICTED_OPERATION contexts must not queue an
@@ -3519,6 +3522,8 @@ AbortTransaction(void)
35193522
*/
35203523
s->state = TRANS_ABORT;
35213524

3525+
system_relation_modified = false;
3526+
35223527
/*
35233528
* Reset user ID which might have been changed transiently. We need this
35243529
* to clean up in case control escaped out of a SECURITY DEFINER function

src/backend/catalog/catalog.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888

8989
static bool IsAoSegmentClass(Form_pg_class reltuple);
9090
static bool IsExtAuxClass(Form_pg_class reltuple);
91+
bool system_relation_modified = false;
9192

9293
/*
9394
* Like relpath(), but gets the directory containing the data file

src/backend/cdb/dispatcher/cdbdisp_query.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "access/xact.h"
2020
#include "libpq-fe.h"
2121
#include "libpq-int.h"
22+
#include "catalog/catalog.h"
2223
#include "cdb/cdbconn.h"
2324
#include "cdb/cdbgang.h"
2425
#include "cdb/cdbutil.h"
@@ -486,7 +487,8 @@ cdbdisp_dispatchCommandInternal(DispatchCommandQueryParms *pQueryParms,
486487
* To fix this issue, we should drop the idle reader gangs after each
487488
* utility statement which may modify the catalog table.
488489
*/
489-
ds->destroyIdleReaderGang = true;
490+
if (system_relation_modified)
491+
ds->destroyIdleReaderGang = true;
490492

491493
queryText = buildGpQueryString(pQueryParms, &queryTextLength);
492494

src/include/catalog/catalog.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,6 @@ extern void reldir_and_filename(RelFileNode rnode, BackendId backend, ForkNumber
5757
char **dir, char **filename);
5858
extern char *aorelpathbackend(RelFileNode node, BackendId backend, int32 segno);
5959

60+
extern bool system_relation_modified;
61+
6062
#endif /* CATALOG_H */

0 commit comments

Comments
 (0)