When selective lookups can stay in BigQuery
In brief
Try a BigQuery search index for occasional, selective lookups on data already in the warehouse.
- Check job statistics to see whether the lookup used the index.
- Consider a separate serving store if unindexed queries miss the caller's deadline.
A support analyst needs the history for one ticket. The records already live in BigQuery, and the lookup is an occasional investigation that no customer transaction waits on. Adding another database would introduce a copy, a refresh path, and another place to investigate missing records.
We’d test a search index before building that second serving system.
What decides it is the lookup’s latency under its real access policies and workload, including executions that don’t use the index. A requirement for consistently short latency on every request can still justify another store.
Check whether the table is a candidate
Search indexes help BigQuery narrow the data it considers for selective searches. An exact identifier that occurs in a tiny fraction of a large table is a good candidate. A common status such as open may match most of the table, leaving little work to avoid. Judge selectivity from the values and predicates the application sends.
Start with a native table. Search indexes can’t be created on external tables or directly on logical or materialized views. A query through a view may still benefit from an underlying table’s index. Indexes also don’t replace a search engine’s fuzzy matching or typo correction.
BigQuery doesn’t populate the index for a table smaller than the documented 10 GB threshold. Creating one on a tiny development fixture can check part of the setup but can’t demonstrate indexed execution. An index can also be temporarily disabled if the base table falls below that threshold.
Check the query’s analysis edition too: Standard runs SEARCH without the index acceleration that on-demand, Enterprise, and Enterprise Plus analysis provide.
Review access policies before the benchmark. Index creation is restricted on tables that already have column ACLs or row filters.
Those protections can be added after creation, but that’s no reason to strip existing ones to get an index built. Work out a supported setup with the data owner.
Preserve the lookup’s meaning
Suppose ticket_id is a case-sensitive string identifier and the intended predicate is exact equality:
SELECT ticket_id, status, opened_at
FROM `demo-warehouse.support.tickets`
WHERE ticket_id = 'CASE-1007';CASE-10070 and case-1007 aren’t the requested identifier. Replacing the predicate with a broad text search to get a faster plan would change the answer. Keep the query’s meaning fixed while you test the access path.
BigQuery can use a search index to optimize some ordinary predicates, including equality and IN, without the query calling SEARCH. Eligibility depends on the exact expression. Capture the SQL emitted by the application or reporting tool rather than testing a hand-simplified query.
For a native table that meets the prerequisites, a narrowly scoped example is:
CREATE SEARCH INDEX ticket_key
ON `demo-warehouse.support.tickets`(ticket_id)
OPTIONS (analyzer = 'NO_OP_ANALYZER');The example indexes the string identifier and assumes you’re allowed to create an index on that table. The DDL only gives BigQuery a possible access path. The query stays ordinary equality SQL.
NO_OP_ANALYZER keeps the whole input without tokenizing or normalizing it, while the default LOG_ANALYZER tokenizes text and normally lowercases tokens. The analyzer also controls matching when the query itself uses SEARCH. Before measuring speed, test punctuation, case, empty input, and identifiers that share a prefix against the intended results.
Separate index readiness from index use
Inspect the dataset’s index metadata in its location:
SELECT
table_name,
index_name,
index_status,
coverage_percentage,
last_refresh_time
FROM `demo-warehouse.support.INFORMATION_SCHEMA.SEARCH_INDEXES`
WHERE table_name = 'tickets';An ACTIVE status can include an index that’s still being created. Check coverage and refresh time alongside it.
Coverage describes approximately how much of the table has been indexed. Zero coverage isn’t usable. A fully covered table can still have slow queries.
Next, inspect the completed job. The console shows index usage, and jobs.get returns statistics.query.searchStatistics. Its usage mode distinguishes FULLY_USED, PARTIALLY_USED, and UNUSED. When the index wasn’t fully used, read the recorded reasons. A base table that’s too small, an analyzer mismatch, a stale index, and a predicate with little pruning power each need a different response. Data masking can also make an index inapplicable to a query.
A correct result from an indexed table can still come from unindexed execution. Test through the application’s service identity and policy configuration.
Keep the job identifier with the timing record. If a test becomes slower after a deployment, you can then compare the emitted predicate, index state, and usage reason for those exact runs.
Measure the interaction and its fallback
Before creating the index, capture a baseline on a representative nonproduction copy with an appropriate data volume and an approved test budget. Keep the same table layout, query projection, principal, and analysis capacity for the indexed comparison. If several variables change together, the result won’t tell you which change earned its cost.
Disable result-cache reuse for the execution comparison with useQueryCache=false. That forces BigQuery to compute the query and can incur normal query charges. A second response served instantly from cache is good for the user and doesn’t exercise the index.
Use a small workload set: existing rare identifiers, absent identifiers, and more frequent values if the interface allows them. Include realistic simultaneous users and only the result columns they need.
Record queue and execution time separately from the application’s time to receive and display the result. Then compare the median and a tail percentile against a requirement you chose before seeing the results.
Set an acceptable latency and cost for fallback execution too. A baseline without the index shows what the interaction would face when indexing is unavailable. Run that comparison in the approved test environment and keep the same result checks on both paths. Don’t drop a production index to manufacture a failure.
We’d keep an occasional investigation in BigQuery if the indexed path meets normal expectations and the fallback stays tolerable. That fallback might run behind a visible asynchronous wait. If every request must complete within a tight bound, an unacceptable fallback defeats this design, however impressive the best indexed run is. Transactional read/write requirements would also send the decision back to an operational datastore.
Budget for changes to the table
BigQuery refreshes indexes as data changes. Broad rewrites and some schema or partition changes can create substantial refresh work.
Queries still return correct results while an index has incomplete coverage, but the performance benefit can change until maintenance catches up. Repeat the workload check after any change that rebuilds or disables the index.
Index storage is charged. Managed creation and refresh have a free capacity allowance subject to organization and region limits. Beyond that, you’ll need to plan your own index-management capacity.
When comparing the index with a second serving store, count storage, refresh capacity where required, and the query cost of fallback execution.
Keep the tested query shapes, the acceptable latency, and the index-state checks with the application. Recheck them when a new caller or a tighter response requirement changes the workload.
More in this domain: Data
Browse allWhen cold history should stay in BigQuery
Keep cold history in BigQuery when retrieval costs would outweigh the storage savings.
BigQuery global queries or a local serving copy?
A global BigQuery query can suit occasional selective reads. An approved local copy can save transfers when reports repeatedly read the same remote data.
Use BigQuery clones for bounded development work
Use a writable BigQuery clone when a test needs the source data's distribution or history. Use a small fixture when it reproduces the problem.
When external Parquet deserves a native BigQuery copy
Keep Parquet external for occasional reads. A native BigQuery copy can pay off when reports repeatedly scan the same files.
Publish a BigQuery dataset without sponsoring every reader's queries
Publish a BigQuery dataset when readers need SQL and have their own execution project. Offer versioned downloads for readers who just need the data.
Related patterns
BigQuery tenant access starts with the query identity
Choose tenant isolation from the identity BigQuery sees on the report's query.
BigQuery physical vs. logical storage: compare the full bill
Physical billing rewards compression, but retained versions can consume the savings. Compare both models using the dataset's current data, rewrite history, and recovery requirements.
On-demand vs slots: the SME decision boundary
Start an SME warehouse on BigQuery on-demand pricing. Consider reservations when recurring workloads need predictable capacity or interfere with one another.
Publish related BigQuery tables as one consistent release
Publish related BigQuery tables in one DML transaction when the change fits. Use immutable releases when readers need consistency across separate queries.