BigQueryテクニック集 – 一時テーブルを使って低コストで開発

BigQuery

 and,a株式会社 デジタルマーケティングエンジニア 佐藤洋太

GA4+BigQueryを利用していてこのようなエラーに出くわすことはありませんか?

エラーメッセージ:
Quota exceeded: Your project exceeded quota for free query bytes scanned. For more information, see https://cloud.google.com/bigquery/docs/troubleshoot-quotas

このエラーはサンドボックスモードを利用していて、プロジェクトの無料クエリ使用分の限界に達した際に発生するエラーです。
SQLを試したい時にこのエラーが出ると非常に厄介です。
有料にすれば解決では?と思いますが、Billing情報を登録してサンドボックスモードを解除したとしても、大きなクエリはお金がかかってしまうため、結局のところクエリコストを如何に減らせるかがキモになってきます。結局はコストを減らす点、クエリの効率化を行うという点からは逃れられません。

このような背景から、今回は開発時に簡単に使えるクエリコストの軽減テクニックを考えてみます。また、このテクニックは無料使用分でも使えるテクニックですのでご参考にどうぞ。

一時テーブルとは?

そこで登場するのが一時テーブルという機能です。

公式のアナウンス:
https://cloud.google.com/bigquery/docs/multi-statement-queries?hl=ja#temporary_tables

一時テーブルを使用すると、中間結果をテーブルに保存できます。この一時テーブルはセッション レベルで存在するため、データセット内での保存や管理の必要はありません。

複数ステートメント クエリで一時テーブルを作成して参照できます。一時テーブルが不要になったら、手動で削除するか、BigQuery が 24 時間後に削除されるのを待ちます。

https://cloud.google.com/bigquery/docs/multi-statement-queries?hl=ja#temporary_tables

一時テーブルはコピー&ペーストの際のクリップボードのような一時的な保存領域と覚えておきましょう。コスト低減以外にも様々なメリットがあるので必須のテクニックかと個人的には考えています。
公式のドキュメントにもSQLソースの記載はありますが、正直めんどくさい・・・という方向けに楽に作る方法をご紹介します。

実践

工程

1:準備

まずは、クエリエディタを開きます。

2:設定

クエリ設定から「一時テーブルにクエリ結果を保存」を選択し、保存します。

3:SQLの実行

任意のSQLをペーストし、実行します。
今回はごく簡単なSQLを実行します。

4:テーブルが作成されたかの確認

先ほどのクエリ結果画面からジョブ詳細を選択すると宛先テーブルの行にTemporary table という文字がハイライトされています。

Temporary table をクリックすると一時テーブルのスキーマ画面が開きます

ここからクエリを選択して開くとSQLが発行されます
このSQLを実行すると先ほどの結果と同じものが保存されていることが確認できます

画像内のFROM句の文字列が一時テーブルの所在になっています。

下記が一時テーブルの住所です。

`project_id._af0a1e64d3998259dfc43b27b34d1c5d90d1bdcd.anonfd8da7be_cd28_49e0_9c05_8e0f0be12a60`

以上で一時テーブルを作成する操作は終わりです。

画面の操作だけで完結するのでほぼ問題ないと思います。

実際にどれぐらい変わるの?

では実際にどれぐらいコスト低減効果があるのかを試してみます。
今回は140GBを超えるGA4のテーブルに直接アクセスして比較しました

結果:

・経過時間が10秒ほど短くなっている
・消費したスロット時間が大幅に減少

この2点が大きな違いです。
スロット時間の消費は料金に対して直接影響がある部分ですので減少は大きなメリットですね。

最後に

重いテーブルを何回もスキャンするなら一時テーブルに保存してからクエリを開発する形がベストと思います。もちろん中間テーブルを利用するのも有用だと思います。特に有料版ではスケジュールクエリなどを利用して中間テーブルを作成することを強くお勧めします。

関連記事

特集記事

