Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

planner: fix group concat projection elimination logic #47612

Merged
merged 2 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion planner/core/casetest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ go_test(
],
data = glob(["testdata/**"]),
flaky = True,
shard_count = 18,
shard_count = 19,
deps = [
"//domain",
"//parser",
Expand Down
8 changes: 8 additions & 0 deletions planner/core/casetest/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -431,3 +431,11 @@ func TestFixControl45132(t *testing.T) {
tk.MustExec(`set @@tidb_opt_fix_control = "45132:0"`)
tk.MustHavePlan(`select * from t where a=2`, `TableFullScan`)
}

func TestIssue41957(t *testing.T) {
store := testkit.CreateMockStore(t)
tk := testkit.NewTestKit(t, store)
tk.MustExec(`use test`)
tk.MustExec("CREATE TABLE `github_events` (\n `id` bigint(20) NOT NULL DEFAULT '0',\n `type` varchar(29) NOT NULL DEFAULT 'Event',\n `created_at` datetime NOT NULL DEFAULT '1970-01-01 00:00:00',\n `repo_id` bigint(20) NOT NULL DEFAULT '0',\n `repo_name` varchar(140) NOT NULL DEFAULT '',\n `actor_id` bigint(20) NOT NULL DEFAULT '0',\n `actor_login` varchar(40) NOT NULL DEFAULT '',\n `language` varchar(26) NOT NULL DEFAULT '',\n `additions` bigint(20) NOT NULL DEFAULT '0',\n `deletions` bigint(20) NOT NULL DEFAULT '0',\n `action` varchar(11) NOT NULL DEFAULT '',\n `number` int(11) NOT NULL DEFAULT '0',\n `commit_id` varchar(40) NOT NULL DEFAULT '',\n `comment_id` bigint(20) NOT NULL DEFAULT '0',\n `org_login` varchar(40) NOT NULL DEFAULT '',\n `org_id` bigint(20) NOT NULL DEFAULT '0',\n `state` varchar(6) NOT NULL DEFAULT '',\n `closed_at` datetime NOT NULL DEFAULT '1970-01-01 00:00:00',\n `comments` int(11) NOT NULL DEFAULT '0',\n `pr_merged_at` datetime NOT NULL DEFAULT '1970-01-01 00:00:00',\n `pr_merged` tinyint(1) NOT NULL DEFAULT '0',\n `pr_changed_files` int(11) NOT NULL DEFAULT '0',\n `pr_review_comments` int(11) NOT NULL DEFAULT '0',\n `pr_or_issue_id` bigint(20) NOT NULL DEFAULT '0',\n `event_day` date NOT NULL,\n `event_month` date NOT NULL,\n `event_year` int(11) NOT NULL,\n `push_size` int(11) NOT NULL DEFAULT '0',\n `push_distinct_size` int(11) NOT NULL DEFAULT '0',\n `creator_user_login` varchar(40) NOT NULL DEFAULT '',\n `creator_user_id` bigint(20) NOT NULL DEFAULT '0',\n `pr_or_issue_created_at` datetime NOT NULL DEFAULT '1970-01-01 00:00:00',\n KEY `index_github_events_on_id` (`id`),\n KEY `index_github_events_on_created_at` (`created_at`),\n KEY `index_github_events_on_repo_id_type_action_month_actor_login` (`repo_id`,`type`,`action`,`event_month`,`actor_login`),\n KEY `index_ge_on_repo_id_type_action_pr_merged_created_at_add_del` (`repo_id`,`type`,`action`,`pr_merged`,`created_at`,`additions`,`deletions`),\n KEY `index_ge_on_creator_id_type_action_merged_created_at_add_del` (`creator_user_id`,`type`,`action`,`pr_merged`,`created_at`,`additions`,`deletions`),\n KEY `index_ge_on_actor_id_type_action_created_at_repo_id_commits` (`actor_id`,`type`,`action`,`created_at`,`repo_id`,`push_distinct_size`),\n KEY `index_ge_on_repo_id_type_action_created_at_number_pdsize_psize` (`repo_id`,`type`,`action`,`created_at`,`number`,`push_distinct_size`,`push_size`),\n KEY `index_ge_on_repo_id_type_action_created_at_actor_login` (`repo_id`,`type`,`action`,`created_at`,`actor_login`),\n KEY `index_ge_on_repo_name_type` (`repo_name`,`type`),\n KEY `index_ge_on_actor_login_type` (`actor_login`,`type`),\n KEY `index_ge_on_org_login_type` (`org_login`,`type`),\n KEY `index_ge_on_language` (`language`),\n KEY `index_ge_on_org_id_type` (`org_id`,`type`),\n KEY `index_ge_on_actor_login_lower` ((lower(`actor_login`))),\n KEY `index_ge_on_repo_name_lower` ((lower(`repo_name`))),\n KEY `index_ge_on_language_lower` ((lower(`language`))),\n KEY `index_ge_on_type_action` (`type`,`action`) /*!80000 INVISIBLE */,\n KEY `index_ge_on_repo_id_type_created_at` (`repo_id`,`type`,`created_at`),\n KEY `index_ge_on_repo_id_created_at` (`repo_id`,`created_at`)\n) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_bin\nPARTITION BY LIST COLUMNS(`type`)\n(PARTITION `push_event` VALUES IN ('PushEvent'),\n PARTITION `create_event` VALUES IN ('CreateEvent'),\n PARTITION `pull_request_event` VALUES IN ('PullRequestEvent'),\n PARTITION `watch_event` VALUES IN ('WatchEvent'),\n PARTITION `issue_comment_event` VALUES IN ('IssueCommentEvent'),\n PARTITION `issues_event` VALUES IN ('IssuesEvent'),\n PARTITION `delete_event` VALUES IN ('DeleteEvent'),\n PARTITION `fork_event` VALUES IN ('ForkEvent'),\n PARTITION `pull_request_review_comment_event` VALUES IN ('PullRequestReviewCommentEvent'),\n PARTITION `pull_request_review_event` VALUES IN ('PullRequestReviewEvent'),\n PARTITION `gollum_event` VALUES IN ('GollumEvent'),\n PARTITION `release_event` VALUES IN ('ReleaseEvent'),\n PARTITION `member_event` VALUES IN ('MemberEvent'),\n PARTITION `commit_comment_event` VALUES IN ('CommitCommentEvent'),\n PARTITION `public_event` VALUES IN ('PublicEvent'),\n PARTITION `gist_event` VALUES IN ('GistEvent'),\n PARTITION `follow_event` VALUES IN ('FollowEvent'),\n PARTITION `event` VALUES IN ('Event'),\n PARTITION `download_event` VALUES IN ('DownloadEvent'),\n PARTITION `team_add_event` VALUES IN ('TeamAddEvent'),\n PARTITION `fork_apply_event` VALUES IN ('ForkApplyEvent'))\n")
tk.MustQuery("SELECT\n repo_id, GROUP_CONCAT(\n DISTINCT actor_login\n ORDER BY cnt DESC\n SEPARATOR ','\n ) AS actor_logins\nFROM (\n SELECT\n ge.repo_id AS repo_id,\n ge.actor_login AS actor_login,\n COUNT(*) AS cnt\n FROM github_events ge\n WHERE\n type = 'PullRequestEvent' AND action = 'opened'\n AND (ge.created_at >= DATE_SUB(NOW(), INTERVAL 1 DAY) AND ge.created_at <= NOW())\n GROUP BY ge.repo_id, ge.actor_login\n ORDER BY cnt DESC\n) sub\nGROUP BY repo_id").Check(testkit.Rows())
}
3 changes: 3 additions & 0 deletions planner/core/rule_eliminate_projection.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ func (la *LogicalAggregation) ReplaceExprColumns(replace map[string]*expression.
for _, aggExpr := range agg.Args {
ResolveExprAndReplace(aggExpr, replace)
}
for _, orderExpr := range agg.OrderByItems {
ResolveExprAndReplace(orderExpr.Expr, replace)
}
}
for _, gbyItem := range la.GroupByItems {
ResolveExprAndReplace(gbyItem, replace)
Expand Down