Repository navigation
Conversation
4925b8b to
b14cfc5
Compare
309cef6 to
0ec32c3
Compare
c3d1948 to
5d25a78
Compare
5d25a78 to
f1588a5
Compare
548f3c9 to
c77c7c5
Compare
1370873 to
55bdd14
Compare
| std::string allow_htapi = dsn_section["ALLOWHTAPIFORLARGERESULTS"]; | ||
| dsn_.allow_htapi = (allow_htapi == "1"); | ||
|
|
||
| std::string htapi_activation_threshold = |
There was a problem hiding this comment.
why do we need this new param? and is it supported by existing driver?
There was a problem hiding this comment.
Yes, it is a standard property supported by the existing driver.
We need it for:
- Compatibility: Drop-in parity for existing DSNs, connection strings, and BI tools that already use this property.
- Performance: Keeps small queries on the fast REST path (avoiding the ~3s Storage API session setup overhead) while transitioning large queries (1M+ rows) to HTAPI.
| // This array is used to dynamically generate individual benchmark | ||
| // configurations to isolate and measure the fetch performance for each specific | ||
| // BigQuery data type. | ||
| std::vector<std::string> const kAllBqTypes2Columns = {"jsonField"}; |
There was a problem hiding this comment.
why only for json? what about others?
There was a problem hiding this comment.
added other datatype as well
| : block_size; | ||
| int64_t query_limit = ExtractQueryLimit(query_str); | ||
| if (query_limit < 0 || query_limit > row_threshold) { | ||
| query_request.set_max_results(1); |
There was a problem hiding this comment.
as discussed last time , why do we need to set this max results ?
There was a problem hiding this comment.
I have updated this specifically to address Sachin's feedback:
- Performance Justification: Without this, BigQuery serializes megabytes of REST JSON before HTAPI engages, causing TTFB on 1M queries to take ~17.5s. With
max_results(1), TTFB drops to ~4.3s (73% faster). - Not Hardcoded: It is dynamically gated by
HTAPI_ActivationThresholdand query limits. Small queries (≤ 100k rows) do not set this and remain on the fast REST path. - Avoids Page-Size Assumptions: Setting
1ensures BigQuery immediately returns the destination table metadata regardless of column count/size, allowing the driver to cleanly hand off the entire result set to the Storage Read API (Arrow).
| } | ||
|
|
||
| namespace { | ||
| int64_t ExtractQueryLimit(absl::string_view query) { |
There was a problem hiding this comment.
no unit test cases for this
There was a problem hiding this comment.
added unit testcase
| int64_t row_threshold = (activation_threshold > 0) | ||
| ? (activation_threshold * block_size) | ||
| : block_size; | ||
| int64_t query_limit = ExtractQueryLimit(query_str); |
There was a problem hiding this comment.
what about cases when there's no limit?
There was a problem hiding this comment.
When there is no LIMIT clause, ExtractQueryLimit returns -1.
The condition (query_limit < 0 || query_limit > row_threshold) explicitly catches this (query_limit < 0) and treats it as an unbounded query, setting max_results(1) so the full result set is streamed directly via the High-Throughput Storage Read API (Arrow) instead of buffering large JSON pages over REST.
55bdd14 to
5b3b2f8
Compare
This PR optimizes data fetch performance not only for the JSON datatype, but also across other BigQuery data types and large result sets by introducing support for the
HTAPI_ActivationThresholdconnection/DSN property, caching bound descriptors forSQLBindCol, and zero-copy JSON parsing with the High-Throughput API (Storage Read API).Problem
maintook ~16.2–17.9 seconds (and ~13–25 seconds across other data types) for TTFB because the driver attempted to retrieve initial data pages over the standard BigQuery REST API JSON response buffer before transitioning to HTAPI.HTAPI_ActivationThreshold(even when explicitly set in connection strings likeAllowHtapiForLargeResults=1;HTAPI_ActivationThreshold=0;), preventing queries from transitioning to HTAPI at the intended threshold.SQLBindCol:WriteRowsetperformed repeatedard.HasDescriptorRecord()andard.GetDescriptorRecord()map lookups for every cell, adding substantial iteration overhead across large queries.ProcessResultSetRowsre-inspected column schemas per cell, copied cell strings by value, and copied rows instead of moving them into the result set.Solution
HTAPI_ActivationThreshold:htapi_activation_thresholdtostruct Dsn(defaulting to3).HTAPI_ACTIVATIONTHRESHOLDfrom DSN and connection strings.set_max_results(1)):ExtractQueryLimit) usingabsl::string_view.AllowHtapiForLargeResults=1, evaluate the query limit against the block threshold:SELECT ...): Setsquery_request.set_max_results(1). BigQuery immediately returns schema and query metadata without serializing rows into REST JSON buffers, allowing the driver to instantly transition to the Storage Read API (Arrow streaming).SQLDriverConnectInternalto allow connection string parameters to properly populate and overridedsn_section.odbc_sql_fetch.cc):BoundColInfo) before the row iteration loop inWriteRowset, eliminating millions of per-cellstd::maplookups (HasDescriptorRecord/GetDescriptorRecord).odbc_internal_commons.cc):std::movewhen populating result set rows to eliminate deep buffer copies.Performance Benchmark Results
1.
SQLBindColmainBranchperf_improve)jsonField10kIteration
Total Time
6.0 ms
2,220 ms
8.7 ms
2,085 ms
7.0 ms
2,086 ms
jsonField100kIteration
Total Time
69.0 ms
4,867 ms
69.3 ms
4,742 ms
74.7 ms
5,019 ms
jsonField1MIteration
Total Time
2,592 ms
19,080 ms
5,292 ms
10,423 ms
2,565 ms
7,260 ms
2.
SQLGetDatamainBranchperf_improve)jsonField_SQLGetData10kIteration
Total Time
8.3 ms
1,460 ms
11.3 ms
1,920 ms
8.3 ms
1,469 ms
jsonField_SQLGetData100kIteration
Total Time
81.3 ms
4,842 ms
87.0 ms
4,911 ms
89.3 ms
5,047 ms
jsonField_SQLGetData1MIteration
Total Time
2,464 ms
19,033 ms
5,011 ms
10,013 ms
2,447 ms
6,833 ms
3. Total JSON Benchmark Suite Runtime (6 Tests)
mainBranch: 51.5 secondsperf_improve): 27.7 seconds (fastest overall)