When trying to write a query using Spanner Data Boost I get the following error:
DataBoost used for non-partitioned query
The code I'm using is as follows:
stmt := spanner.Statement{
SQL: query,
Params: params,
}
iter := client.Single().QueryWithOptions(ctx, stmt, spanner.QueryOptions{
Priority: spannerpb.RequestOptions_PRIORITY_LOW,
DataBoostEnabled: true,
})
Queries using Data Boost must be executed as described in the Cloud Spanner docs and use PartitionQueryWithOptions
. My code that works:
txn, err := client.BatchReadOnlyTransaction(ctx, spanner.StrongRead())
if err != nil {
return err
}
defer txn.Close()
stmt := spanner.Statement{
SQL: query,
Params: params,
}
partitions, _ := txn.PartitionQueryWithOptions(ctx,
stmt,
spanner.PartitionOptions{},
spanner.QueryOptions{
DataBoostEnabled: true
}
)
for _, p := range partitions {
iter := txn.Execute(ctx, p)
defer iter.Stop()
for {
row, err := iter.Next()
if err == iterator.Done {
break
} else if err != nil {
return err
}
fmt.Println(row)
}
}