@@ -37,7 +37,6 @@ typedef struct
3737#define IsPlusInfinity (i )( (i)->is_infinite == PLUS_INFINITY )
3838#define IsMinusInfinity (i )( (i)->is_infinite == MINUS_INFINITY )
3939
40-
4140static inline Bound
4241CopyBound (const Bound * src ,bool byval ,int typlen )
4342{
@@ -75,6 +74,13 @@ BoundGetValue(const Bound *bound)
7574return bound -> value ;
7675}
7776
77+ static inline void
78+ FreeBound (Bound * bound ,bool byval )
79+ {
80+ if (!IsInfinite (bound )&& !byval )
81+ pfree (DatumGetPointer (BoundGetValue (bound )));
82+ }
83+
7884static inline int
7985cmp_bounds (FmgrInfo * cmp_func ,const Bound * b1 ,const Bound * b2 )
8086{
@@ -97,7 +103,7 @@ cmp_bounds(FmgrInfo *cmp_func, const Bound *b1, const Bound *b2)
97103 */
98104typedef enum
99105{
100- PT_INDIFFERENT = 0 ,/* for part type traits (virtual type) */
106+ PT_ANY = 0 ,/* for part type traits (virtual type) */
101107PT_HASH ,
102108PT_RANGE
103109}PartType ;
@@ -122,11 +128,14 @@ typedef struct
122128bool valid ;/* is this entry valid? */
123129bool enable_parent ;/* include parent to the plan */
124130
131+ PartType parttype ;/* partitioning type (HASH | RANGE) */
132+
125133uint32 children_count ;
126134Oid * children ;/* Oids of child partitions */
127135RangeEntry * ranges ;/* per-partition range entry or NULL */
128136
129- PartType parttype ;/* partitioning type (HASH | RANGE) */
137+ const char * attname ;/* name of the partitioned column */
138+
130139AttrNumber attnum ;/* partitioned column's index */
131140Oid atttype ;/* partitioned column's type */
132141int32 atttypmod ;/* partitioned column type modifier */
@@ -140,7 +149,7 @@ typedef struct
140149}PartRelationInfo ;
141150
142151/*
143- *RelParentInfo
152+ *PartParentInfo
144153 *Cached parent of the specified partition.
145154 *Allows us to quickly search for PartRelationInfo.
146155 */
@@ -150,12 +159,24 @@ typedef struct
150159Oid parent_rel ;
151160}PartParentInfo ;
152161
162+ /*
163+ * PartBoundInfo
164+ *Cached bounds of the specified partition.
165+ */
153166typedef struct
154167{
155168Oid child_rel ;/* key */
156- Oid conid ;
157- Expr * constraint ;
158- }PartConstraintInfo ;
169+
170+ PartType parttype ;
171+
172+ /* For RANGE partitions */
173+ Bound range_min ;
174+ Bound range_max ;
175+ bool byval ;
176+
177+ /* For HASH partitions */
178+ uint32 hash ;
179+ }PartBoundInfo ;
159180
160181/*
161182 * PartParentSearch
@@ -220,38 +241,50 @@ void cache_parent_of_partition(Oid partition, Oid parent);
220241Oid forget_parent_of_partition (Oid partition ,PartParentSearch * status );
221242Oid get_parent_of_partition (Oid partition ,PartParentSearch * status );
222243
223- /* Constraint cache */
224- void forget_constraint_of_partition (Oid partition );
225- Expr * get_constraint_of_partition (Oid partition ,AttrNumber part_attno );
244+ /* Bounds cache */
245+ void forget_bounds_of_partition (Oid partition );
246+ PartBoundInfo * get_bounds_of_partition (Oid partition ,
247+ const PartRelationInfo * prel );
226248
227249/* Safe casts for PartType */
228250PartType DatumGetPartType (Datum datum );
229251char * PartTypeToCString (PartType parttype );
230252
231253/* PartRelationInfo checker */
232- void shout_if_prel_is_invalid (Oid parent_oid ,
254+ void shout_if_prel_is_invalid (const Oid parent_oid ,
233255const PartRelationInfo * prel ,
234- PartType expected_part_type );
256+ const PartType expected_part_type );
235257
236258
237259/*
238- * Usefulstatic functions for freeing memory.
260+ * Useful functions & macros for freeing memory.
239261 */
240262
263+ #define FreeIfNotNull (ptr ) \
264+ do { \
265+ if (ptr) \
266+ { \
267+ pfree((void *) ptr); \
268+ ptr = NULL; \
269+ } \
270+ } while(0)
271+
241272static inline void
242273FreeChildrenArray (PartRelationInfo * prel )
243274{
244275uint32 i ;
245276
246- Assert (PrelIsValid (prel ));
247-
248277/* Remove relevant PartParentInfos */
249278if (prel -> children )
250279{
251280for (i = 0 ;i < PrelChildrenCount (prel );i ++ )
252281{
253282Oid child = prel -> children [i ];
254283
284+ /* Skip if Oid is invalid (e.g. initialization error) */
285+ if (!OidIsValid (child ))
286+ continue ;
287+
255288/* If it's *always been* relid's partition, free cache */
256289if (PrelParentRelid (prel )== get_parent_of_partition (child ,NULL ))
257290forget_parent_of_partition (child ,NULL );
@@ -267,8 +300,6 @@ FreeRangesArray(PartRelationInfo *prel)
267300{
268301uint32 i ;
269302
270- Assert (PrelIsValid (prel ));
271-
272303/* Remove RangeEntries array */
273304if (prel -> ranges )
274305{
@@ -277,11 +308,14 @@ FreeRangesArray(PartRelationInfo *prel)
277308{
278309for (i = 0 ;i < PrelChildrenCount (prel );i ++ )
279310{
280- if (!IsInfinite (& prel -> ranges [i ].min ))
281- pfree (DatumGetPointer (BoundGetValue (& prel -> ranges [i ].min )));
311+ Oid child = prel -> ranges [i ].child_oid ;
282312
283- if (!IsInfinite (& prel -> ranges [i ].max ))
284- pfree (DatumGetPointer (BoundGetValue (& prel -> ranges [i ].max )));
313+ /* Skip if Oid is invalid (e.g. initialization error) */
314+ if (!OidIsValid (child ))
315+ continue ;
316+
317+ FreeBound (& prel -> ranges [i ].min ,prel -> attbyval );
318+ FreeBound (& prel -> ranges [i ].max ,prel -> attbyval );
285319}
286320}
287321
@@ -290,5 +324,4 @@ FreeRangesArray(PartRelationInfo *prel)
290324}
291325}
292326
293-
294327#endif /* RELATION_INFO_H */