Fix two QualifiedName join orders#21747
Conversation
Before on `StanfordLegion__legion` with `cpp/throwing-pointer`:
```
Pipeline standard for QualifiedName::Namespace.getQualifiedName/0#cbc0648a@7ff329j5 was evaluated in 2 iterations totaling 0ms (delta sizes total: 70).
162061 ~0% {2} r1 = JOIN `QualifiedName::Namespace.getQualifiedName/0#cbc0648a#prev_delta` WITH namespacembrs ON FIRST 1 OUTPUT Rhs.1, Lhs.1
70 ~2% {4} | JOIN WITH namespaces ON FIRST 1 OUTPUT Lhs.0, _, Lhs.1, Rhs.1
70 ~0% {2} | REWRITE WITH Tmp.1 := "::", Out.1 := (In.2 ++ Tmp.1 ++ In.3) KEEPING 2
70 ~0% {2} | AND NOT `QualifiedName::Namespace.getQualifiedName/0#cbc0648a#prev`(FIRST 2)
return r1
Pipeline standard for QualifiedName::Namespace.getAQualifierForMembers/0#132b16e1@cfd47189 was evaluated in 2 iterations totaling 3ms (delta sizes total: 85).
12 ~0% {2} r1 = JOIN `QualifiedName::Namespace.getAQualifierForMembers/0#132b16e1#prev_delta` WITH _#namespace_inlineMerge_#namespacembrsMerge#join_rhs ON FIRST 1 OUTPUT Rhs.1, Lhs.1
162417 ~0% {2} r2 = JOIN `QualifiedName::Namespace.getAQualifierForMembers/0#132b16e1#prev_delta` WITH namespacembrs ON FIRST 1 OUTPUT Rhs.1, Lhs.1
73 ~1% {4} | JOIN WITH namespaces ON FIRST 1 OUTPUT Lhs.0, _, Lhs.1, Rhs.1
73 ~0% {2} | REWRITE WITH Tmp.1 := "::", Out.1 := (In.2 ++ Tmp.1 ++ In.3) KEEPING 2
85 ~0% {2} r3 = r1 UNION r2
85 ~0% {2} | AND NOT `QualifiedName::Namespace.getAQualifierForMembers/0#132b16e1#prev`(FIRST 2)
return r3
```
After:
```
Pipeline standard for QualifiedName::Namespace.getQualifiedName/0#cbc0648a@91677d3f was evaluated in 2 iterations totaling 0ms (delta sizes total: 70).
70 ~0% {4} r1 = JOIN `QualifiedName::Namespace.getQualifiedName/0#cbc0648a#prev_delta` WITH _#namespacembrsMerge_1#antijoin_rhs_#namespacembrsMerge_10#join_rhs_#namespacesMerge#join_rhs ON FIRST 1 OUTPUT Rhs.1, _, Lhs.1, Rhs.2
70 ~0% {2} | REWRITE WITH Tmp.1 := "::", Out.1 := (In.2 ++ Tmp.1 ++ In.3) KEEPING 2
70 ~0% {2} | AND NOT `QualifiedName::Namespace.getQualifiedName/0#cbc0648a#prev`(FIRST 2)
return r1
Pipeline standard for QualifiedName::Namespace.getAQualifierForMembers/0#132b16e1@3bbc99mb was evaluated in 2 iterations totaling 0ms (delta sizes total: 85).
12 ~0% {2} r1 = JOIN `QualifiedName::Namespace.getAQualifierForMembers/0#132b16e1#prev_delta` WITH _#namespace_inlineMerge_#namespacembrsMerge_1#antijoin_rhs__#namespacembrsMerge_#namespacembrsMerge___#join_rhs ON FIRST 1 OUTPUT Rhs.1, Lhs.1
73 ~0% {4} r2 = JOIN `QualifiedName::Namespace.getAQualifierForMembers/0#132b16e1#prev_delta` WITH _#namespacembrsMerge_1#antijoin_rhs_#namespacesMerge__#namespacembrsMerge_#namespacembrsMerge_10#joi__#join_rhs ON FIRST 1 OUTPUT Rhs.1, _, Lhs.1, Rhs.2
73 ~1% {2} | REWRITE WITH Tmp.1 := "::", Out.1 := (In.2 ++ Tmp.1 ++ In.3) KEEPING 2
85 ~0% {2} r3 = r1 UNION r2
85 ~0% {2} | AND NOT `QualifiedName::Namespace.getAQualifierForMembers/0#132b16e1#prev`(FIRST 2)
return r3
```
There was a problem hiding this comment.
Pull request overview
This PR improves evaluation performance for C++ qualified name construction by adjusting join order hints in the internal QualifiedName library, targeting expensive namespacembrs joins observed on large databases.
Changes:
- Add
pragma[only_bind_out](this)to thenamespacembrscalls inNamespace.getQualifiedName(). - Add
pragma[only_bind_out](this)to thenamespacembrscalls inNamespace.getAQualifierForMembers().
Show a summary per file
| File | Description |
|---|---|
| cpp/ql/lib/semmle/code/cpp/internal/QualifiedName.qll | Adds only_bind_out pragmas to influence join order for namespace member lookups in qualified-name predicates. |
Copilot's findings
- Files reviewed: 1/1 changed files
- Comments generated: 0
aschackmull
left a comment
There was a problem hiding this comment.
Whether this is a fix or whether this was even an issue beforehand is a bit unclear to me, since there were only two iterations with no indication of what the base delta count was, and in the "after" tuple counts the new loop-invariant prefix is unaccounted for. But the pragma does look like it enforces the new join-order (i.e. pushing the join between namespacembrs and namespaces into a loop-invariant prefix), so the QL change does appear to match the intention, hence I'll tentatively approve.
|
Thanks for the review. I agree. It's mostly because this is polluting the stable join-order table in DCA quite significantly. Maybe that table is not really measuring the right thing, but that's a separate discussion, I think. |
Before on
StanfordLegion__legionwithcpp/throwing-pointer:After: