36
36
37
37
namespace pax {
38
38
39
- void PaxSparseFilter::Initialize (List *quals) {
39
+ void PaxSparseFilter::Initialize (List *quals, ScanKey key, int nkeys ) {
40
40
ListCell *qual_cell;
41
41
std::vector<std::shared_ptr<PFTNode>> fl_nodes; /* first level nodes */
42
42
std::string origin_tree_str;
43
43
44
44
// no inited
45
45
Assert (!filter_tree_);
46
46
47
- if (!quals) {
47
+ if (!quals && nkeys == 0 ) {
48
48
return ;
49
49
}
50
50
@@ -57,6 +57,23 @@ void PaxSparseFilter::Initialize(List *quals) {
57
57
fl_nodes.emplace_back (std::move (fl_node));
58
58
}
59
59
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
+
60
77
// build the root of `filter_tree_`
61
78
BuildPFTRoot (fl_nodes);
62
79
if (pax_log_filter_tree) origin_tree_str = DebugString ();
@@ -67,6 +84,47 @@ void PaxSparseFilter::Initialize(List *quals) {
67
84
origin_tree_str.c_str (), DebugString ().c_str ());
68
85
}
69
86
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
+
70
128
Expr *PaxSparseFilter::ExprFlatVar (Expr *clause) {
71
129
Expr *flat_clause = clause;
72
130
if (unlikely (!clause)) {
0 commit comments