Reference documentation and code samples for the Cloud Firestore API class Google::Cloud::Firestore::AggregateQueryExplainResult.
AggregateQueryExplainResult
Represents the result of a Firestore aggregate query explanation.
This class provides access to the
V1::ExplainMetrics, which contain details
about the query plan and execution statistics. If the explanation was
run with analyze: true, it also provides access to the
AggregateQuerySnapshot.
The metrics and snapshot (if applicable) are fetched and cached upon
the first call to either #explain_metrics or #snapshot.
Inherits
Object
Examples
Getting planning and execution metrics with the snapshot
require"google/cloud/firestore"firestore=Google::Cloud::Firestore.newaggregate_query=firestore.col(:cities).aggregate_query.add_countexplain_result=aggregate_query.explainanalyze:false# Defaultmetrics=explain_result.explain_metricsputs"Plan summary: #{metrics.plan_summary&.to_json}"ifmetrics# Snapshot will be nil because analyze was falseputs"Snapshot is nil: #{explain_result.snapshot.nil?}"
The metrics from planning and potentially execution stages of the
aggregate query.
Calling this method for the first time will process the server
responses to extract and cache the metrics (and snapshot if
analyze: true was used). Subsequent calls return the cached metrics.
Returns
(Google::Cloud::Firestore::V1::ExplainMetrics, nil) — The query explanation metrics, or nil if no metrics were returned
by the server.
Indicates whether the metrics and snapshot (if applicable) have been
fetched from the server response and cached.
This becomes true after the first call to #explain_metrics or
#snapshot.
Returns
(Boolean) — true if data has been fetched, false otherwise.
Indicates whether the metrics and snapshot (if applicable) have been
fetched from the server response and cached.
This becomes true after the first call to #explain_metrics or
#snapshot.
Returns
(Boolean) — true if data has been fetched, false otherwise.
This is only available if the explanation was run with analyze: true.
If analyze: false was used, or if the query yielded no results
even with analyze: true, this method returns nil.
Calling this method for the first time will process the server
responses to extract and cache the snapshot (and metrics).
Subsequent calls return the cached snapshot.
Returns
(AggregateQuerySnapshot, nil) — The aggregate query snapshot if analyze: true was used and results
are available, otherwise nil.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-09 UTC."],[],[],null,["# Cloud Firestore API - Class Google::Cloud::Firestore::AggregateQueryExplainResult (v3.1.0)\n\nVersion latestkeyboard_arrow_down\n\n- [3.1.0 (latest)](/ruby/docs/reference/google-cloud-firestore/latest/Google-Cloud-Firestore-AggregateQueryExplainResult)\n- [3.0.0](/ruby/docs/reference/google-cloud-firestore/3.0.0/Google-Cloud-Firestore-AggregateQueryExplainResult)\n- [2.16.1](/ruby/docs/reference/google-cloud-firestore/2.16.1/Google-Cloud-Firestore-AggregateQueryExplainResult)\n- [2.15.1](/ruby/docs/reference/google-cloud-firestore/2.15.1/Google-Cloud-Firestore-AggregateQueryExplainResult)\n- [2.14.0](/ruby/docs/reference/google-cloud-firestore/2.14.0/Google-Cloud-Firestore-AggregateQueryExplainResult)\n- [2.13.1](/ruby/docs/reference/google-cloud-firestore/2.13.1/Google-Cloud-Firestore-AggregateQueryExplainResult)\n- [2.12.0](/ruby/docs/reference/google-cloud-firestore/2.12.0/Google-Cloud-Firestore-AggregateQueryExplainResult)\n- [2.11.0](/ruby/docs/reference/google-cloud-firestore/2.11.0/Google-Cloud-Firestore-AggregateQueryExplainResult)\n- [2.10.1](/ruby/docs/reference/google-cloud-firestore/2.10.1/Google-Cloud-Firestore-AggregateQueryExplainResult)\n- [2.9.1](/ruby/docs/reference/google-cloud-firestore/2.9.1/Google-Cloud-Firestore-AggregateQueryExplainResult)\n- [2.8.0](/ruby/docs/reference/google-cloud-firestore/2.8.0/Google-Cloud-Firestore-AggregateQueryExplainResult)\n- [2.7.2](/ruby/docs/reference/google-cloud-firestore/2.7.2/Google-Cloud-Firestore-AggregateQueryExplainResult)\n- [2.6.6](/ruby/docs/reference/google-cloud-firestore/2.6.6/Google-Cloud-Firestore-AggregateQueryExplainResult) \nReference documentation and code samples for the Cloud Firestore API class Google::Cloud::Firestore::AggregateQueryExplainResult.\n\nAggregateQueryExplainResult\n---------------------------\n\nRepresents the result of a Firestore aggregate query explanation.\nThis class provides access to the\nV1::ExplainMetrics, which contain details\nabout the query plan and execution statistics. If the explanation was\nrun with `analyze: true`, it also provides access to the\n[AggregateQuerySnapshot](/ruby/docs/reference/google-cloud-firestore/latest/Google-Cloud-Firestore-AggregateQuerySnapshot \"Google::Cloud::Firestore::AggregateQuerySnapshot (class)\").\n\nThe metrics and snapshot (if applicable) are fetched and cached upon\nthe first call to either [#explain_metrics](/ruby/docs/reference/google-cloud-firestore/latest/Google-Cloud-Firestore-AggregateQueryExplainResult#Google__Cloud__Firestore__AggregateQueryExplainResult_explain_metrics_instance_ \"Google::Cloud::Firestore::AggregateQueryExplainResult#explain_metrics (method)\") or [#snapshot](/ruby/docs/reference/google-cloud-firestore/latest/Google-Cloud-Firestore-AggregateQueryExplainResult#Google__Cloud__Firestore__AggregateQueryExplainResult_snapshot_instance_ \"Google::Cloud::Firestore::AggregateQueryExplainResult#snapshot (method)\"). \n\nInherits\n--------\n\n- Object\n\nExamples\n--------\n\nGetting planning and execution metrics with the snapshot \n\n```ruby\nrequire \"google/cloud/firestore\"\n\nfirestore = Google::Cloud::Firestore.new\naggregate_query = firestore.col(:cities).aggregate_query.add_count\n\nexplain_result = aggregate_query.explain analyze: true\n\nmetrics = explain_result.explain_metrics\nif metrics\n puts \"Plan summary: #{metrics.plan_summary&.to_json}\"\n puts \"Execution stats: #{metrics.execution_stats&.to_json}\"\nend\n\nsnapshot = explain_result.snapshot\nputs \"Count: #{snapshot.get}\" if snapshot\n```\n\nGetting only planning metrics \n\n```ruby\nrequire \"google/cloud/firestore\"\n\nfirestore = Google::Cloud::Firestore.new\naggregate_query = firestore.col(:cities).aggregate_query.add_count\n\nexplain_result = aggregate_query.explain analyze: false # Default\n\nmetrics = explain_result.explain_metrics\nputs \"Plan summary: #{metrics.plan_summary&.to_json}\" if metrics\n\n# Snapshot will be nil because analyze was false\nputs \"Snapshot is nil: #{explain_result.snapshot.nil?}\"\n```\n\nMethods\n-------\n\n### #explain_metrics\n\n def explain_metrics() -\u003e Google::Cloud::Firestore::V1::ExplainMetrics, nil\n\nThe metrics from planning and potentially execution stages of the\naggregate query.\n\n\n\u003cbr /\u003e\n\nCalling this method for the first time will process the server\nresponses to extract and cache the metrics (and snapshot if\n`analyze: true` was used). Subsequent calls return the cached metrics. \n**Returns**\n\n- (Google::Cloud::Firestore::V1::ExplainMetrics, nil) --- The query explanation metrics, or `nil` if no metrics were returned by the server.\n\n### #metrics_fetched\n\n def metrics_fetched() -\u003e Boolean\n\n**Aliases**\n\n- [#metrics_fetched?](./Google-Cloud-Firestore-AggregateQueryExplainResult#Google__Cloud__Firestore__AggregateQueryExplainResult_metrics_fetched?_instance_) \nIndicates whether the metrics and snapshot (if applicable) have been\nfetched from the server response and cached.\nThis becomes `true` after the first call to [#explain_metrics](/ruby/docs/reference/google-cloud-firestore/latest/Google-Cloud-Firestore-AggregateQueryExplainResult#Google__Cloud__Firestore__AggregateQueryExplainResult_explain_metrics_instance_ \"Google::Cloud::Firestore::AggregateQueryExplainResult#explain_metrics (method)\") or\n[#snapshot](/ruby/docs/reference/google-cloud-firestore/latest/Google-Cloud-Firestore-AggregateQueryExplainResult#Google__Cloud__Firestore__AggregateQueryExplainResult_snapshot_instance_ \"Google::Cloud::Firestore::AggregateQueryExplainResult#snapshot (method)\"). \n**Returns**\n\n- (Boolean) --- `true` if data has been fetched, `false` otherwise.\n\n### #metrics_fetched?\n\n def metrics_fetched?() -\u003e Boolean\n\n**Alias Of** : [#metrics_fetched](./Google-Cloud-Firestore-AggregateQueryExplainResult#Google__Cloud__Firestore__AggregateQueryExplainResult_metrics_fetched_instance_) \nIndicates whether the metrics and snapshot (if applicable) have been\nfetched from the server response and cached.\nThis becomes `true` after the first call to [#explain_metrics](/ruby/docs/reference/google-cloud-firestore/latest/Google-Cloud-Firestore-AggregateQueryExplainResult#Google__Cloud__Firestore__AggregateQueryExplainResult_explain_metrics_instance_ \"Google::Cloud::Firestore::AggregateQueryExplainResult#explain_metrics (method)\") or\n[#snapshot](/ruby/docs/reference/google-cloud-firestore/latest/Google-Cloud-Firestore-AggregateQueryExplainResult#Google__Cloud__Firestore__AggregateQueryExplainResult_snapshot_instance_ \"Google::Cloud::Firestore::AggregateQueryExplainResult#snapshot (method)\"). \n**Returns**\n\n- (Boolean) --- `true` if data has been fetched, `false` otherwise.\n\n### #snapshot\n\n def snapshot() -\u003e AggregateQuerySnapshot, nil\n\nThe [AggregateQuerySnapshot](/ruby/docs/reference/google-cloud-firestore/latest/Google-Cloud-Firestore-AggregateQuerySnapshot \"Google::Cloud::Firestore::AggregateQuerySnapshot (class)\") containing the aggregation results.\n\n\nThis is only available if the explanation was run with `analyze: true`.\nIf `analyze: false` was used, or if the query yielded no results\neven with `analyze: true`, this method returns `nil`.\n\n\u003cbr /\u003e\n\nCalling this method for the first time will process the server\nresponses to extract and cache the snapshot (and metrics).\nSubsequent calls return the cached snapshot. \n**Returns**\n\n- ([AggregateQuerySnapshot](./Google-Cloud-Firestore-AggregateQuerySnapshot), nil) --- The aggregate query snapshot if `analyze: true` was used and results are available, otherwise `nil`."]]