コメント

  1. Really informative article post.Really thank you!

  2. wow, awesome blog.Much thanks again. Keep writing.

  3. This is one awesome article post.Much thanks again.

  4. Really appreciate you sharing this post.Really looking forward to read more. Much obliged.

  5. Great article post. Will read on…

  6. ivermectin walgreens ivermectin egg withdrawal

  7. Thanks for the blog post. Really Cool.

  8. Very good blog.Really thank you! Really Cool.

  9. A big thank you for your article.Thanks Again. Cool.

  10. I value the post. Much obliged.

  11. I really enjoy the article post.Much thanks again. Awesome.

  12. What’s Going down i am new to this, I stumbled upon this I’ve found It absolutely useful and it has helped me out loads. I’m hoping to give a contribution & aid other users like its aided me. Great job.

  13. fountain pointe apartments grandview heights apartments plantation apartments

  14. After being escorted to the room, I turned on the air conditioner, then I went to the car.

  15. Fantastic blog post.Really thank you! Want more.

  16. Thank you, I’ve recently been looking for information approximately this subject for a while and yours is the greatest I’ve came upon so far. But, what concerning the bottom line? Are you certain concerning the source?

  17. what is atorvastatin] generic for lipitor atorvastatin medication

  18. An intriguing discussion is worth comment. There’s no doubt that that you need to publish more about this subject matter, it might not be a taboo subject but usually people do not speak about these topics. To the next! Cheers!!

  19. Specifically the sort of material that enriches the internet. Thanks!

  20. I really like your writing style, excellent information, regards for putting up : D.

  21. It’s difficult to find educated people about this topic, but youseem like you know what you’re talking about! Thanks

  22. yasmin uk online – yasmin 28 birth control yasmin brand coupon

  23. I really enjoy the blog post.Really thank you! Really Great.

  24. Great, thanks for sharing this blog.Really looking forward to read more. Really Great.

  25. Thanks for the blog.Thanks Again. Want more.

  26. best erectile dysfunction treatmenterectile sprayerectile dysfunction injections

  27. At this moment I am going to do my breakfast, once having my breakfast coming over again to read additionalnews.

  28. Hit me up! I enjoyed your post. Thank you. You’ve made my day! Thx again. Great post!

  29. Great blog post. Want more.

  30. Hey, thanks for the article post.Much thanks again. Really Cool.

  31. pretty beneficial material, overall I believe this is worthy of a bookmark, thanks

  32. Enjoyed every bit of your post.Really looking forward to read more. Great.

  33. I really like and appreciate your blog article.Really looking forward to read more. Want more.

  34. Itís hard to come by experienced people on this topic, however, you seem like you know what youíre talking about! Thanks

  35. Hi there, I enjoy reading all of your post.I like to write a little comment to support you.

  36. You could definitely see your skills in the work you write. The arena hopes for more passionate writers such as you who aren’t afraid to mention how they believe. Always follow your heart.

  37. I have been examinating out some of your stories and i can state pretty clever stuff. I will make sure to bookmark your blog.

  38. Simply a smiling visitant here to share the love (:, btw outstanding style and design .

  39. I couldn’t refrain from commenting. Perfectly written! kokosvatten ica maxi swere.sewomenpriz.com/advice-girlfriends/kokosvatten-ica-maxi.php

  40. I value the article.Thanks Again. Awesome.

  41. Great post.Much thanks again. Will read on…

  42. Enjoyed every bit of your article post.Thanks Again. Fantastic.

  43. Say, you got a nice blog post.Really thank you! Awesome.

  44. I think this is a real great blog.Thanks Again. Cool.

  45. Appreciate you sharing, great blog.Really thank you! Really Great.

  46. I am curious to find out what blog system you have been working with? I’m having some small security problems with my latest blog and I would like to find something more safe. Do you have any recommendations?

  47. This is one awesome article post.Thanks Again. Really Cool.

  48. mexican online mail order pharmacy cvs pharmacy

  49. best replica watches review is normally dedicated producing the more leading-edge an element of the watch.

  50. Is There A Way A Minor Can Make Money Online For Free?: I am looking for any legitimate sites that i can make a li

  51. Nice post. I understand some thing additional challenging on different blogs everyday. It is going to usually be stimulating to read content from other writers and practice somewhat something from their store. I’d prefer to use some with the content on my blog whether or not you do not mind. Natually I’ll provide you with a link on your internet weblog. Thanks for sharing.

  52. I like the valuable info you provide in your articles.

    I’ll bookmark your blog and check again here
    frequently. I’m quite sure I’ll learn a lot of new stuff
    right here! Best of luck for the next!

  53. When I originally commented I clicked the “Notify me when new comments are added” checkbox and now each time a comment is added I get four e-mails
    with the same comment. Is there any way you can remove people from that service?
    Appreciate it!

  54. Hey! Do you use Twitter? I’d like to follow you if that would
    be ok. I’m undoubtedly enjoying your blog and look forward to
    new posts.

  55. I have to thank you for the efforts you’ve put in writing this site.
    I really hope to check out the same high-grade blog posts from you later on as well.

    In truth, your creative writing abilities has inspired me to get my own,
    personal blog now 😉

  56. Hi there just wanted to give you a quick heads up. The
    words in your article seem to be running off the screen in Safari.
    I’m not sure if this is a format issue or something to do with web browser compatibility but I figured
    I’d post to let you know. The design and style look
    great though! Hope you get the issue resolved soon.
    Cheers

  57. Great blog! Is your theme custom made or did you download it from somewhere?
    A design like yours with a few simple adjustements would really make my blog shine.
    Please let me know where you got your design. Appreciate it

  58. What a stuff of un-ambiguity and preserveness of precious experience concerning unpredicted emotions.

  59. Thanks a lot for the article.Much thanks again. Will read on…

  60. If you are going for best contents like I do, only pay a quick visit
    this web page every day since it presents feature contents, thanks

  61. commander médicaments en ligne Generis Badhoevedorp medicamentos para estimular la fertilidad

  62. When someone writes an paragraph he/she keeps the plan of a user in his/her mind that how
    a user can know it. So that’s why this piece
    of writing is amazing. Thanks!

  63. приснился бывший парень хорошо общались союз женщина
    овен и рак мужчина какой у деве камень зодиака
    гадание на ближайшее будущее в личной жизни заговор для продажи кота

  64. medicijnen te koop in Zwolle – bestel nu en ontvang snel.
    Yoshindo Crans-Montana farmaci disponibile per l’acquisto
    in Francia

  65. It’s the best time to make a few plans for the future and it is
    time to be happy. I have read this post and if I may just I
    desire to recommend you few interesting issues or advice.
    Perhaps you could write next articles relating to this article.
    I want to read more things approximately it!

  66. medicijnen: betrouwbare pijnverlichting zonder recept Biofarm Huizen médicaments en ligne :
    avantages et inconvénients

  67. мой папа красавчик песня, папа mp3 үй
    шаруашылықтарының бюджетінің ерекшеліктері, үй шаруашылығы деген не
    ғазірет камшат, газрет кажымуканулы биография асп 2023, калькулятор
    асп 2023

  68. әке туралы толғаныс онлайн мектеп, әке асқар тау
    жалғасы жер ананы сақтайық шығарма жазу, жер ананы аялайық эссе штрафы по иин, административный штраф рк по
    иин intel core i5 10 400f характеристики,
    intel core i5-10400f отзывы

  69. аккорд а на гитаре, как научиться играть
    на гитаре с нуля в домашних условиях кэш
    юн ли, не удалось выполнить вход в ис эсф от имени организации костанайская область
    амангельдинский район индекс, костанай индекс менің үлгі тұтар ұстазым, үлгі менің ұстазым

  70. Good

  71. canadian mail order pharmacy – canadian pharmacy oxycodone canadian mail order pharmacy

ランキング(週間)

  1. 1

    GA4 「ページ ロケーション」と「ページ パス と スクリーン クラス」何が違う?ドメインの有無以外にもパラメータの扱いに違いあり

  2. 2

    GA4 拡張計測機能の新顔「フォームの操作」 form_start, form_submit

  3. 3

    GA4の探索で「ページ別訪問数」を見ることは可能か?

  4. 4

    GA4のレポート画面の数値データは、イベント発生時から何時間後に確定するのか?

  5. 5

    GA4 クロスドメイン設定では、リンク先に「_gl」パラメータが付く。勝手なパラメータを付けるとエラーになるページは要注意

  6. 6

    Ads Data Hub(ADH) とはどんなものですか?GA4との関連は?

  7. 7

    YouTubeの概要欄に貼られたリンクをクリックしてサイトを訪れたユーザーを計測するために

  8. 8

    GA4で異なるドメイン(サブドメイン)の同一ページパスをドメイン付きで表示する

  9. 9

    GA4の指標「総ユーザー数」VS「アクティブ ユーザー数」

  10. 10

    GA4で設定したイベントの消し方(削除の仕方)

最近の記事

  1. 生成AIを調整してABテストを実装したら想像以上に早かった

  2. 無料で使えるABテストツールのバージョンアップを行いました

  3. 無料ABテストツール(and,B)のマニュアルを作成しました

カテゴリー

 
TOP