Skip to content

ES|QL - Planning and query profiling#138400

Closed
carlosdelest wants to merge 20 commits intoelastic:mainfrom
carlosdelest:non-issue/esql-planner-profile
Closed

ES|QL - Planning and query profiling#138400
carlosdelest wants to merge 20 commits intoelastic:mainfrom
carlosdelest:non-issue/esql-planner-profile

Conversation

@carlosdelest
Copy link
Member

This PR adds the following information to the ES|QL profiling information:

Planning and planning optimization profiling

Adds planning and optimization timing to the plans profile section:

{
        "plans": [
            {
                "description": "data",
                "cluster_name": "runTask",
                "node_name": "runTask-0",
                "plan": "ExchangeSinkExec...",
                "plan_nanos": 2792,
                "logical_optimization_nanos": 466416,
                "physical_optimization_nanos": 132667
            },
            {
                "description": "node_reduce",
                "cluster_name": "runTask",
                "node_name": "runTask-0",
                "plan": "ExchangeSinkExec[[title{f}#30, _score{m}#24],false]\n\\_ProjectExec[[title{f}#30, _score{m}#24]]\n  \\_FieldExtractExec[title{f}#30]<[],[]>\n    \\_TopNExec[[Order[_score{m}#24,DESC,FIRST]],10[INTEGER],5198]\n      \\_ExchangeSourceExec[[_doc{f}#33, _score{m}#24, titleVector{f}#31, tags{f}#32],false]",
                "plan_nanos": 244584
            },
            {
                "description": "final",
                "cluster_name": "runTask",
                "node_name": "runTask-0",
                "plan": "OutputExec[org.elasticsearch.xpack.esql.plugin.ComputeService$$Lambda/0x00000ff8016155d8@10a8116]\n\\_ProjectExec[[title{f}#30, _score{m}#24]]\n  \\_TopNExec[[Order[_score{m}#24,DESC,FIRST]],10[INTEGER],1032]\n    \\_ExchangeSourceExec[[title{f}#30, _score{m}#24],false]",
                "plan_nanos": 12416,
                "logical_optimization_nanos": 807583,
                "physical_optimization_nanos": 244750
            }
        ]
}

Query profiling

Adds query profiling information to the LuceneOperator:

