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: update cost model2 #39438

Merged
merged 16 commits into from
Nov 29, 2022
Merged

planner: update cost model2 #39438

merged 16 commits into from
Nov 29, 2022

Conversation

qw4990
Copy link
Contributor

@qw4990 qw4990 commented Nov 28, 2022

What problem does this PR solve?

Issue Number: ref #35240

Problem Summary: planner: update cost model2

What is changed and how it works?

planner: update cost model2

  1. add some start-costs to HashJoin/IndexJoin to let the optimizer prefers to use MergeJoin if data size is small;
  2. add some start-costs to HashAgg to let the optimizer prefers to use StreamAgg and not push HashAgg down if the data-size is small;

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

None

@ti-chi-bot
Copy link
Member

ti-chi-bot commented Nov 28, 2022

[REVIEW NOTIFICATION]

This pull request has been approved by:

  • chrysan
  • time-and-fate

To complete the pull request process, please ask the reviewers in the list to review by filling /cc @reviewer in the comment.
After your PR has acquired the required number of LGTMs, you can assign this pull request to the committer in the list by filling /assign @committer in the comment to help you merge this pull request.

The full list of commands accepted by this bot can be found here.

Reviewer can indicate their review by submitting an approval review.
Reviewer can cancel approval by submitting a request changes review.

@ti-chi-bot ti-chi-bot added do-not-merge/invalid-title release-note-none Denotes a PR that doesn't merit a release note. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Nov 28, 2022
@qw4990
Copy link
Contributor Author

qw4990 commented Nov 29, 2022

/run-build-arm64 comment=true

@sre-bot
Copy link
Contributor

sre-bot commented Nov 29, 2022

@qw4990 qw4990 changed the title wip planner: update cost model2 Nov 29, 2022
@qw4990 qw4990 added sig/planner SIG: Planner epic/cost-model the optimizer cost model labels Nov 29, 2022
@ti-chi-bot ti-chi-bot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Nov 29, 2022
@@ -364,7 +364,7 @@ func TestCheckActRowsWithUnistore(t *testing.T) {
},
{
sql: "select count(*) from t_unistore_act_rows group by b",
expected: []string{"2", "2", "2", "4"},
expected: []string{"2", "4", "4"},
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected, not push Agg down.

` └─TableReader_13(Probe) 0.00 root data:Selection_12`,
` └─Selection_12 0.00 cop[tikv] eq(test.t1.a, 1)`,
` └─TableRangeScan_11 0.80 cop[tikv] table:t1 range: decided by [eq(test.t1.a, test.t2.a)], keep order:false, stats:pseudo`))
`└─MergeJoin_10 1.00 root inner join, left key:test.t2.a, right key:test.t1.a`,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected, MergeJoin is more cpu-effective if data-size is small.

@@ -1479,7 +1479,7 @@ func TestIndexNestedLoopHashJoin(t *testing.T) {
" └─TableRowIDScan 27.00 cop[tikv] table:l2 keep order:false"))
tk.MustQuery("select * from t l1 where exists ( select * from t l2 where l2.l_orderkey = l1.l_orderkey and l2.l_suppkey <> l1.l_suppkey )order by `l_orderkey`,`l_linenumber`;").Check(testkit.Rows("0 0 0 0", "0 1 0 1", "0 2 0 0", "1 0 1 0", "1 1 1 1", "1 2 1 0", "2 0 0 0", "2 1 0 1", "2 2 0 0"))
tk.MustQuery("desc format = 'brief' select count(*) from t l1 where exists ( select * from t l2 where l2.l_orderkey = l1.l_orderkey and l2.l_suppkey <> l1.l_suppkey );").Check(testkit.Rows(
"HashAgg 1.00 root funcs:count(1)->Column#11",
"StreamAgg 1.00 root funcs:count(1)->Column#11",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected, StreamAgg is more cpu-effective if data-size is small.

@@ -123,23 +123,23 @@
"operator_info": "data:TableFullScan_16"
}
],
"cost": 975351.9825195674,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected, just update cost values.

@@ -7,10 +7,9 @@
"Plan": [
"HashJoin 2.25 root inner join, equal:[eq(test.t1.a, test.t2.a) eq(test.t1.b, test.t2.b)]",
"├─HashAgg(Build) 1.69 root group by:test.t2.a, test.t2.b, funcs:firstrow(test.t2.a)->test.t2.a, funcs:firstrow(test.t2.b)->test.t2.b",
"│ └─TableReader 1.69 root data:HashAgg",
"│ └─HashAgg 1.69 cop[tikv] group by:test.t2.a, test.t2.b, ",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected, not push Agg down if data-size is small.

@ti-chi-bot ti-chi-bot added the status/LGT1 Indicates that a PR has LGTM 1. label Nov 29, 2022
@ti-chi-bot ti-chi-bot added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Nov 29, 2022
@qw4990
Copy link
Contributor Author

qw4990 commented Nov 29, 2022

/merge

@ti-chi-bot
Copy link
Member

This pull request has been accepted and is ready to merge.

Commit hash: 83c2880

@ti-chi-bot ti-chi-bot added the status/can-merge Indicates a PR has been approved by a committer. label Nov 29, 2022
@qw4990
Copy link
Contributor Author

qw4990 commented Nov 29, 2022

/merge

@qw4990
Copy link
Contributor Author

qw4990 commented Nov 29, 2022

/merge

@hawkingrei
Copy link
Member

/run-all-tests

1 similar comment
@qw4990
Copy link
Contributor Author

qw4990 commented Nov 29, 2022

/run-all-tests

@qw4990
Copy link
Contributor Author

qw4990 commented Nov 29, 2022

/run-build-arm64 comment=true

@sre-bot
Copy link
Contributor

sre-bot commented Nov 29, 2022

@ti-chi-bot ti-chi-bot merged commit 4476173 into pingcap:master Nov 29, 2022
@sre-bot
Copy link
Contributor

sre-bot commented Nov 29, 2022

TiDB MergeCI notify

🔴 Bad News! New failing [1] after this pr merged.
These new failed integration tests seem to be caused by the current PR, please try to fix these new failed integration tests, thanks!

CI Name Result Duration Compare with Parent commit
idc-jenkins-ci-tidb/integration-ddl-test 🟥 failed 2, success 4, total 6 5 min 21 sec New failing
idc-jenkins-ci/integration-cdc-test ✅ all 40 tests passed 22 min Fixed
idc-jenkins-ci-tidb/integration-common-test 🟢 all 17 tests passed 18 min Existing passed
idc-jenkins-ci-tidb/common-test 🟢 all 11 tests passed 9 min 31 sec Existing passed
idc-jenkins-ci-tidb/sqllogic-test-2 🟢 all 28 tests passed 6 min 54 sec Existing passed
idc-jenkins-ci-tidb/mybatis-test 🟢 all 1 tests passed 5 min 51 sec Existing passed
idc-jenkins-ci-tidb/tics-test 🟢 all 1 tests passed 5 min 41 sec Existing passed
idc-jenkins-ci-tidb/sqllogic-test-1 🟢 all 26 tests passed 5 min 32 sec Existing passed
idc-jenkins-ci-tidb/integration-compatibility-test 🟢 all 1 tests passed 3 min 13 sec Existing passed
idc-jenkins-ci-tidb/plugin-test 🟢 build success, plugin test success 4min Existing passed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
epic/cost-model the optimizer cost model release-note-none Denotes a PR that doesn't merit a release note. sig/planner SIG: Planner size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. status/can-merge Indicates a PR has been approved by a committer. status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants