batching update statement to avoid updating 1 row at a time with BigQuery

93 views Asked by At

I'm reading this section DML statements that update or insert single rows and I don't understand why the following statement is not "updating 1 row at a time":

UPDATE
  dataset.t t
SET
  my_column = u.my_column
FROM
  dataset.u u
WHERE
  t.my_key = u.my_key

Why is this considered as batched statement? The way I read this is that each row is going to be evaluated to make sure that the column is updated correctly only when the key is matching. What's under the hood of this statement that make it a batch?

1

There are 1 answers

0
Peter Boone On

That batch update example is meant to be in contrast to multiple update statements. This is not recommended:

UPDATE dataset.t t
SET my_column = "some literal"
WHERE t.my_key = "1";


UPDATE dataset.t t
SET my_column = "some literal 2"
WHERE t.my_key = "2";

-- ...

UPDATE dataset.t t
SET my_column = "some literal n"
WHERE t.my_key = "n";

In the batch example, BigQuery can update many rows with just one statement. I don't know exactly what's going on under the hood, but it must be more efficient.