12
12
#include "runtimeappend.h"
13
13
#include "utils.h"
14
14
15
+ #include "access/sysattr.h"
15
16
#include "optimizer/restrictinfo.h"
17
+ #include "optimizer/var.h"
16
18
#include "utils/memutils.h"
17
19
18
20
@@ -248,6 +250,38 @@ unpack_runtimeappend_private(RuntimeAppendState *scan_state, CustomScan *cscan)
248
250
scan_state -> enable_parent = (bool )linitial_int (lthird (runtimeappend_private ));
249
251
}
250
252
253
+ /*
254
+ * Filter all available clauses and extract relevant ones.
255
+ */
256
+ List *
257
+ get_partitioned_attr_clauses (List * restrictinfo_list ,
258
+ const PartRelationInfo * prel ,
259
+ Index partitioned_rel )
260
+ {
261
+ #define AdjustAttno (attno ) \
262
+ ( (AttrNumber) (part_attno + FirstLowInvalidHeapAttributeNumber) )
263
+
264
+ List * result = NIL ;
265
+ ListCell * l ;
266
+
267
+ foreach (l ,restrictinfo_list )
268
+ {
269
+ RestrictInfo * rinfo = (RestrictInfo * )lfirst (l );
270
+ Bitmapset * varattnos = NULL ;
271
+ int part_attno ;
272
+
273
+ Assert (IsA (rinfo ,RestrictInfo ));
274
+ pull_varattnos ((Node * )rinfo -> clause ,partitioned_rel ,& varattnos );
275
+
276
+ if (bms_get_singleton_member (varattnos ,& part_attno )&&
277
+ AdjustAttno (part_attno )== prel -> attnum )
278
+ {
279
+ result = lappend (result ,rinfo -> clause );
280
+ }
281
+ }
282
+ return result ;
283
+ }
284
+
251
285
252
286
/* Transform partition ranges into plain array of partition Oids */
253
287
Oid *
@@ -385,7 +419,7 @@ create_append_plan_common(PlannerInfo *root, RelOptInfo *rel,
385
419
Plan * child_plan = (Plan * )lfirst (lc2 );
386
420
RelOptInfo * child_rel = ((Path * )lfirst (lc1 ))-> parent ;
387
421
388
- /* Replace rel's tlist with a matching one */
422
+ /* Replace rel's tlist with a matching one */
389
423
if (!cscan -> scan .plan .targetlist )
390
424
tlist = replace_tlist_varnos (child_plan -> targetlist ,rel );
391
425
@@ -407,7 +441,7 @@ create_append_plan_common(PlannerInfo *root, RelOptInfo *rel,
407
441
/* Since we're not scanning any real table directly */
408
442
cscan -> scan .scanrelid = 0 ;
409
443
410
- cscan -> custom_exprs = get_actual_clauses (clauses );
444
+ cscan -> custom_exprs = get_partitioned_attr_clauses (clauses , prel , rel -> relid );
411
445
cscan -> custom_plans = custom_plans ;
412
446
cscan -> methods = scan_methods ;
413
447