Profiling information
{
  "profile": {
    "drivers": [
      {
        "operators": [
          {
            "operator": "LuceneTopNSourceOperator[shards = [vectors:0,vectors:1], maxPageSize = 62, limit = 10, needsScore = true, sorts = [{\"_score\":{\"order\":\"desc\"}}]]",
            "query_profile": [
              {
                "type": "CachingEnableFilterQuery",
                "description": "(ConstantScore(tags:java))^0.0",
                "time_in_nanos": 223935,
                "breakdown": {
                  "set_min_competitive_score_count": 0,
                  "match_count": 0,
                  "shallow_advance_count": 0,
                  "set_min_competitive_score": 0,
                  "next_doc": 117519,
                  "match": 0,
                  "next_doc_count": 741,
                  "score_count": 0,
                  "compute_max_score_count": 0,
                  "compute_max_score": 0,
                  "advance": 0,
                  "advance_count": 0,
                  "count_weight_count": 0,
                  "score": 0,
                  "build_scorer_count": 2,
                  "create_weight": 7875,
                  "shallow_advance": 0,
                  "count_weight": 0,
                  "create_weight_count": 1,
                  "build_scorer": 98541
                },
                "children": [
                  {
                    "type": "TermQuery",
                    "description": "tags:java",
                    "time_in_nanos": 197230,
                    "breakdown": {
                      "set_min_competitive_score_count": 0,
                      "match_count": 0,
                      "shallow_advance_count": 0,
                      "set_min_competitive_score": 0,
                      "next_doc": 97439,
                      "match": 0,
                      "next_doc_count": 741,
                      "score_count": 0,
                      "compute_max_score_count": 0,
                      "compute_max_score": 0,
                      "advance": 0,
                      "advance_count": 0,
                      "count_weight_count": 0,
                      "score": 0,
                      "build_scorer_count": 2,
                      "create_weight": 2625,
                      "shallow_advance": 0,
                      "count_weight": 0,
                      "create_weight_count": 1,
                      "build_scorer": 97166
                    }
                  }
                ]
              },
              {
                "type": "KnnScoreDocQuery",
                "description": "ScoreAndDocQuery",
                "time_in_nanos": 8616,
                "breakdown": {
                  "set_min_competitive_score_count": 0,
                  "match_count": 0,
                  "shallow_advance_count": 0,
                  "set_min_competitive_score": 0,
                  "next_doc": 893,
                  "match": 0,
                  "next_doc_count": 31,
                  "score_count": 30,
                  "compute_max_score_count": 0,
                  "compute_max_score": 0,
                  "advance": 0,
                  "advance_count": 0,
                  "count_weight_count": 0,
                  "score": 5265,
                  "build_scorer_count": 2,
                  "create_weight": 666,
                  "shallow_advance": 0,
                  "count_weight": 0,
                  "create_weight_count": 1,
                  "build_scorer": 1792
                }
              },
              {
                "type": "BooleanQuery",
                "description": "+ScoreAndDocQuery +tags:java",
                "time_in_nanos": 444501,
                "breakdown": {
                  "set_min_competitive_score_count": 0,
                  "match_count": 0,
                  "shallow_advance_count": 0,
                  "set_min_competitive_score": 0,
                  "next_doc": 180418,
                  "match": 0,
                  "next_doc_count": 11,
                  "score_count": 10,
                  "compute_max_score_count": 0,
                  "compute_max_score": 0,
                  "advance": 0,
                  "advance_count": 0,
                  "count_weight_count": 0,
                  "score": 8500,
                  "build_scorer_count": 2,
                  "create_weight": 92166,
                  "shallow_advance": 0,
                  "count_weight": 0,
                  "create_weight_count": 1,
                  "build_scorer": 163417
                },
                "children": [
                  {
                    "type": "KnnScoreDocQuery",
                    "description": "ScoreAndDocQuery",
                    "time_in_nanos": 10336,
                    "breakdown": {
                      "set_min_competitive_score_count": 0,
                      "match_count": 0,
                      "shallow_advance_count": 1,
                      "set_min_competitive_score": 0,
                      "next_doc": 0,
                      "match": 0,
                      "next_doc_count": 0,
                      "score_count": 10,
                      "compute_max_score_count": 0,
                      "compute_max_score": 0,
                      "advance": 3291,
                      "advance_count": 11,
                      "count_weight_count": 0,
                      "score": 461,
                      "build_scorer_count": 3,
                      "create_weight": 375,
                      "shallow_advance": 1666,
                      "count_weight": 0,
                      "create_weight_count": 1,
                      "build_scorer": 4543
                    }
                  },
                  {
                    "type": "TermQuery",
                    "description": "tags:java",
                    "time_in_nanos": 322043,
                    "breakdown": {
                      "set_min_competitive_score_count": 0,
                      "match_count": 0,
                      "shallow_advance_count": 1,
                      "set_min_competitive_score": 0,
                      "next_doc": 0,
                      "match": 0,
                      "next_doc_count": 0,
                      "score_count": 10,
                      "compute_max_score_count": 0,
                      "compute_max_score": 0,
                      "advance": 162752,
                      "advance_count": 10,
                      "count_weight_count": 0,
                      "score": 4000,
                      "build_scorer_count": 3,
                      "create_weight": 83458,
                      "shallow_advance": 11708,
                      "count_weight": 0,
                      "create_weight_count": 1,
                      "build_scorer": 60125
                    }
                  }
                ]
              }
            ]
          }
        ]
      }
    ]
  }
}

Field caps timing

Adds timing profile to field_caps request:

{
    "profile": {
        "field_capabilities": {
            "start_millis": 1763713476849,
            "stop_millis": 1763713476849,
            "took_millis": 0,
            "took_nanos": 597625
        }
    }
}
elasticsearchmachine added 10 commits November 17, 2025 11:47
…r-profile

# Conflicts:
#	server/src/main/resources/transport/upper_bounds/9.3.csv
#	x-pack/plugin/esql/compute/src/main/java/org/elasticsearch/compute/lucene/ShardContext.java
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/action/EsqlExecutionInfo.java
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/plugin/DataNodeComputeHandler.java
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/session/IndexResolver.java
…r-profile

# Conflicts:
#	server/src/main/resources/transport/upper_bounds/9.3.csv
#	x-pack/plugin/esql/src/main/java/org/elasticsearch/xpack/esql/session/EsqlSession.java
@carlosdelest carlosdelest added :Analytics/ES|QL AKA ESQL Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch Team:Search - Relevance The Search organization Search Relevance team Team:ES|QL :Search Relevance/ES|QL Search functionality in ES|QL >enhancement labels Nov 21, 2025
@elasticsearchmachine
Copy link
Collaborator

Hi @carlosdelest, I've created a changelog YAML for you.


/**
* @param logicalOptimizationNanos Time spent on local logical plan optimization (in nanoseconds)
* @param physicalOptimizationNanos Time spent on local physical plan optimization (in nanoseconds)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind clarifying planNanos as well?

It looks like it includes:

  • breakPlanBetweenCoordinatorAndDataNode
  • reductionPlan
  • plan.collect(LookupJoinExec.class::isInstance)...

All of them should be fairly cheap.
It also looks like it does not include local/physical optimization stages.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm looking at it now - as you say, it's fairly cheap and probably makes no sense as it addresses multiple intermediate operations for planning.

I will remove it as it adds some confusion. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

:Analytics/ES|QL AKA ESQL >enhancement :Search Relevance/ES|QL Search functionality in ES|QL Team:ES|QL Team:Search - Relevance The Search organization Search Relevance team Team:Search Relevance Meta label for the Search Relevance team in Elasticsearch v9.3.0

3 participants