Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb496441

Browse files
committed
Fix the two stupid bugs. Intro AQO memory context for long-live data.
1 parentaf99598 commitb496441

File tree

5 files changed

+26
-6
lines changed

5 files changed

+26
-6
lines changed

‎aqo.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,12 @@ boolexplain_aqo;
5050
instr_timequery_starttime;
5151
doublequery_planning_time;
5252

53+
/*
54+
* Currently we use it only to store query_text string which is initialized
55+
* after a query parsing and is used during the query planning.
56+
*/
57+
MemoryContextAQOMemoryContext;
58+
5359
/* Saved hook values */
5460
post_parse_analyze_hook_typeprev_post_parse_analyze_hook;
5561
planner_hook_typeprev_planner_hook;
@@ -105,6 +111,8 @@ _PG_init(void)
105111
ExplainOnePlan_hook=print_into_explain;
106112

107113
init_deactivated_queries_storage();
114+
115+
AQOMemoryContext=AllocSetContextCreate(TopMemoryContext,"AQOMemoryContext",ALLOCSET_DEFAULT_SIZES);
108116
}
109117

110118
PG_FUNCTION_INFO_V1(invalidate_deactivated_queries_cache);

‎aqo.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
#include"utils/builtins.h"
143143
#include"utils/guc.h"
144144
#include"utils/hsearch.h"
145+
#include"utils/memutils.h"
145146
#include"utils/rel.h"
146147
#include"utils/tqual.h"
147148
#include"utils/fmgroids.h"
@@ -217,6 +218,9 @@ extern bool explain_aqo;
217218
externinstr_timequery_starttime;
218219
externdoublequery_planning_time;
219220

221+
/* Memory context for long-live data */
222+
externMemoryContextAQOMemoryContext;
223+
220224
/* Saved hook values in case of unload */
221225
externpost_parse_analyze_hook_typeprev_post_parse_analyze_hook;
222226
externplanner_hook_typeprev_planner_hook;

‎auto_tuning.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ is_in_infinite_loop_cq(double *elems, int nelems)
106106
* we cannot execute queries on our own wish, so the tuning now is in setting
107107
* use_aqo and learn_aqo parameters for the query type.
108108
*
109-
* Now the workflow is quitesimlple:
109+
* Now the workflow is quitesimple:
110110
*
111111
* Firstly, we run a new query type auto_tuning_window_size times without our
112112
* method to have an execution time statistics for such type of queries.

‎machine_learning.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,14 @@ OkNNr_predict(int matrix_rows, int matrix_cols,
116116
if (idx[i]!=-1)
117117
result+=targets[idx[i]]*w[i] /w_sum;
118118

119-
pfree(distances);
120-
pfree(idx);
121-
pfree(w);
122-
123119
/* this should never happen */
124120
if (idx[0]==-1)
125121
return-1;
126122

123+
pfree(distances);
124+
pfree(idx);
125+
pfree(w);
126+
127127
if (result<0)
128128
result=0;
129129
returnresult;

‎preprocessing.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,16 @@ static bool isQueryUsingSystemRelation_walker(Node *node, void *context);
6767
void
6868
get_query_text(ParseState*pstate,Query*query)
6969
{
70+
MemoryContextoldCxt;
71+
72+
/*
73+
* Duplicate query string into private AQO memory context for guard
74+
* from possible memory context switching.
75+
*/
76+
oldCxt=MemoryContextSwitchTo(AQOMemoryContext);
7077
if (pstate)
71-
Assert((query_text=strdup(pstate->p_sourcetext))!=NULL);
78+
query_text=pstrdup(pstate->p_sourcetext);
79+
MemoryContextSwitchTo(oldCxt);
7280

7381
if (prev_post_parse_analyze_hook)
7482
prev_post_parse_analyze_hook(pstate,query);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp