yjhjstz commented on code in PR #724:
URL: https://github.com/apache/cloudberry/pull/724#discussion_r1857443716


##########
src/backend/executor/nodeHash.c:
##########
@@ -4126,3 +4151,138 @@ get_hash_mem(void)
 
        return (int) mem_limit;
 }
+
+/*
+ * Convert AttrFilter to ScanKeyData and send these runtime filters to the
+ * target node(seqscan).
+ */
+void
+PushdownRuntimeFilter(HashState *node)
+{
+       ListCell        *lc;
+       List            *scankeys;
+       ScanKey         sk;
+       AttrFilter      *attr_filter;
+
+       foreach (lc, node->filters)
+       {
+               scankeys = NIL;
+
+               attr_filter = lfirst(lc);
+               if (!IsA(attr_filter->target, SeqScanState) || 
attr_filter->empty)
+                       continue;
+
+               /* bloom filter */
+               sk = (ScanKey)palloc0(sizeof(ScanKeyData));
+               sk->sk_flags    = SK_BLOOM_FILTER;
+               sk->sk_attno    = attr_filter->lattno;
+               sk->sk_subtype  = INT8OID;
+               sk->sk_argument = PointerGetDatum(attr_filter->blm_filter);
+               scankeys = lappend(scankeys, sk);
+
+               /* range filter */
+               sk = (ScanKey)palloc0(sizeof(ScanKeyData));
+               sk->sk_flags    = 0;
+               sk->sk_attno    = attr_filter->lattno;
+               sk->sk_strategy = BTGreaterEqualStrategyNumber;
+               sk->sk_subtype  = INT8OID;
+               sk->sk_argument = attr_filter->min;
+               scankeys = lappend(scankeys, sk);
+
+               sk = (ScanKey)palloc0(sizeof(ScanKeyData));
+               sk->sk_flags    = 0;
+               sk->sk_attno    = attr_filter->lattno;
+               sk->sk_strategy = BTLessEqualStrategyNumber;
+               sk->sk_subtype  = INT8OID;
+               sk->sk_argument = attr_filter->max;
+               scankeys = lappend(scankeys, sk);
+
+               /* append new runtime filters to target node */
+               SeqScanState *sss = castNode(SeqScanState, attr_filter->target);
+               sss->filters = list_concat(sss->filters, scankeys);

Review Comment:
   ```sql
   create table t1(a int, b int) with(parallel_workers=2);
   create table rt1(a int, b int) with(parallel_workers=2);
   create table rt2(a int, b int);
   create table rt3(a int, b int);
   insert into t1 select i, i from generate_series(1, 100000) i;
   insert into t1 select i, i+1 from generate_series(1, 10) i;
   insert into rt1 select i, i+1 from generate_series(1, 10) i;
   insert into rt2 select i, i+1 from generate_series(1, 10000) i;
   insert into rt3 select i, i+1 from generate_series(1, 10) i;
   analyze t1;
   analyze rt1;
   analyze rt2;
   analyze rt3;
   
   explain analyze select * from rt1 join t1 on rt1.a = t1.b join rt3 on rt3.a 
= t1.b;
   
   postgres=# explain select * from rt1 join t1 on rt1.a = t1.b join rt3 on 
rt3.a = t1.b;
                                      QUERY PLAN                                
   
   
--------------------------------------------------------------------------------
    Gather Motion 3:1  (slice1; segments: 3)  (cost=2.45..428.51 rows=17 
width=24)
      ->  Hash Join  (cost=2.45..428.29 rows=6 width=24)
            Hash Cond: (t1.b = rt1.a)
            ->  Hash Join  (cost=1.23..427.00 rows=6 width=16)
                  Hash Cond: (t1.b = rt3.a)
                  ->  Seq Scan on t1  (cost=0.00..342.37 rows=33337 width=8)
                  ->  Hash  (cost=1.10..1.10 rows=10 width=8)
                        ->  Seq Scan on rt3  (cost=0.00..1.10 rows=10 width=8)
            ->  Hash  (cost=1.10..1.10 rows=10 width=8)
                  ->  Seq Scan on rt1  (cost=0.00..1.10 rows=10 width=8)
    Optimizer: Postgres query optimizer
   (11 rows)
   
   ```
   you can try this case, will got two range filters.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscr...@cloudberry.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@cloudberry.apache.org
For additional commands, e-mail: commits-h...@cloudberry.apache.org

Reply via email to