@@ -17,9 +17,9 @@ namespace {
17
17
* Check if a callable is an attribute of some table
18
18
* Currently just return a boolean and cover only basic cases
19
19
*/
20
- TMaybe<TCoMember > IsAttribute (const TExprBase& input) {
20
+ std::optional<TString > IsAttribute (const TExprBase& input) {
21
21
if (auto member = input.Maybe <TCoMember>()) {
22
- return member.Cast ();
22
+ return TString ( member.Cast (). Name () );
23
23
} else if (auto cast = input.Maybe <TCoSafeCast>()) {
24
24
return IsAttribute (cast.Cast ().Value ());
25
25
} else if (auto ifPresent = input.Maybe <TCoIfPresent>()) {
@@ -35,8 +35,37 @@ namespace {
35
35
} else if (auto exists = input.Maybe <TCoExists>()) {
36
36
auto child = TExprBase (input.Ptr ()->ChildRef (0 ));
37
37
return IsAttribute (child);
38
+ } else if (auto argument = input.Maybe <TCoArgument>()) {
39
+ TString argumentName = TString (argument.Cast ().Name ());
40
+ TStringBuf olapApplyMemberPrefix = " members_" ;
41
+ if (argumentName.StartsWith (olapApplyMemberPrefix)) {
42
+ return argumentName.substr (olapApplyMemberPrefix.length (), argumentName.size () - olapApplyMemberPrefix.length ());
43
+ } else {
44
+ return argumentName;
45
+ }
38
46
}
47
+ return std::nullopt;
48
+ }
39
49
50
+ TMaybe<TCoMember> IsMember (const TExprBase& input) {
51
+ if (auto member = input.Maybe <TCoMember>()) {
52
+ return member.Cast ();
53
+ } else if (auto cast = input.Maybe <TCoSafeCast>()) {
54
+ return IsMember (cast.Cast ().Value ());
55
+ } else if (auto ifPresent = input.Maybe <TCoIfPresent>()) {
56
+ return IsMember (ifPresent.Cast ().Optional ());
57
+ } else if (auto just = input.Maybe <TCoJust>()) {
58
+ return IsMember (just.Cast ().Input ());
59
+ } else if (input.Ptr ()->IsCallable (" PgCast" )) {
60
+ auto child = TExprBase (input.Ptr ()->ChildRef (0 ));
61
+ return IsMember (child);
62
+ } else if (input.Ptr ()->IsCallable (" FromPg" )) {
63
+ auto child = TExprBase (input.Ptr ()->ChildRef (0 ));
64
+ return IsMember (child);
65
+ } else if (auto exists = input.Maybe <TCoExists>()) {
66
+ auto child = TExprBase (input.Ptr ()->ChildRef (0 ));
67
+ return IsMember (child);
68
+ }
40
69
return Nothing ();
41
70
}
42
71
@@ -143,26 +172,32 @@ double NYql::NDq::TPredicateSelectivityComputer::ComputeEqualitySelectivity(cons
143
172
return ComputeEqualitySelectivity (right, left);
144
173
}
145
174
146
- if (auto maybeMember = IsAttribute (left)) {
175
+ if (auto attribute = IsAttribute (left)) {
147
176
// In case both arguments refer to an attribute, return 0.2
148
- if (auto maybeAnotherMember = IsAttribute (right)) {
177
+ if (IsAttribute (right)) {
149
178
if (CollectMemberEqualities) {
150
- MemberEqualities.Add (*maybeMember.Get (), *maybeAnotherMember.Get ());
179
+ auto maybeMember = IsMember (left);
180
+ auto maybeAnotherMember = IsMember (right);
181
+ if (maybeMember && maybeAnotherMember) {
182
+ MemberEqualities.Add (*maybeMember.Get (), *maybeAnotherMember.Get ());
183
+ }
151
184
}
152
185
return 0.3 ;
153
186
}
154
187
// In case the right side is a constant that can be extracted, compute the selectivity using statistics
155
188
// Currently, with the basic statistics we just return 1/nRows
156
189
157
190
else if (IsConstantExprWithParams (right.Ptr ())) {
158
- TString attributeName = maybeMember. Get ()-> Name (). StringValue ();
191
+ TString attributeName = attribute. value ();
159
192
if (!IsConstantExpr (right.Ptr ())) {
160
193
return DefaultSelectivity (Stats, attributeName);
161
194
}
162
195
163
196
if (Stats == nullptr || Stats->ColumnStatistics == nullptr ) {
164
197
if (CollectColumnsStatUsedMembers) {
165
- ColumnStatsUsedMembers.AddEquality (*maybeMember.Get ());
198
+ if (auto maybeMember = IsMember (left)) {
199
+ ColumnStatsUsedMembers.AddEquality (*maybeMember.Get ());
200
+ }
166
201
}
167
202
return DefaultSelectivity (Stats, attributeName);
168
203
}
0 commit comments