8000 Fix issues found by a check-world stress test with enabled AQO · postgrespro/aqo@fa3ea86 · GitHub
[go: up one dir, main page]

Skip to content

Commit fa3ea86

Browse files
committed
Fix issues found by a check-world stress test with enabled AQO
1 parent ba3de97 commit fa3ea86

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

postprocessing.c

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,12 @@ typedef struct
4242
static double cardinality_sum_errors;
4343
static int cardinality_num_objects;
4444

45-
/* It is needed to recognize stored Query-related aqo data in the query
45+
/*
46+
* Store an AQO-related query data into the Query Environment structure.
47+
*
48+
* It is very sad that we have to use such unsuitable field, but alternative is
49+
* to introduce a private field in a PlannedStmt struct.
50+
* It is needed to recognize stored Query-related aqo data in the query
4651
* environment field.
4752
*/
4853
static char *AQOPrivateData = "AQOPrivateData";
@@ -751,16 +756,20 @@ StoreToQueryEnv(QueryDesc *queryDesc)
751756
EphemeralNamedRelation enr;
752757
int qcsize = sizeof(QueryContextData);
753758
MemoryContext oldCxt;
759+
bool newentry = false;
754760

755-
oldCxt = MemoryContextSwitchTo(GetMemoryChunkContext(queryDesc));
761+
oldCxt = MemoryContextSwitchTo(GetMemoryChunkContext(queryDesc->plannedstmt));
756762

757763
if (queryDesc->queryEnv == NULL)
758764
queryDesc->queryEnv = create_queryEnv();
759765

760766
enr = get_ENR(queryDesc->queryEnv, AQOPrivateData);
761767
if (enr == NULL)
768+
{
762769
/* If such query environment don't exists, allocate new. */
763770
enr = palloc0(sizeof(EphemeralNamedRelationData));
771+
newentry = true;
772+
}
764773

765774
enr->md.name = AQOPrivateData;
766775
enr->md.enrtuples = 0;
@@ -770,7 +779,9 @@ StoreToQueryEnv(QueryDesc *queryDesc)
770779
enr->reldata = palloc0(qcsize);
771780
memcpy(enr->reldata, &query_context, qcsize);
772781

773-
register_ENR(queryDesc->queryEnv, enr);
782+
if (newentry)
783+
register_ENR(queryDesc->queryEnv, enr);
784+
774785
MemoryContextSwitchTo(oldCxt);
775786
}
776787

@@ -794,19 +805,23 @@ StorePlanInternals(QueryDesc *queryDesc)
794805
{
795806
EphemeralNamedRelation enr;
796807
MemoryContext oldCxt;
808+
bool newentry = false;
797809

798810
njoins = 0;
799811
planstate_tree_walker(queryDesc->planstate, calculateJoinNum, &njoins);
800812

801-
oldCxt = MemoryContextSwitchTo(GetMemoryChunkContext(queryDesc));
813+
oldCxt = MemoryContextSwitchTo(GetMemoryChunkContext(queryDesc->plannedstmt));
802814

803815
if (queryDesc->queryEnv == NULL)
804816
queryDesc->queryEnv = create_queryEnv();
805817

806818
enr = get_ENR(queryDesc->queryEnv, PlanStateInfo);
807819
if (enr == NULL)
808-
/* If such query environment don't exists, allocate new. */
820+
{
821+
/* If such query environment field doesn't exist, allocate new. */
809822
enr = palloc0(sizeof(EphemeralNamedRelationData));
823+
newentry = true;
824+
}
810825

811826
enr->md.name = PlanStateInfo;
812827
enr->md.enrtuples = 0;
@@ -815,7 +830,10 @@ StorePlanInternals(QueryDesc *queryDesc)
815830
enr->md.tupdesc = NULL;
816831
enr->reldata = palloc0(sizeof(int));
817832
memcpy(enr->reldata, &njoins, sizeof(int));
818-
register_ENR(queryDesc->queryEnv, enr);
833+
834+
if (newentry)
835+
register_ENR(queryDesc->queryEnv, enr);
836+
819837
MemoryContextSwitchTo(oldCxt);
820838
}
821839

profile_mem.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,8 +232,6 @@ profile_shmem_startup(void)
232232
if (aqo_profile_classes <= 0)
233233
return;
234234

235-
Assert(profile_mem_queries == NULL);
236-
237235
ctl.keysize = sizeof(int);
238236
ctl.entrysize = sizeof(ProfileMemEntry);
239237
profile_mem_queries = ShmemInitHash("aqo_profile_mem_queries",

0 commit comments

Comments
 (0)
0