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

Commit1c6f8e3

Browse files
committed
Cache more variables
1 parent0f26132 commit1c6f8e3

File tree

1 file changed

+33
-40
lines changed

1 file changed

+33
-40
lines changed

‎sr_plan.c

Lines changed: 33 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ typedef struct SrPlanCachedInfo {
3939
Oidschema_oid;
4040
Oidsr_plans_oid;
4141
Oidsr_index_oid;
42+
Oidreloids_index_oid;
43+
Oidindex_reloids_index_oid;
4244
constchar*query_text;
4345
}SrPlanCachedInfo;
4446

@@ -51,6 +53,8 @@ static SrPlanCachedInfo cachedInfo = {
5153
InvalidOid,/* schema_oid */
5254
InvalidOid,/* sr_plans_reloid */
5355
InvalidOid,/* sr_plans_index_oid */
56+
InvalidOid,/* reloids_index_oid */
57+
InvalidOid,/* index_reloids_index_oid */
5458
NULL
5559
};
5660

@@ -101,11 +105,19 @@ invalidate_oids(void)
101105
{
102106
cachedInfo.schema_oid=InvalidOid;
103107
cachedInfo.sr_plans_oid=InvalidOid;
108+
cachedInfo.sr_index_oid=InvalidOid;
109+
cachedInfo.fake_func=InvalidOid;
110+
cachedInfo.reloids_index_oid=InvalidOid;
111+
cachedInfo.index_reloids_index_oid=InvalidOid;
104112
}
105113

106114
staticvoid
107115
init_sr_plan(void)
108116
{
117+
char*schema_name;
118+
List*func_name_list;
119+
120+
Oidargs[1]= {ANYELEMENTOID};
109121
staticboolrelcache_callback_needed= true;
110122

111123
cachedInfo.schema_oid=get_sr_plan_schema();
@@ -116,11 +128,25 @@ init_sr_plan(void)
116128
SR_PLANS_TABLE_QUERY_INDEX_NAME);
117129
cachedInfo.sr_plans_oid=sr_get_relname_oid(cachedInfo.schema_oid,
118130
SR_PLANS_TABLE_NAME);
131+
cachedInfo.reloids_index_oid=sr_get_relname_oid(cachedInfo.schema_oid,
132+
SR_PLANS_RELOIDS_INDEX);
133+
cachedInfo.index_reloids_index_oid=sr_get_relname_oid(cachedInfo.schema_oid,
134+
SR_PLANS_INDEX_RELOIDS_INDEX);
119135

120136
if (cachedInfo.sr_plans_oid==InvalidOid||
121137
cachedInfo.sr_index_oid==InvalidOid)
122138
elog(ERROR,"sr_plan extension installed incorrectly");
123139

140+
/* Initialize _p function Oid */
141+
schema_name=get_namespace_name(cachedInfo.schema_oid);
142+
func_name_list=list_make2(makeString(schema_name),makeString("_p"));
143+
cachedInfo.fake_func=LookupFuncName(func_name_list,1,args, true);
144+
list_free(func_name_list);
145+
pfree(schema_name);
146+
147+
if (cachedInfo.fake_func==InvalidOid)
148+
elog(ERROR,"sr_plan extension installed incorrectly");
149+
124150
if (relcache_callback_needed)
125151
{
126152
CacheRegisterRelcacheCallback(sr_plan_relcache_hook,PointerGetDatum(NULL));
@@ -387,9 +413,7 @@ sr_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
387413
Relationsr_plans_heap,
388414
sr_index_rel;
389415
HeapTupletuple;
390-
char*schema_name;
391416
char*plan_text;
392-
List*func_name_list;
393417
Snapshotsnapshot;
394418
ScanKeyDatakey;
395419
boolfound;
@@ -424,33 +448,10 @@ sr_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
424448

425449
if (cachedInfo.schema_oid==InvalidOid)
426450
{
427-
if (!OidIsValid(cachedInfo.schema_oid))
428-
{
429-
/* Just call standard_planner() if schema doesn't exist. */
430-
pl_stmt=call_standard_planner();
431-
level--;
432-
returnpl_stmt;
433-
}
434-
}
435-
436-
if (cachedInfo.fake_func)
437-
{
438-
HeapTupleftup;
439-
ftup=SearchSysCache1(PROCOID,ObjectIdGetDatum(cachedInfo.fake_func));
440-
if (!HeapTupleIsValid(ftup))
441-
cachedInfo.fake_func=0;
442-
else
443-
ReleaseSysCache(ftup);
444-
}
445-
else
446-
{
447-
Oidargs[1]= {ANYELEMENTOID};
448-
449-
schema_name=get_namespace_name(cachedInfo.schema_oid);
450-
func_name_list=list_make2(makeString(schema_name),makeString("_p"));
451-
cachedInfo.fake_func=LookupFuncName(func_name_list,1,args, true);
452-
list_free(func_name_list);
453-
pfree(schema_name);
451+
/* Just call standard_planner() if schema doesn't exist. */
452+
pl_stmt=call_standard_planner();
453+
level--;
454+
returnpl_stmt;
454455
}
455456

456457
/* Make list with all _p functions and his position */
@@ -546,25 +547,17 @@ sr_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
546547
structIndexIdsindex_ids= {NIL};
547548

548549
Relationreloids_index_rel;
549-
Oidreloids_index_oid;
550-
551550
Relationindex_reloids_index_rel;
552-
Oidindex_reloids_index_oid;
553551

554552
ArrayType*reloids=NULL;
555553
ArrayType*index_reloids=NULL;
556554
Datumvalues[Anum_sr_attcount];
557555
boolnulls[Anum_sr_attcount];
558-
559556
intreloids_len=list_length(pl_stmt->relationOids);
560557

561-
/* prepare relation for reloids index too */
562-
reloids_index_oid=sr_get_relname_oid(cachedInfo.schema_oid,SR_PLANS_RELOIDS_INDEX);
563-
reloids_index_rel=index_open(reloids_index_oid,heap_lock);
564-
565-
/* prepare relation for reloids index too */
566-
index_reloids_index_oid=sr_get_relname_oid(cachedInfo.schema_oid,SR_PLANS_INDEX_RELOIDS_INDEX);
567-
index_reloids_index_rel=index_open(index_reloids_index_oid,heap_lock);
558+
/* prepare indexes */
559+
reloids_index_rel=index_open(cachedInfo.reloids_index_oid,heap_lock);
560+
index_reloids_index_rel=index_open(cachedInfo.index_reloids_index_oid,heap_lock);
568561

569562
MemSet(nulls,0,sizeof(nulls));
570563

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp