1
votes

Is it possible to execute multiple queries against the Google Spanner in on round trip?

For example, I would like to run the following two queries in one round trip: (From performance concerns)

select * from Test1;

select * from Test2;
2

2 Answers

3
votes

No, not in a single request. Current batching support is only for writes. Instead, send the 2 requests in parallel on separate requests.

2
votes

There are couple of other things you can do to compose a single query in such a way that it contains the result of both those queries:

  1. Use "UNION ALL" operator https://cloud.google.com/spanner/docs/query-syntax#union : SELECT * FROM Test1 UNION ALL SELECT * FROM Test2

This only works if the number of columns in the two tables is same and are of the same type (or have a common supertype)

  1. Use a query like this:

SELECT ARRAY(SELECT AS STRUCT * FROM T1), ARRAY(SELECT AS STRUCT * FROM T2)

This works even if the two tables have different number of columns or different column types. Limitation here is that this will just return a single row containing all the data which will be fully materialized in memory.