3636
3737namespace pax {
3838
39- void PaxSparseFilter::Initialize (List *quals) {
39+ void PaxSparseFilter::Initialize (List *quals, ScanKey key, int nkeys ) {
4040 ListCell *qual_cell;
4141 std::vector<std::shared_ptr<PFTNode>> fl_nodes; /* first level nodes */
4242 std::string origin_tree_str;
4343
4444 // no inited
4545 Assert (!filter_tree_);
4646
47- if (!quals) {
47+ if (!quals && nkeys == 0 ) {
4848 return ;
4949 }
5050
@@ -57,6 +57,23 @@ void PaxSparseFilter::Initialize(List *quals) {
5757 fl_nodes.emplace_back (std::move (fl_node));
5858 }
5959
60+ // walk scan key and only support min/max filter now
61+ for (int i = 0 ; i < nkeys; i++) {
62+ // TODO: support bloom filter in PaxFilter
63+ // but now just skip it, SeqNext() will check bloom filter in PassByBloomFilter()
64+ if (key[i].sk_flags & SK_BLOOM_FILTER) {
65+ continue ;
66+ }
67+
68+ if (key[i].sk_strategy != BTGreaterEqualStrategyNumber &&
69+ key[i].sk_strategy != BTLessEqualStrategyNumber) {
70+ continue ;
71+ }
72+ std::shared_ptr<PFTNode> fl_node = ProcessScanKey (&key[i]);
73+ Assert (fl_node);
74+ fl_nodes.emplace_back (std::move (fl_node));
75+ }
76+
6077 // build the root of `filter_tree_`
6178 BuildPFTRoot (fl_nodes);
6279 if (pax_log_filter_tree) origin_tree_str = DebugString ();
@@ -67,6 +84,47 @@ void PaxSparseFilter::Initialize(List *quals) {
6784 origin_tree_str.c_str (), DebugString ().c_str ());
6885}
6986
87+ std::shared_ptr<PFTNode> PaxSparseFilter::ProcessScanKey (ScanKey key) {
88+ std::shared_ptr<PFTNode> node = nullptr ;
89+ Assert (key);
90+ Assert (!(key->sk_flags & SK_BLOOM_FILTER));
91+ Assert (key->sk_strategy == BTGreaterEqualStrategyNumber ||
92+ key->sk_strategy == BTLessEqualStrategyNumber);
93+ Assert (key->sk_attno > 0 &&
94+ key->sk_attno <= RelationGetNumberOfAttributes (rel_));
95+
96+ AttrNumber attno = key->sk_attno ;
97+
98+ // Build VarNode on the left
99+ auto var_node = std::make_shared<VarNode>();
100+ var_node->attrno = attno;
101+
102+ // Build ConstNode on the right from ScanKey
103+ auto const_node = std::make_shared<ConstNode>();
104+ const_node->const_val = key->sk_argument ;
105+ const_node->const_type = key->sk_subtype ;
106+ if (key->sk_flags & SK_ISNULL) {
107+ const_node->sk_flags |= SK_ISNULL;
108+ }
109+
110+ // Build OpNode and attach children: (var, const)
111+ auto op_node = std::make_shared<OpNode>();
112+ op_node->strategy = key->sk_strategy ;
113+ op_node->collation = key->sk_collation ; // may be InvalidOid; executor will
114+ // fallback to attr collation
115+
116+ // Set operand types
117+ Form_pg_attribute attr = TupleDescAttr (RelationGetDescr (rel_), attno - 1 );
118+ op_node->left_typid = attr->atttypid ;
119+ op_node->right_typid = key->sk_subtype ;
120+
121+ PFTNode::AppendSubNode (op_node, std::move (var_node));
122+ PFTNode::AppendSubNode (op_node, std::move (const_node));
123+
124+ node = op_node;
125+ return node;
126+ }
127+
70128Expr *PaxSparseFilter::ExprFlatVar (Expr *clause) {
71129 Expr *flat_clause = clause;
72130 if (unlikely (!clause)) {
0 commit comments