0
votes

a simple count query on one of my tables takes a long time to complete (~18 secs), this table has around half a million rows, and making the same query in a bigger table (around 3 mil) takes less than 3 secs. The schema is exactly the same and the query is a simple SELECT count(*) FROM [dataset.table]

Any ideas why this is happening and what can I do to prevent it?

1
How much data is each query processing? - mimming
Can you provide a job id for the query that took 18 seconds? - Jordan Tigani
@JenTong : According to the UI, a count processes 0B. The table itself has 404 MB according to the same UI - arinarmo
@JordanTigani : I can provide it, it happens each time i do the query, should I just post the id here? - arinarmo
Yes, please post it, it will let one of the BigQuery engineers look at the query statistics to try to figure out what is going wrong. COUNT(*) over a small table should not take that long. - Jordan Tigani

1 Answers

0
votes

It looks like the issue with your table is that it was created in a lot of small chunks; this takes more work to query, since we spend a lot of time on filesystem operations (listing files and opening them).

Even so, a table the size of yours should not be so slow; BigQuery is currently experiencing high filesystem load that is causing high variability in latency. We're actively working on resolving this one. So that is the first problem.

The second problem is that we probably should do a better job of compacting the table. I've filed an internal bug that we should tweak our heuristics to be a bit more aggressive in compaction.

As a workaround, you can compact the table manually by copying the table in place. In other words, run a SELECT * from ... and writing the output to the same table, using writeDisposition:WRITE_TRUNCATE, destinationTable:<your table> and allowLargeResults:true and flattenSchema:false.

Again, this last step shouldn't be needed, but for now it should improve your situation.