Google Big Query - Error: 37.1 - 38.24: The JOIN operator's right-side table must be a small table

Google Big Query - Error: 37.1 - 38.24: The JOIN operator's right-side table must be a small table

我在尝试将此 SQL 查询执行到 Google Big Query 时收到此错误消息。

Error: 37.1 - 38.24: The JOIN operator's right-side table must be a small table. Switch the tables if the left-side table is smaller, or use JOIN EACH if both tables are larger than the maximum described at https://cloud.google.com/bigquery/docs/reference/legacy-sql#joins

SQL查询

SELECT 
  a.login,
  e.CommitCommentEvent,
  e.CreateEvent,
  e.DeleteEvent,
  e.DeploymentEvent,
  e.DeploymentStatusEvent,
  e.DownloadEvent,
  e.FollowEvent,
  e.ForkEvent,
  e.ForkApplyEvent,
  e.GistEvent,
  e.GollumEvent,
  e.IssueCommentEvent,
  e.IssuesEvent,
  e.MemberEvent,
  e.MembershipEvent,
  e.PageBuildEvent,
  e.PublicEvent,
  e.PullRequestEvent,
  e.PullRequestReviewCommentEvent,
  e.PushEvent,
  e.ReleaseEvent,
  e.RepositoryEvent,
  e.StatusEvent,
  e.TeamAddEvent,
  e.WatchEvent
FROM (
  SELECT actor.login AS login,
    IFNULL(SUM(IF(type='CommitCommentEvent',1,NULL)),0) AS CommitCommentEvent,
    IFNULL(SUM(IF(type='CreateEvent',1,NULL)),0) AS CreateEvent,
    IFNULL(SUM(IF(type='DeleteEvent',1,NULL)),0) AS  DeleteEvent,
    IFNULL(SUM(IF(type='DeploymentEvent',1,NULL)),0) AS  DeploymentEvent,
    IFNULL(SUM(IF(type='DeploymentStatusEvent',1,NULL)),0) AS  DeploymentStatusEvent,
    IFNULL(SUM(IF(type='DownloadEvent',1,NULL)),0) AS  DownloadEvent,
    IFNULL(SUM(IF(type='FollowEvent',1,NULL)),0) AS  FollowEvent,
    IFNULL(SUM(IF(type='ForkEvent',1,NULL)),0) AS  ForkEvent,
    IFNULL(SUM(IF(type='ForkApplyEvent',1,NULL)),0) AS  ForkApplyEvent,
    IFNULL(SUM(IF(type='GistEvent',1,NULL)),0) AS  GistEvent,
    IFNULL(SUM(IF(type='GollumEvent',1,NULL)),0) AS  GollumEvent,
    IFNULL(SUM(IF(type='IssueCommentEvent',1,NULL)),0) AS  IssueCommentEvent,
    IFNULL(SUM(IF(type='IssuesEvent',1,NULL)),0) AS  IssuesEvent,
    IFNULL(SUM(IF(type='MemberEvent',1,NULL)),0) AS  MemberEvent,
    IFNULL(SUM(IF(type='MembershipEvent',1,NULL)),0) AS  MembershipEvent,
    IFNULL(SUM(IF(type='PageBuildEvent',1,NULL)),0) AS  PageBuildEvent,
    IFNULL(SUM(IF(type='PublicEvent',1,NULL)),0) AS  PublicEvent,
    IFNULL(SUM(IF(type='PullRequestEvent',1,NULL)),0) AS  PullRequestEvent,
    IFNULL(SUM(IF(type='PullRequestReviewCommentEvent',1,NULL)),0) AS  PullRequestReviewCommentEvent,
    IFNULL(SUM(IF(type='PushEvent',1,NULL)),0) AS  PushEvent,
    IFNULL(SUM(IF(type='ReleaseEvent',1,NULL)),0) AS  ReleaseEvent,
    IFNULL(SUM(IF(type='RepositoryEvent',1,NULL)),0) AS  RepositoryEvent,
    IFNULL(SUM(IF(type='StatusEvent',1,NULL)),0) AS  StatusEvent,
    IFNULL(SUM(IF(type='TeamAddEvent',1,NULL)),0) AS  TeamAddEvent,
    IFNULL(SUM(IF(type='WatchEvent',1,NULL)),0) AS  WatchEvent
  FROM (
    TABLE_DATE_RANGE([githubarchive:day.events_], 
      DATE_ADD(CURRENT_TIMESTAMP(), -1, "YEAR"),
      CURRENT_TIMESTAMP()
    )) AS events
  WHERE type IN ("CommitCommentEvent","CreateEvent","DeleteEvent","DeploymentEvent","DeploymentStatusEvent","DownloadEvent","FollowEvent",
  "ForkEvent","ForkApplyEvent","GistEvent","GollumEvent","IssueCommentEvent","IssuesEvent","MemberEvent","MembershipEvent","PageBuildEvent",
  "PublicEvent","PullRequestEvent","PullRequestReviewCommentEvent","PushEvent","ReleaseEvent","RepositoryEvent","StatusEvent","TeamAddEvent",
  "WatchEvent") 
  GROUP BY 1
) AS e
JOIN [githubuser.malaysia] AS a
ON e.login = a.login

将您的 JOIN 行更改为使用 JOIN EACH

明确:

JOIN EACH [githubuser.malaysia] AS a

BigQuery 以不同于大表的方式处理小表的联接,并且查询语言当前强制您在它们之间进行选择。

BQ 团队注意事项:最好让查询规划器自动切换边(如果可能),或者在必要时"upgrade"加入每个,并包含一个查询选项来执行此操作,例如"Automatically optimize joins" 默认开启。