FALSE
(default)TRUE
, the execution engine favors using more parallelism when possible. Because this can reduce resources available to other operations, you may want to avoid this hint if you run latency-sensitive operations on the same instance.
LOCK_SCANNED_RANGES
exclusive
|shared
(default)Without the hint, it's possible that multiple simultaneous transactions will acquire shared locks, and then try to upgrade to exclusive locks. This will cause a deadlock, because each transaction's shared lock is preventing the other transaction(s) from upgrading to exclusive. Spanner aborts all but one of the transactions.
When requesting an exclusive lock using this hint, one transaction acquires the lock and proceeds to execute, while other transactions wait their turn for the lock. Throughput is still limited because the conflicting transactions can only be performed one at a time, but in this case Spanner is always making progress on one transaction, saving time that would otherwise be spent aborting and retrying transactions.
This hint is supported on all statement types, both query and DML.
Spanner always enforces serializability. Lock mode hints can affect which transactions wait or abort in contended workloads, but don't change the isolation level.
Because this is just a hint, it shouldn't be considered equivalent to a mutex. In other words, you shouldn't use Spanner exclusive locks as a mutual exclusion mechanism for the execution of code outside of Spanner. For more information, see Locking.
You can't use both the FOR UPDATE
clause and the LOCK_SCANNED_RANGES
hint in the same query. An error is returned. For more information, see Use SELECT FOR UPDATE.
SCAN_METHOD
AUTO
(default) |BATCH
|ROW
The default Spanner scan method is AUTO
(automatic). The AUTO
setting specifies that depending on the heuristics of the query, batch or row-oriented query processing might be used to improve query performance. If you want to change the default scanning method, you can use a statement hint to enforce the BATCH
-oriented or ROW
-oriented processing method. You can't manually set the scan method to AUTO
. However, if you remove the statement hint, then Spanner uses the AUTO
scan method. For more information, see Optimize scans.
EXECUTION_METHOD
DEFAULT
|BATCH
|ROW
The default Spanner query execution method is DEFAULT
. The DEFAULT
setting specifies that batch-oriented execution might be used to improve query performance, depending on the heuristics of the query. If you want to change the default execution method, you can use a statement hint to enforce the BATCH
-oriented or ROW
-oriented execution method. You can't manually set the query execution method to DEFAULT
. However, if you remove the statement hint, then Spanner uses the DEFAULT
execution method. For more information, see Optimize query execution.
ALLOW_TIMESTAMP_PREDICATE_PUSHDOWN
TRUE
|FALSE
(default)TRUE
, the query execution engine uses the timestamp predicate pushdown optimization technique. This technique improves the efficiency of queries that use timestamps and data with an age-based tiered storage policy. For more information, see Optimize queries with timestamp predicate pushdown. [ /*@ table_hint_key = table_hint_value [, ...] */ ] where table_hint_key is: FORCE_INDEX | GROUPBY_SCAN_OPTIMIZATION | SCAN_METHOD
Spanner supports the following table hints as extensions to open source PostgreSQL.
Hint key | Possible values | Description |
---|---|---|
FORCE_INDEX | String. The name of an existing index in the database or _BASE_TABLE to use the base table rather than an index. |
Note: |
GROUPBY_SCAN_OPTIMIZATION | TRUE |FALSE | The group by scan optimization can make queries faster if they use The optimization is applied if the optimizer estimates that it will make the query more efficient. The hint overrides that decision. If the hint is set to |
SCAN_METHOD | AUTO (default) |BATCH |ROW | Use this hint to enforce the query scan method. By default, Spanner sets the scan method as |
[ /*@ join_hint_key = join_hint_value [, ...] */ ] where join_hint_key is: FORCE_JOIN_ORDER | JOIN_METHOD | HASH_JOIN_BUILD_SIDE | BATCH_MODE
Spanner supports the following join hints as extensions to open source PostgreSQL.
Hint key | Possible values | Description |
---|---|---|
FORCE_JOIN_ORDER | TRUE |FALSE (default) | If set to true, use the join order that's specified in the query. |
JOIN_METHOD | HASH_JOIN |APPLY_JOIN |MERGE_JOIN |PUSH_BROADCAST_HASH_JOIN | When implementing a logical join, choose a specific alternative to use for the underlying join method. Learn more in Join methods. |
HASH_JOIN_BUILD_SIDE | BUILD_LEFT |BUILD_RIGHT | Specifies which side of the hash join is used as the build side. Can only be used with JOIN_METHOD=HASH_JOIN |
BATCH_MODE | TRUE (default) |FALSE | Used to disable batched apply join in favor of row-at-a-time apply join. Can only be used with JOIN_METHOD=APPLY_JOIN . |
function_name() [ /*@ function_hint_key = function_hint_value [, ...] */ ] where function_hint_key is: DISABLE_INLINE
Spanner supports the following function hints as extensions to open source PostgreSQL.
Hint key | Possible values | Description |
---|---|---|
DISABLE_INLINE | TRUE |FALSE (default) | If set to true, the function is computed once instead of each time another part of a query references it.
You can't use |
Examples
In the following example, inline expressions are enabled by default for x
. x
is computed twice, once by each reference:
SELECTSUBSTRING(x,2,5)ASw,SUBSTRING(x,3,7)ASyFROM(SELECTSHA512(z)ASxFROMt)ASsubquery
In the following example, inline expressions are disabled for x
. x
is computed once, and the result is used by each reference:
SELECTSUBSTRING(x,2,5)ASw,SUBSTRING(x,3,7)ASyFROM(SELECTSHA512(z)/*@ DISABLE_INLINE = TRUE */ASxFROMt)ASsubquery
Join methods are specific implementations of the various logical join types. Some join methods are available only for certain join types. The choice of which join method to use depends on the specifics of your query and of the data being queried. The best way to figure out if a particular join method helps with the performance of your query is to try the method and view the resulting query execution plan. See Query Execution Operators for more details.
Join Method | Description | Operands |
---|---|---|
HASH_JOIN | The hash join operator builds a hash table out of one side (the build side), and probes in the hash table for all the elements in the other side (the probe side). | Different variants are used for various join types. View the query execution plan for your query to see which variant is used. Read more about the Hash join operator. |
APPLY_JOIN | The apply join operator gets each item from one side (the input side), and evaluates the subquery on other side (the map side) using the values of the item from the input side. | Different variants are used for various join types. Cross apply is used for inner join, and outer apply is used for left joins. Read more about the Cross apply and Outer apply operators. |
MERGE_JOIN | The merge join operator joins two streams of sorted data. The optimizer will add Sort operators to the plan if the data is not already providing the required sort property for the given join condition. The engine provides a distributed merge sort by default, which when coupled with merge join may allow for larger joins, potentially avoiding disk spilling and improving scale and latency. | Different variants are used for various join types. View the query execution plan for your query to see which variant is used. Read more about the Merge join operator. |
PUSH_BROADCAST_HASH_JOIN | The push broadcast hash join operator builds a batch of data from the build side of the join. The batch is then sent in parallel to all the local splits of the probe side of the join. On each of the local servers, a hash join is executed between the batch and the local data. This join is most likely to be beneficial when the input can fit within one batch, but is not strict. Another potential area of benefit is when operations can be distributed to the local servers, such as an aggregation that occurs after a join. A push broadcast hash join can distribute some aggregation where a hash join cannot. | Different variants are used for various join types. View the query execution plan for your query to see which variant is used. Read more about the Push broadcast hash join operator. |
UNNEST
operatorunnest_operator: { UNNEST( array_expression ) | UNNEST( array_path ) } [ table_hint_expr ] [ as_alias ] as_alias: [AS] alias
The UNNEST
operator takes an array and returns a table, with one row for each element in the array. For input arrays of most element types, the output of UNNEST
generally has one column.
Input values:
array_expression
: an expression that produces an array.table_name
: The name of a table.array_path
: The path to an ARRAY
type.
Example:
SELECT*FROMUNNEST(ARRAY[10,20,30])asnumbers;/*---------* | numbers | +---------+ | 10 | | 20 | | 30 | *---------*/
alias
: An alias for a value table. An input array that produces a single column can have an optional alias, which you can use to refer to the column elsewhere in the query.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-04-17 UTC.