@@ -39,6 +39,8 @@ typedef struct SrPlanCachedInfo {
39
39
Oid schema_oid ;
40
40
Oid sr_plans_oid ;
41
41
Oid sr_index_oid ;
42
+ Oid reloids_index_oid ;
43
+ Oid index_reloids_index_oid ;
42
44
const char * query_text ;
43
45
}SrPlanCachedInfo ;
44
46
@@ -51,6 +53,8 @@ static SrPlanCachedInfo cachedInfo = {
51
53
InvalidOid ,/* schema_oid */
52
54
InvalidOid ,/* sr_plans_reloid */
53
55
InvalidOid ,/* sr_plans_index_oid */
56
+ InvalidOid ,/* reloids_index_oid */
57
+ InvalidOid ,/* index_reloids_index_oid */
54
58
NULL
55
59
};
56
60
@@ -101,11 +105,19 @@ invalidate_oids(void)
101
105
{
102
106
cachedInfo .schema_oid = InvalidOid ;
103
107
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 ;
104
112
}
105
113
106
114
static void
107
115
init_sr_plan (void )
108
116
{
117
+ char * schema_name ;
118
+ List * func_name_list ;
119
+
120
+ Oid args [1 ]= {ANYELEMENTOID };
109
121
static bool relcache_callback_needed = true;
110
122
111
123
cachedInfo .schema_oid = get_sr_plan_schema ();
@@ -116,11 +128,25 @@ init_sr_plan(void)
116
128
SR_PLANS_TABLE_QUERY_INDEX_NAME );
117
129
cachedInfo .sr_plans_oid = sr_get_relname_oid (cachedInfo .schema_oid ,
118
130
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 );
119
135
120
136
if (cachedInfo .sr_plans_oid == InvalidOid ||
121
137
cachedInfo .sr_index_oid == InvalidOid )
122
138
elog (ERROR ,"sr_plan extension installed incorrectly" );
123
139
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
+
124
150
if (relcache_callback_needed )
125
151
{
126
152
CacheRegisterRelcacheCallback (sr_plan_relcache_hook ,PointerGetDatum (NULL ));
@@ -387,9 +413,7 @@ sr_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
387
413
Relation sr_plans_heap ,
388
414
sr_index_rel ;
389
415
HeapTuple tuple ;
390
- char * schema_name ;
391
416
char * plan_text ;
392
- List * func_name_list ;
393
417
Snapshot snapshot ;
394
418
ScanKeyData key ;
395
419
bool found ;
@@ -424,33 +448,10 @@ sr_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
424
448
425
449
if (cachedInfo .schema_oid == InvalidOid )
426
450
{
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
- return pl_stmt ;
433
- }
434
- }
435
-
436
- if (cachedInfo .fake_func )
437
- {
438
- HeapTuple ftup ;
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
- Oid args [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
+ return pl_stmt ;
454
455
}
455
456
456
457
/* Make list with all _p functions and his position */
@@ -546,25 +547,17 @@ sr_planner(Query *parse, int cursorOptions, ParamListInfo boundParams)
546
547
struct IndexIds index_ids = {NIL };
547
548
548
549
Relation reloids_index_rel ;
549
- Oid reloids_index_oid ;
550
-
551
550
Relation index_reloids_index_rel ;
552
- Oid index_reloids_index_oid ;
553
551
554
552
ArrayType * reloids = NULL ;
555
553
ArrayType * index_reloids = NULL ;
556
554
Datum values [Anum_sr_attcount ];
557
555
bool nulls [Anum_sr_attcount ];
558
-
559
556
int reloids_len = list_length (pl_stmt -> relationOids );
560
557
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 );
568
561
569
562
MemSet (nulls ,0 ,sizeof (nulls ));
570
563