Skip to content

fix(bigquery): route JOB_CREATION_REQUIRED through fast query path#13437

Open
jinseopkim0 wants to merge 2 commits into
mainfrom
fix/fast-query-latency
Open

fix(bigquery): route JOB_CREATION_REQUIRED through fast query path#13437
jinseopkim0 wants to merge 2 commits into
mainfrom
fix/fast-query-latency

Conversation

@jinseopkim0

@jinseopkim0 jinseopkim0 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

Routes queries under JobCreationMode.JOB_CREATION_REQUIRED to the fast query path (jobs.query API / 1 RPC) to avoid the slow fallback path (jobs.insert API / 2 RPCs).

https://docs.cloud.google.com/bigquery/docs/reference/rest/v2/jobs/query#QueryResponse says:

object (JobReference)

Reference to the Job that was created to run the query. This field will be present even if the original request timed out, in which case jobs.getQueryResults can be used to read the results once the query has completed. Since this API only returns the first page of results, subsequent pages can be fetched via the same mechanism (jobs.getQueryResults).

If jobCreationMode was set to JOB_CREATION_OPTIONAL and the query completes without creating a job, this field will be empty.

Thus, routing JOB_CREATION_REQUIRED through the fast path is preferred.

b/522363981

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request enables fast query support when the job creation mode is set to JOB_CREATION_REQUIRED in QueryRequestInfo. This allows queries with this configuration to execute via the fast query path, returning a TableResult directly (with both JobId and QueryId populated) rather than creating a separate job. Unit and integration tests have been updated to reflect and verify this behavior. I have no feedback to provide.

@jinseopkim0 jinseopkim0 requested a review from lqiu96 June 11, 2026 18:34
@jinseopkim0 jinseopkim0 marked this pull request as ready for review June 11, 2026 18:34
@jinseopkim0 jinseopkim0 requested review from a team as code owners June 11, 2026 18:34
&& config.getTimePartitioning() == null
&& config.getUserDefinedFunctions() == null
&& config.getWriteDisposition() == null
&& config.getJobCreationMode() != JobCreationMode.JOB_CREATION_REQUIRED;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

qq, wouldn't this just end up always doing a fast query (default is set to required)? IIUC, I think should be a fast query only for JobCreationMode.JOB_CREATION_OPTIONAL?

Is there any performance impact or behavioral change if default to a fast query even if a user explicitly sets job_required?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the questions.

qq, wouldn't this just end up always doing a fast query (default is set to required)?

Yes, this is intended.

IIUC, I think should be a fast query only for JobCreationMode.JOB_CREATION_OPTIONAL?

Fast query should be for both. The BigQuery backend always creates a job in the background and returns a jobReference (including the jobId, see https://docs.cloud.google.com/bigquery/docs/reference/rest/v2/jobs/query#QueryResponse) for all jobs.query requests, so fast query makes sense.

Is there any performance impact or behavioral change if default to a fast query even if a user explicitly sets job_required?

The result is faster queries and lower latencies. There is no behavioral change as a job is still created in the background and tracked as expected.

@lqiu96 lqiu96 Jun 12, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Gotcha, I think faster queries is always better for the user, but something seems a bit weird about JobCreationMode to me. Why even have an JOB_CREATION_OPTIONAL configuration on the client side and not just do it under the hood on the server side?

Since we have this configuration, it seems odd to have a customer specify JOB_CREATION_REQUIRED and potentially not result in a job back. Could the original issue be solved if fast query runs only when JOB_CREATION_OPTIONAL is specified? It seems like the issue was the fast query logic was running on the wrong conditions?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants