Updating analyze endpoint - #5658
Conversation
PR Code Analyzer ❗AI-powered 'Code-Diff-Analyzer' found issues on commit 7b87b68.
The table above displays the top 10 most important findings. Pull Requests Author(s): Please update your Pull Request according to the report above. Repository Maintainer(s): You can Thanks. |
PR Reviewer Guide 🔍(Review updated until commit d58f214)Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to d58f214 Explore these optional code suggestions:
Previous suggestionsSuggestions up to commit 7b87b68
Suggestions up to commit 833e6f8
Suggestions up to commit 9fcb5e7
Suggestions up to commit 3954423
Suggestions up to commit 6c8e52b
|
Signed-off-by: Krish Gandhi <kjg2352@gmail.com>
Signed-off-by: Krish Gandhi <kjg2352@gmail.com>
a585c62 to
ac2182c
Compare
|
Persistent review updated to latest commit ac2182c |
Signed-off-by: Krish Gandhi <kjg2352@gmail.com>
|
Persistent review updated to latest commit 6c8e52b |
Signed-off-by: Krish Gandhi <kjg2352@gmail.com>
|
Persistent review updated to latest commit 3954423 |
Signed-off-by: Krish Gandhi <kjg2352@gmail.com>
|
Persistent review updated to latest commit 9fcb5e7 |
Signed-off-by: Krish Gandhi <kjg2352@gmail.com>
|
Persistent review updated to latest commit 833e6f8 |
|
|
||
| @ToString.Exclude private Map<String, Object> afterKey; | ||
|
|
||
| @EqualsAndHashCode.Exclude @ToString.Exclude private final boolean disableRequestCache; |
There was a problem hiding this comment.
Can we push request cache related changes later until we feel it's required? Currently I'm not sure how useful it is and passing it around seems tricky.
There was a problem hiding this comment.
I think it is useful because a user doesn’t benefit from analysis of a cached query but I don’t mind removing it. What are your thoughts @ahkcs ?
There was a problem hiding this comment.
It's a useful feature since cold timings matter, but I think we can follow @dai-chen's suggestion here to temporarily defer request cache related changes as they may be risky.
Two issues identified regarding request cache changes:
possibleCacheHit is always false today. disableCache is hardcoded true, so possibleCacheHit = !disableCache && … is a constant false, and getRequestCacheHitCount is never called (the disableCache ? -1 : … branch always wins).
The disable itself no-ops for script-bearing queries. disableRequestCache is set on the coordinating thread, but it's not in snapshotThreadLocals()/restoreThreadLocals(). The complex-pool dispatch relies on that snapshot to cross threads, and the request reads disableRequestCache.get() lazily in CalciteEnumerableIndexScan.enumerator() — on the sql-complex-worker thread, where it's the default false. So any hasScripts plan silently keeps the cache on.
There was a problem hiding this comment.
Sounds good. Removing possibleCacheHit and cache disabling functionality on analyze path.
| * max(child.time_ms)} (see {@link #duration}). Time-fraction rules use this self-time so they | ||
| * attribute the cost actually spent in the stage rather than the whole subtree beneath it. | ||
| */ | ||
| public class AnalyzeRecommendationBuilder { |
There was a problem hiding this comment.
Split the internal logic into recommendation rule?
There was a problem hiding this comment.
Can you elaborate on this
There was a problem hiding this comment.
Sure, just thinking split the logic into some small inner class/lambda. Ref: FilterQueryBuilder
| "time_ms": 14.19, | ||
| "rows": 0 |
There was a problem hiding this comment.
could you remind me currently how we capture the operator-level metrics?
There was a problem hiding this comment.
They are captured using logic from existing profile API by reusing same execution path
There was a problem hiding this comment.
Could you double confirm because I don't remember profile API has operator-level metrics. Is this from actual test output?
There was a problem hiding this comment.
How per-operator metrics collected? e.g. EnumerableCalc? I think profile API only collect phase (execution) metrics.
How does rows collected? why 0?
There was a problem hiding this comment.
Here is output from existing profile API (i.e. not my changes):
curl -X POST "localhost:9200/_plugins/_ppl" \
-H "Content-Type: application/json" \
-d '{"query": "SOURCE = `test_data` | join left=l right=r on l.client_city=r.client_city `test_data` | head 1 | fields client_city", "profile": true}'
{
"profile": {
"summary": {
"total_time_ms": 2203.61
},
"phases": {
"analyze": {
"time_ms": 7.76
},
"optimize": {
"time_ms": 21.64
},
"execute": {
"time_ms": 2174.02
},
"format": {
"time_ms": 0.02
}
},
"plan": {
"node": "EnumerableCalc",
"time_ms": 2171.57,
"rows": 1,
"children": [
{
"node": "EnumerableLimit",
"time_ms": 2171.43,
"rows": 1,
"children": [
{
"node": "EnumerableLimit",
"time_ms": 2171.42,
"rows": 1,
"children": [
{
"node": "EnumerableMergeJoin",
"time_ms": 2171.42,
"rows": 2,
"children": [
{
"node": "CalciteEnumerableIndexScan",
"time_ms": 1842.1,
"rows": 367
},
{
"node": "CalciteEnumerableIndexScan",
"time_ms": 328.95,
"rows": 367
}
]
}
]
}
]
}
]
},
"thread_pool": "sql-complex-worker"
},
"schema": [
{
"name": "client_city",
"type": "string"
}
],
"datarows": [
[
"Aaronborough"
]
],
"total": 1,
"size": 1
}
This is called from the analyze path and included in the analyze response.
How does rows collected? why 0?
This is because of the query includes where bytes_sent < 30 and there aren't any rows that fit that condition. This was done intentionally to show the general structure of the response with multiple operators, rather than using | head 1 where a pushdown can be confusing to reader. I can update endpoints.md to show a different query if needed.
Signed-off-by: Krish Gandhi <kjg2352@gmail.com>
Signed-off-by: Krish Gandhi <kjg2352@gmail.com>
|
Persistent review updated to latest commit 7b87b68 |
…ning up comments Signed-off-by: Krish Gandhi <kjg2352@gmail.com>
…ning up comments, updating docs Signed-off-by: Krish Gandhi <kjg2352@gmail.com>
|
Persistent review updated to latest commit d58f214 |
Description
operator_ treefromanalyzeanalyzeresponseanalyzeThis PR improves correctness of the
analyzeendpoint, addressing theoperator_treecorrectness issue mentioned in #5568. Additionally, this PR enhancesanalyzeby providing rule-based query optimization recommendations in the response.Example Query and Response
The response of this will be as follows (logical and physical plans are trimmed for brevity):
Recommendations Implemented
node.nodecontains "filter" or "project";rows_out / rows_in > xx = 0.95(INEFFECTIVE_FILTER_MAX_PASS_RATIO)Filter only dropped <pct>% of rowsratio > x), CRITICAL (ratio >= z)node.nodecontains "join";rows_out / rows_in > xx = 5.0(JOIN_EXPLOSION_RATIO),z = 20.0(JOIN_EXPLOSION_CRITICAL_RATIO)Join expanded <rows_in> rows into <rows_out> rows (<ratio>×)node.nodecontains "sort";duration(node) / profile.phases.execute.time_ms > xandrows_in > yx = 0.20(EXPENSIVE_SORT_TIME_FRACTION),y = 50,000(EXPENSIVE_SORT_MIN_ROWS)Sorting <rows_in> rows took <duration> ms (<pct>% of execution)argmax(duration(node)) / profile.phases.execute.time_ms > xx = 0.75(BOTTLENECK_TIME_FRACTION)<node> took <duration> ms (<pct>% of execution)profile.phases.execute.time_ms < profile.phases.optimize.time_msandprofile.phases.optimize.time_ms > xx = 75ms (OPTIMIZE_DOMINATES_MIN_MS)Query planning took <optimize> ms vs <execute> ms executingRelated Issues
#5568
#5500
#4343
#5044
#5688
Check List
--signoffor-s.By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.