BigQueryã§ã¯ã¨ãªãæ¸ãæã«ãã¯ã¨ãªã®æ¸ãæ¹ã«ãã£ã¦å®è¡æéãé«éåã§ãããå¦çãããã¤ãæ°ãç¯ç´ãããã§ãã¾ã
Googleãå
¬å¼ã§BigQueryのベストプラクティス集(今はまだ未翻訳)ãå
¬éãã¦ããã¦ããã®ã§ããã®ãã¡ã®ã¯ã¨ãªãæ¸ãæå¨ãã®ãã¦ãã¦ãç°¡åã«ã¾ã¨ãã¦ããã¾ããå¥ã
ã®ãã¼ã¸ã®å
容ãªã®ã§éè¤ããã£ãã端æã£ãããã¦ãã¾ã
誤訳ã解éã®èª¤ãããã£ããã³ã¡ã³ããªã©ã§æãã¦ãã ãã
- BigQueryã®ãã¹ããã©ã¯ãã£ã¹(ã¯ã¨ãªç·¨)
- å
¥åããããã¼ã¿ã®éãæ¸ãã
- SELECT *ãé¿ãã
- æ¥ä»ã§ãã¼ãã£ã·ã§ãã³ã°ããããã¼ãã«ã®å ´åå¿ è¦ãªãã¼ãã£ã·ã§ã³ã ããæå®ãã
- å¯è½ãªéãéæ£è¦åããããã¼ã¿ã§æ±ã
- å¤é¨ãªã½ã¼ã¹ãå ¥åã«ããã®ã¯é«éã§ã¯ãªã
- ãã¼ãã«åãã¯ã¤ã«ãã«ã¼ãã§æå®ããã¨ãã¯å¿ è¦ãªãã¼ãã«ã ããæå®ãã
- éä¿¡ã®æé©å
- è¨ç®ã®æé©å
- åãå¤æãSQLã§ä½åº¦ãããã®ãé¿ãã
- JavaScript ã®ã¦ã¼ã¶ã¼å®ç¾©é¢æ°(UDF)ãé¿ãã
- è¿ä¼¼çãªéè¨é¢æ°ã使ã
- ã¯ã¨ãªã®é çªã«æ°ãã¤ãã
- JOINã®é çªã«æ°ãã¤ãã
- æ¥ä»ã§ãã¼ãã£ã·ã§ãã³ã°ããããã¼ãã«ã®å ´åå¿ è¦ãªãã¼ãã£ã·ã§ã³ã ããæå®ãã
- åºåå¨ãã®æé©å
- ã¢ã³ããã¿ã¼ã³ãé¿ãã
- å
¥åããããã¼ã¿ã®éãæ¸ãã
- å人çãªææ³
- ã©ã¤ã»ã³ã¹å¨ã
BigQueryã®ãã¹ããã©ã¯ãã£ã¹(ã¯ã¨ãªç·¨)
å ¥åããããã¼ã¿ã®éãæ¸ãã
Managing Input Data and Data Sources | BigQuery | Google Cloud Platform
SELECT *
ãé¿ãã
SELECT *
ã¯ãã¼ãã«å
¨ä½ãèªã¿è¾¼ãã§ãã¾ãã®ã§ãããªããã§ããã ã使ãã«ã©ã ãæ¸ããã¾ããã
Standard SQLã使ã£ã¦ãããªãSELECT * EXCEPT (ã«ã©ã å1, ...)
ã¨æ¸ããã¨ã§æå®ããã«ã©ã 以å¤ã®ã«ã©ã ãåã£ã¦ãããã¨ã§å°ãç¯ç´ãã§ããã
LIMIT
ãä»ãã¦ãèªã¿è¾¼ã¾ãããã¼ã¿éã¯å¤ãããªãã®ã§ããã¼ãã«å
¨ä½ãèªã¿è¾¼ãã ã®ã¨åããã¤ãéã§èª²éããã¦ãã¾ãã¾ã
ããããã¹ã¦ã®ã«ã©ã ã«ã¢ã¯ã»ã¹ããå¿
è¦ãããã®ãªããããããããã¼ãã«ãæ¥ä»ã§ãã¼ãã£ã·ã§ãã³ã°ãã¦ãããããã¦å°ãããã¦ããã¨ãã
æ¥ä»ã§ãã¼ãã£ã·ã§ãã³ã°ããããã¼ãã«ã®å ´åå¿ è¦ãªãã¼ãã£ã·ã§ã³ã ããæå®ãã
æ¥ä»ã§ãã¼ãã£ã·ã§ãã³ã°ããããã¼ãã«ã«ã¯ã¨ãªãæ¸ãå ´åãå¿ è¦ãªæ¥ä»ãæå®ãããã¨ã§è¨ç®ã«ä¸å¿ è¦ãªæ¥ä»ã®ãã¼ã¿ãåã£ã¦ãããã¨ããªããªãã¾ã
WHERE _PARTITIONTIME BETWEEN TIMESTAMP("2017-10-01") AND TIMESTAMP("2017-10-07")
å¯è½ãªéãéæ£è¦åããããã¼ã¿ã§æ±ã
éæ£è¦åããããã¼ã¿ã¯JOINãå¿ è¦ãªãã®ã§å¹ççã«ä¸¦åã«ã¯ã¨ãªãå®è¡ãããã¨ãã§ãã
1対å¤ã®é¢ä¿æ§ãflattenãããå½¢ã®ãã¼ã¿ã§æã¤ããã¯(æ§é ä½ã®)é
åã®ãã£ã¼ã«ãã§æã¤ã¹ãã
(æ§é ä½ã®)é
åã®ãã£ã¼ã«ãã使ããã«flattenããããã¼ã¿ãæ±ãå ´åãGROUP BY
ãå¿
è¦ã«ãªã£ã¦ãããã¯ã¼ã¯éä¿¡(ã·ã£ããã«)ã®ããã§ããã©ã¼ãã³ã¹ãè½ã¡ããã¨ããã
å¤é¨ãªã½ã¼ã¹ãå ¥åã«ããã®ã¯é«éã§ã¯ãªã
BigQueryã§ã¯Google Cloud StorageãGoogle DriveãGoogle Cloud Bigtableãå ¥åã«ãããã¨ãã§ããããBigQueryã®ãã¼ãã«ãåç §ããã»ããåºæ¬çã«é«éãªã®ã§ã¯ã¨ãªã®ããã©ã¼ãã³ã¹ãéè¦ãªã¨ãã¯ä½¿ãã¹ãã§ã¯ãªã
ãã¼ãã«åãã¯ã¤ã«ãã«ã¼ãã§æå®ããã¨ãã¯å¿ è¦ãªãã¼ãã«ã ããæå®ãã
BigQueryã§ã¯FROM
ã§æå®ãããã¼ãã«åã®æ«å°¾ã«*
ãæå®ãããã¨ã§ãã¬ãã£ãã¯ã¹ã«ãããããè¤æ°ã®ãã¼ãã«ãããã¼ã¿ãåã£ã¦ãããã¨ãã§ãã
ãã¼ãã£ã·ã§ã³ã®é¨åã§ãåããããªè©±ããã¦ããããå¿
è¦ãªããã¼ãã«ã¯åã£ã¦ããå¿
è¦ãç¡ãã®ã§å¿
è¦ååãªã§ããã ãé·ããã¬ãã£ãã¯ã¹ãæå®ããã¨ãã
ãã®è¨äºã®åæã«ã¯æ¸ããã¦ããªããWHERE _TABLE_SUFFIX BETWEEN '20171001'AND '20171007'
ã®ããã«ã¯ã¤ã«ãã«ã¼ãé¨åã«æ¡ä»¶ãæ¸ãã¦çµãè¾¼ããã¨ãã§ãã
éä¿¡ã®æé©å
Optimizing Communication Between Slots | BigQuery | Google Cloud Platform
JOINããåã«ãã¼ã¿ã®éãæ¸ãã
JOIN
ããå¾ã«ãã¼ã¿ãWHERE
ã®æ¡ä»¶ãªã©ã§ãã£ã«ã¿ãªã³ã°ããã®ã¨ãJOIN
ããåã«ãã£ã«ã¿ãªã³ã°ããã®ã§ã¯ããã©ã¼ãã³ã¹ã大ããå¤ãããã¨ããã
JOIN
ããåã«ãã¼ã¿éãæ¸ãããã¨ãå¯è½ãªãã§ããã ãããã¹ã
WITHå¥ã使ã£ã¦ãã¯ã¨ãªã¯å¹ççã«ãªããªã
WITH
å¥ã¯ä¸»ã«å¯èªæ§ãã³ã¼ãã®æ¸ããããã®ããã®ãã®ã§ãè¤æ°ã®WITH
å¥ä¸ã«å
±éã®ã¯ã¨ãªãå«ã¾ãã¦ãã¦ãããããå®è¡ããã
æ¥ä»ãã¨ã«ãã¼ãã«ãä½ãã®ãé¿ãã
ããããã®ãã¼ãã«ãã¨ã«ã¹ãã¼ããã¡ã¿ãã¼ã¿ãæã£ããããã¼ããã·ã§ã³ã®ç¢ºèªãããªãã¨ãããªãã®ã§å¹ççã§ã¯ãªã
ããæ¥ä»ãã¨ã«åå²ããªããªããã¼ãã£ã·ã§ã³ã®æ©è½ã使ãã¹ã
è¨ç®ã®æé©å
Optimizing Query Computation | BigQuery | Google Cloud Platform
åãå¤æãSQLã§ä½åº¦ãããã®ãé¿ãã
åããã¼ã¿ã®å¤æçµæãä½åº¦ã使ãã¨ãã¯ãéä¸çµæãå¥ã®ãã¼ãã«ã«ä¿åãã¹ã
JavaScript ã®ã¦ã¼ã¶ã¼å®ç¾©é¢æ°(UDF)ãé¿ãã
JavaScriptã®UDFãå¼ã¶ã¨Java(åæãã)ã®ãµãããã»ã¹ãå®è¡ãããã®ã§é ããªããå¯è½ãªãSQLã®UDFã使ãã¹ã
è¿ä¼¼çãªéè¨é¢æ°ã使ã
çµ±è¨çãªè¿ä¼¼ã«ããéè¨é¢æ°ãããã¤ãå®è£ ããã¦ããã®ã§ãæ£ç¢ºãªå¤ãå¿ è¦ã§ãªãã¨ãã¯ãããã使ã£ãã»ããå¹çç
ã¯ã¨ãªã®é çªã«æ°ãã¤ãã
ãã¼ã¿ãORDER BY
ã§ã½ã¼ããã¦ãããã£ã«ã¿ãªã³ã°ããã®ã¨ããã£ã«ã¿ãªã³ã°ãã¦ããã½ã¼ãããã®ã§ã¯å¾è
ã®æ¹ãå§åçã«éãã
ã½ã¼ããæ£è¦è¡¨ç¾ãªã©ã«ããè¤éãªå¦çã¯ã§ããã ãå¾ã®æ¹ã§è¡ã£ãã»ãããã¼ã¿éãæ¸ã£ã¦ããã®ã§å¹çç
JOINã®é çªã«æ°ãã¤ãã
ããç¨åº¦ã¯ãªããã£ãã¤ã¶ãé
æ
®ãã¦ããããã大ããªãã¼ãã«ã«å¯¾ãã¦å°ããªãã¼ãã«ãJOIN
ããããã«ãã¦ããã¨å¹ççã«ãªã
æ¥ä»ã§ãã¼ãã£ã·ã§ãã³ã°ããããã¼ãã«ã®å ´åå¿ è¦ãªãã¼ãã£ã·ã§ã³ã ããæå®ãã
ä¸ã®æ¹ã§æ¸ããã®ã¨åããå¦çãããã¼ã¿éãæ¸ãã®ã§å¹ççã«ãªã
åºåå¨ãã®æé©å
Managing Query Outputs | BigQuery | Google Cloud Platform
ç¹°ãè¿ãJOINããµãã¯ã¨ãªãããã®ãé¿ãã
ä½åº¦ãåããã¼ãã«ãJOIN
ãããä½åº¦ãåããµãã¯ã¨ãªãæããå ´åã¯ããããã£ããã¼ãã«ãä½ã£ã¦ãã¾ã£ãã»ããå¹ççã«ãªã
åºåã大ããå ´åã«ã¯ãã¼ãã«ã«ä¿åãããã¨ãèãã
ã¯ã¨ãªã®çµæã大ããããã¨Response too large
ã¨ããã¨ã©ã¼ã«ãªã
ãã®å ´ååºåããã£ã«ã¿ãªã³ã°ãããLIMIT
ãæå®ãã¦ãã¼ã¿éãå°ãªããããããã¼ãã«ã«ä¿åããã°ãã
ãã ããã¼ãã«ã«ä¿åããå ´åã«ã¯ã¹ãã¬ã¼ã¸ä»£ãããã
大ããªãã¼ã¿ãã½ã¼ãããã¨ãã¯LIMITãæå®ãã
大éã®ãã¼ã¿ã«å¯¾ãã¦ORDER BY
ãæå®ããã¨Resources exceeded
ã®ã¨ã©ã¼ãåºã¦ãã¾ã
ãã®å ´åLIMIT
ãæå®ããã¨ã¨ã©ã¼ãã§ãªããªããã¨ããã
ã¢ã³ããã¿ã¼ã³ãé¿ãã
Avoiding SQL Anti-Patterns | BigQuery | Google Cloud Platform
self joinãé¿ãã
åããã¼ãã«å士ãJOIN
ããself joinã¯ãã¼ã¿ã®è¡æ°ã大ããå¢ãããã¨ãå¤ã
ã§ããã ãself joinã®ä»£ããã«ã¦ã£ã³ãã¦é¢æ°ã使ãã¹ã
ãã¼ã¿ã®åã
GROUP BY
ãJOIN
ãªã©ãããæã«ãã¼ã®å¤ã«åããããã¨ããã©ã¼ãã³ã¹ã«æªå½±é¿ããã
ä¾ãã°ã¦ã¼ã¶ã¼IDã§GROUP BY
ãã¦éè¨ããæã«ãã»ã¨ãã©ã®ã¬ã³ã¼ãã®ã¦ã¼ã¶ã¼IDãnull
ã§èããåãã«ãªã£ãããã
åããæ¿ããã¨ããã®å¤ãå²ãå½ãã£ãã¹ãããã®ãªã½ã¼ã¹ã使ãåã£ã¦resources exceeded
ã®ã¨ã©ã¼ãåºã
対çã¨ãã¦ã¯ä»¥ä¸ã®2ã¤ããã
- è¿ä¼¼çãªéè¨é¢æ°ã使ã
- ã§ããã ãããããããã¼ã¿éãæ¸ããã¦ãã
åæ§ã«JOINã®ã¨ãã以ä¸ã®ãããªå¯¾çãèãããã
- ã§ããã ãããããããã¼ã¿éãæ¸ããã¦ãã
- å¯è½ãªã2ã¤ã®ã¯ã¨ãªã«åãã
以ä¸ã®è¨äºã®èª¬æããããããã
Query Plan Explanation | BigQuery | Google Cloud Platform
CROSS JOIN(ãã«ã«ãç©)
ãã¼ãã«ã®è¡ã®ãã¹ã¦ã®çµã¿åããã§JOINããCROSS JOIN
ãããã¨ãã¼ã¿éãé常ã«å¤ããªã£ã¦ææªã¯ã¨ãªãçµãããªããªã
ã§ããã ãCROSS JOINã使ããã«ã¦ã£ã³ãã¦é¢æ°ã使ã£ãããããå¯è½ãªãéè¨ãã¦ããCROSS JOINããã¨ãã(ãã®é¨åã¯ç¿»è¨³ãæªãããåæâUse a GROUP BY clause to pre-aggregate the data.
)
UPDATEãINSERTã1è¡ãã¤ãããªã
UPDATE
ãINSERT
ã¯1è¡ãã¤ãããã«è¤æ°è¡ã§ã¾ã¨ãã¦è¡ãã®ããã
å人çãªææ³
éæ£è¦åããããã¼ã¿ã®æ¹ãå¹ççã¨ãã話ã¨WITH
å¥ã使ã£ã¦ãã¯ã¨ãªã¯å¹ççã«ãªããªãã¨ãã話ãæå¤ã ã£ã
æ¥ä»ãã¨ã«ãã¼ãã«ã使ãã®ã§ã¯ãªããã¼ãã£ã·ã§ã³æ©è½ã使ãã®ãå¼·ãæ¨å¥¨ããã¦ãããããã¼ãã«ãåããªãå ´åãã¼ãã£ã·ã§ã³æå®ãå¿ããã¨ãã¼ãã«ã®ãã«ã¹ãã£ã³ãåãã¦èª²éçã«æ»ã¬å¯è½æ§ãæãã¦ãªããªããã¼ãã£ã·ã§ã³ã«ç§»è¡ã§ãã¦ããªã
ãã¼ãã£ã·ã§ã³ãæå®ããªãã¯ã¨ãªã¯æããããªãããã«ããè¨å®ã¿ãããªã®ãã§ããªãã®ã ãããâ¦â¦
ã©ã¤ã»ã³ã¹å¨ã
ãã®è¨äºã¯ä»¥ä¸ã®URLã®ããã¥ã¡ã³ãã«æ¸ããã¦ããå 容ã®ç¿»è¨³ãå¤ãå«ã¿ã¾ã
- BigQuery Best Practices: Optimizing Query Performance | BigQuery | Google Cloud Platform
- Managing Input Data and Data Sources | BigQuery | Google Cloud Platform
- Optimizing Communication Between Slots | BigQuery | Google Cloud Platform
- Optimizing Query Computation | BigQuery | Google Cloud Platform
- Managing Query Outputs | BigQuery | Google Cloud Platform
- Avoiding SQL Anti-Patterns | BigQuery | Google Cloud Platform
å ã®ããã¥ã¡ã³ãã¯Creative Commons 3.0 Attribution Licenseã§å ¬éããã¦ããã®ã§ãã®è¨äºã«ã¤ãã¦ãåæ§ã§ã
念ã®ããSite Policiesã®ãã¼ã¸ã«ãã£ã以ä¸ã®è¡¨ç¤ºãè¼ãã¦ããã¾ã
Site Policies | Google Developers
Portions of this page are modifications based on work created and shared by Google and used according to terms described in the Creative Commons 3.0 Attribution License.